[Swift-commit] r5916 - in trunk: docs/userguide libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript tests/language-behaviour/strings

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Sun Sep 2 13:38:33 CDT 2012


Author: davidk
Date: 2012-09-02 13:38:32 -0500 (Sun, 02 Sep 2012)
New Revision: 5916

Added:
   trunk/tests/language-behaviour/strings/0055-strjoin.check.sh
   trunk/tests/language-behaviour/strings/0055-strjoin.swift
Modified:
   trunk/docs/userguide/app_procedures
   trunk/libexec/vdl-lib.xml
   trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
@strjoin


Modified: trunk/docs/userguide/app_procedures
===================================================================
--- trunk/docs/userguide/app_procedures	2012-09-01 14:58:35 UTC (rev 5915)
+++ trunk/docs/userguide/app_procedures	2012-09-02 18:38:32 UTC (rev 5916)
@@ -368,13 +368,28 @@
 trace(out);
 ----
 
-will output the message: Your name is John.
+This will output the message: Your name is John.
 
+ at strjoin
+~~~~~~~~
+ at strjoin(array, delimiter) will combine the elements of an array
+into a single string separated by a given delimiter. The array
+passed to @strjoin must be of a primitive type (string, int, float, 
+or boolean). It will not join the contents of an array of files.
+
+Example:
+----
+string test[] = ["this", "is", "a", "test" ];
+string mystring = @strjoin(test, " ");
+tracef("%s\n", mystring);
+----
+
+This will print the string "this is a test".
+
 @strsplit
 ~~~~~~~~~
 @strsplit(input,pattern) will split the input string based on
 separators that match the given pattern and return a string array.
-(since Swift 0.9)
 
 Example:
 ----
@@ -385,7 +400,7 @@
 }
 ----
 
-will output one word of the sentence on each line (though not
+This will output one word of the sentence on each line (though not
 necessarily in order, due to the fact that foreach iterations execute in
 parallel).
 

Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2012-09-01 14:58:35 UTC (rev 5915)
+++ trunk/libexec/vdl-lib.xml	2012-09-02 18:38:32 UTC (rev 5916)
@@ -11,6 +11,7 @@
 	<export name="strcut"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="strstr"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="strsplit"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
+        <export name="strjoin"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="regexp"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="to_int"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="to_float"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>

Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2012-09-01 14:58:35 UTC (rev 5915)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2012-09-02 18:38:32 UTC (rev 5916)
@@ -196,7 +196,7 @@
 		add(functionsMap, "strcut", returns(STRING), args(STRING, STRING));
 		add(functionsMap, "strstr", returns(INT), args(STRING, STRING));
 		add(functionsMap, "strsplit", returns(STRING_ARRAY), args(STRING, STRING));
-		
+		add(functionsMap, "strjoin", returns(STRING), args(ANY, STRING));
 		add(functionsMap, "toInt", returns(INT), args(ANY));
 		add(functionsMap, "toFloat", returns(FLOAT), args(ANY));
 		add(functionsMap, "toString", returns(STRING), args(ANY));

Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java	2012-09-01 14:58:35 UTC (rev 5915)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java	2012-09-02 18:38:32 UTC (rev 5916)
@@ -61,6 +61,7 @@
         setArguments("swiftscript_strcat",  new Arg[] { Arg.VARGS });
         setArguments("swiftscript_strcut", new Arg[] { PA_INPUT, PA_PATTERN });
         setArguments("swiftscript_strsplit", new Arg[] { PA_INPUT, PA_PATTERN });
+        setArguments("swiftscript_strjoin", new Arg[] { PA_ARRAY, PA_INPUT });
         setArguments("swiftscript_strstr", new Arg[] { PA_INPUT, PA_PATTERN });
 		setArguments("swiftscript_trace", new Arg[] { Arg.VARGS });
         setArguments("swiftscript_to_int", new Arg[] { PA_INPUT });
@@ -69,7 +70,6 @@
 		setArguments("swiftscript_tofloat", new Arg[] { PA_INPUT });
         setArguments("swiftscript_to_string", new Arg[] { PA_INPUT });
         setArguments("swiftscript_tostring", new Arg[] { PA_INPUT });
-
 	}
 
 	private static final Logger traceLogger =
@@ -256,7 +256,31 @@
 		VDLFunction.logProvenanceParameter(provid, PA_PATTERN.getRawValue(stack), "pattern");
 		return handle;
 	}
+	
+	/**
+	 * swiftscript_strjoin (@strjoin) - Combine elements of an array into a single string with a specified delimiter
+	 * @param stack
+	 * @return DSHandle representing the resulting string
+	 * @throws ExecutionException
+	 */
+    public DSHandle swiftscript_strjoin(VariableStack stack) throws ExecutionException 
+    {
+        AbstractDataNode array = (AbstractDataNode) PA_ARRAY.getRawValue(stack);
+        String delim = TypeUtil.toString(PA_INPUT.getValue(stack));
+        String result = "";
 
+        array.waitFor();
+
+        Map<?, ?> arrayValues = array.getArrayValue();
+        for (Object value : arrayValues.values()) {
+            if (result == "") { result += ((DSHandle) value).getValue(); }
+            else { result += delim + ((DSHandle) value).getValue(); }
+        }
+
+        DSHandle handle = new RootDataNode(Types.STRING, result);
+        return handle;
+    }
+
 	public DSHandle swiftscript_regexp(VariableStack stack)
 	throws ExecutionException {
 		String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));

Added: trunk/tests/language-behaviour/strings/0055-strjoin.check.sh
===================================================================
--- trunk/tests/language-behaviour/strings/0055-strjoin.check.sh	                        (rev 0)
+++ trunk/tests/language-behaviour/strings/0055-strjoin.check.sh	2012-09-02 18:38:32 UTC (rev 5916)
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+set -x
+filename="0055-strjoin.stdout"
+
+grep -x "Empty: " $filename || exit 1
+grep -x "Integer array: 1:2:3:4:5" $filename || exit 1
+grep -x "String array: a:bb:ccc" $filename || exit 1
+grep -x "Boolean array: true:false:true:false" $filename || exit 1
+grep -x "Float array: 1.1:2.2:3.3:4.4:5.5" $filename || exit 1
+
+exit 0


Property changes on: trunk/tests/language-behaviour/strings/0055-strjoin.check.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/tests/language-behaviour/strings/0055-strjoin.swift
===================================================================
--- trunk/tests/language-behaviour/strings/0055-strjoin.swift	                        (rev 0)
+++ trunk/tests/language-behaviour/strings/0055-strjoin.swift	2012-09-02 18:38:32 UTC (rev 5916)
@@ -0,0 +1,20 @@
+string sa[] = ["a", "bb", "ccc"];
+string sas = @strjoin(sa, ":");
+tracef("String array: %s\n", sas);
+
+int ia[] = [1, 2, 3, 4, 5];
+string ias = @strjoin(ia, ":");
+tracef("Integer array: %s\n", ias);
+
+float fa[] = [1.1, 2.2, 3.3, 4.4, 5.5];
+string fas = @strjoin(fa, ":");
+tracef("Float array: %s\n", fas);
+
+boolean ba[] = [true, false, true, false];
+string bas = @strjoin(ba, ":");
+tracef("Boolean array: %s\n", bas);
+
+string empty[];
+string emptystring = @strjoin(empty, ":");
+tracef("Empty: %s\n", emptystring);
+


Property changes on: trunk/tests/language-behaviour/strings/0055-strjoin.swift
___________________________________________________________________
Added: svn:executable
   + *




More information about the Swift-commit mailing list