--- /dev/null
+IN: io.windows.launcher.tests\r
+USING: tools.test io.windows.launcher ;\r
+\r
+[ "hello world" ] [ { "hello" "world" } join-arguments ] unit-test\r
+\r
+[ "bob \"mac arthur\"" ] [ { "bob" "mac arthur" } join-arguments ] unit-test\r
+\r
+[ "bob mac\\\\arthur" ] [ { "bob" "mac\\\\arthur" } join-arguments ] unit-test\r
+\r
+[ "bob \"mac arthur\\\\\"" ] [ { "bob" "mac arthur\\" } join-arguments ] unit-test\r
lpProcessInformation>>
} get-slots CreateProcess win32-error=0/f ;
+: count-trailing-backslashes ( str n -- str n )
+ >r "\\" ?tail [
+ r> 1+ count-trailing-backslashes
+ ] [
+ r>
+ ] if ;
+
+: fix-trailing-backslashes ( str -- str' )
+ 0 count-trailing-backslashes
+ 2 * CHAR: \\ <repetition> append ;
+
: escape-argument ( str -- newstr )
- CHAR: \s over member? [ "\"" swap "\"" 3append ] when ;
+ CHAR: \s over member? [
+ "\"" swap fix-trailing-backslashes "\"" 3append
+ ] when ;
: join-arguments ( args -- cmd-line )
[ escape-argument ] map " " join ;