[Swift-commit] r2484 - in trunk: docs libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript tests/language-behaviour
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Thu Jan 29 12:24:39 CST 2009
Author: hategan
Date: 2009-01-29 12:24:39 -0600 (Thu, 29 Jan 2009)
New Revision: 2484
Added:
trunk/tests/language-behaviour/0054-strsplit.out.expected
trunk/tests/language-behaviour/0054-strsplit.swift
Modified:
trunk/docs/userguide.xml
trunk/libexec/vdl-lib.xml
trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
added strsplit
Modified: trunk/docs/userguide.xml
===================================================================
--- trunk/docs/userguide.xml 2009-01-29 16:56:02 UTC (rev 2483)
+++ trunk/docs/userguide.xml 2009-01-29 18:24:39 UTC (rev 2484)
@@ -1682,6 +1682,32 @@
will output the message 'Your name is John'.
</para>
</section>
+
+ <section id="function.strsplit"><title>@strsplit</title>
+ <para>
+ at strsplit(input,pattern) will split the input string based on separators
+that match the given pattern and return a string array.
+ </para>
+ <para>
+Example:
+ </para>
+
+ <programlisting>
+string t = "my name is John and i like puppies.";
+string words[] = @strsplit(t, "\\s");
+foreach word in words {
+ print(word);
+}
+ </programlisting>
+
+ <para>
+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).
+ </para>
+ </section>
+
+
<section id="function.toint"><title>@toint</title>
<para>
@toint(input) will parse its input string into an integer. This can be
Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml 2009-01-29 16:56:02 UTC (rev 2483)
+++ trunk/libexec/vdl-lib.xml 2009-01-29 18:24:39 UTC (rev 2484)
@@ -7,6 +7,7 @@
<export name="readdata2"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadData2"/></export>
<export name="strcat"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="strcut"><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="regexp"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="toint"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="trace"><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 2009-01-29 16:56:02 UTC (rev 2483)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2009-01-29 18:24:39 UTC (rev 2484)
@@ -182,6 +182,15 @@
strcut.addOutputArg(strcutOut1);
functionsMap.put(strcut.getName(), strcut);
+ ProcedureSignature strsplit = new ProcedureSignature("strsplit");
+ FormalArgumentSignature strsplitIn1 = new FormalArgumentSignature("string");
+ strsplit.addInputArg(strsplitIn1);
+ FormalArgumentSignature strsplitIn2 = new FormalArgumentSignature("string");
+ strsplit.addInputArg(strsplitIn2);
+ FormalArgumentSignature strsplitOut1 = new FormalArgumentSignature("string[]");
+ strsplit.addOutputArg(strsplitOut1);
+ functionsMap.put(strsplit.getName(), strsplit);
+
ProcedureSignature toint = new ProcedureSignature("toint");
FormalArgumentSignature tointIn1 = new FormalArgumentSignature("string");
toint.addInputArg(tointIn1);
Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2009-01-29 16:56:02 UTC (rev 2483)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2009-01-29 18:24:39 UTC (rev 2484)
@@ -12,6 +12,8 @@
import org.griphyn.vdl.karajan.lib.SwiftArg;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.InvalidPathException;
+import org.griphyn.vdl.mapping.Path;
+import org.griphyn.vdl.mapping.RootArrayDataNode;
import org.griphyn.vdl.mapping.RootDataNode;
import org.griphyn.vdl.type.NoSuchTypeException;
import org.griphyn.vdl.type.Types;
@@ -28,6 +30,7 @@
setArguments("swiftscript_trace", new Arg[] { Arg.VARGS });
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_regexp", new Arg[] { PA_INPUT, PA_PATTERN, PA_TRANSFORM });
setArguments("swiftscript_toint", new Arg[] { PA_INPUT });
}
@@ -88,6 +91,22 @@
handle.closeShallow();
return handle;
}
+
+ public DSHandle swiftscript_strsplit(VariableStack stack) throws ExecutionException, NoSuchTypeException,
+ InvalidPathException {
+ String str = TypeUtil.toString(PA_INPUT.getValue(stack));
+ String pattern = TypeUtil.toString(PA_PATTERN.getValue(stack));
+
+ String[] split = str.split(pattern);
+
+ DSHandle handle = new RootArrayDataNode(Types.STRING.arrayType());
+ for (int i = 0; i < split.length; i++) {
+ DSHandle el = handle.getField(Path.EMPTY_PATH.addFirst(String.valueOf(i), true));
+ el.setValue(split[i]);
+ }
+ handle.closeDeep();
+ return handle;
+ }
public DSHandle swiftscript_regexp(VariableStack stack) throws ExecutionException, NoSuchTypeException,
InvalidPathException {
Added: trunk/tests/language-behaviour/0054-strsplit.out.expected
===================================================================
--- trunk/tests/language-behaviour/0054-strsplit.out.expected (rev 0)
+++ trunk/tests/language-behaviour/0054-strsplit.out.expected 2009-01-29 18:24:39 UTC (rev 2484)
@@ -0,0 +1 @@
+ab , c , def , ghij
Added: trunk/tests/language-behaviour/0054-strsplit.swift
===================================================================
--- trunk/tests/language-behaviour/0054-strsplit.swift (rev 0)
+++ trunk/tests/language-behaviour/0054-strsplit.swift 2009-01-29 18:24:39 UTC (rev 2484)
@@ -0,0 +1,14 @@
+type messagefile {}
+
+(messagefile t) greeting(string a, string b, string c, string d) {
+ app {
+ echo a "," b "," c "," d stdout=@filename(t);
+ }
+}
+
+messagefile outfile <"0054-strsplit.out">;
+
+string s[] = @strsplit("ab c def ghij", "\\s");
+
+outfile = greeting(s[0], s[1], s[2], s[3]);
+
More information about the Swift-commit
mailing list