[Swift-commit] r3259 - in trunk/src/org/griphyn/vdl/karajan/lib: . swiftscript
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Thu Mar 11 15:19:33 CST 2010
Author: wozniak
Date: 2010-03-11 15:19:33 -0600 (Thu, 11 Mar 2010)
New Revision: 3259
Modified:
trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java
trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
New %M specifier for tracef().
Modified: trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java 2010-03-01 20:59:19 UTC (rev 3258)
+++ trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java 2010-03-11 21:19:33 UTC (rev 3259)
@@ -191,7 +191,7 @@
}
/** The caller is expected to have synchronized on the root of var. */
- public String[] filename(DSHandle var) throws ExecutionException, HandleOpenException {
+ public static String[] filename(DSHandle var) throws ExecutionException, HandleOpenException {
assert Thread.holdsLock(var.getRoot());
try {
if (var.getType().isArray()) {
@@ -207,7 +207,7 @@
}
}
- private String[] leavesFileNames(DSHandle var) throws ExecutionException, HandleOpenException {
+ private static String[] leavesFileNames(DSHandle var) throws ExecutionException, HandleOpenException {
List l = new ArrayList();
Iterator i;
try {
@@ -278,7 +278,7 @@
}
}
- private String leafFileName(DSHandle var) throws ExecutionException {
+ private static String leafFileName(DSHandle var) throws ExecutionException {
if (Types.STRING.equals(var.getType())) {
return relativize(String.valueOf(var.getValue()));
}
@@ -311,7 +311,7 @@
}
}
- protected String pathOnly(String file) {
+ protected static String pathOnly(String file) {
return new AbsFile(file).getPath();
}
@@ -347,7 +347,7 @@
* removes leading / character from a supplied filename if present, so that
* the path can be used as a relative path.
*/
- public String relativize(String name) {
+ public static String relativize(String name) {
name = pathOnly(name);
if (name != null && name.length() > 0 && name.charAt(0) == '/') {
return name.substring(1);
Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2010-03-01 20:59:19 UTC (rev 3258)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2010-03-11 21:19:33 UTC (rev 3259)
@@ -35,6 +35,7 @@
setArguments("swiftscript_tracef", new Arg[] { Arg.VARGS });
setArguments("swiftscript_strcat", new Arg[] { Arg.VARGS });
setArguments("swiftscript_strcut", new Arg[] { PA_INPUT, PA_PATTERN });
+ setArguments("swiftscript_strstr", 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 });
@@ -133,6 +134,20 @@
if (c == 'p') {
output.append(args[arg].toString());
}
+ else if (c == 'M') {
+ try {
+ synchronized (args[arg].getRoot()) {
+ String[] names = VDLFunction.filename(args[arg]);
+ if (names.length > 1)
+ output.append(names);
+ else
+ output.append(names[0]);
+ }
+ }
+ catch (Exception e) {
+ throw new ExecutionException("tracef(%M): Could not lookup: " + args[arg]);
+ }
+ }
else if (c == 's') {
if (args[arg].getType() == Types.STRING) {
output.append(args[arg]).toString();
@@ -235,6 +250,22 @@
return handle;
}
+ public DSHandle swiftscript_strstr(VariableStack stack) throws ExecutionException, NoSuchTypeException,
+ InvalidPathException {
+
+ String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
+ String pattern = TypeUtil.toString(PA_PATTERN.getValue(stack));
+ if (logger.isDebugEnabled()) {
+ logger.debug("strstr will search '" + inputString +
+ "' for pattern '" + pattern + "'");
+ }
+ int result = inputString.indexOf(pattern);
+ DSHandle handle = new RootDataNode(Types.INT);
+ handle.setValue(new Double(result));
+ handle.closeShallow();
+ return handle;
+ }
+
public DSHandle swiftscript_strsplit(VariableStack stack) throws ExecutionException, NoSuchTypeException,
InvalidPathException {
String str = TypeUtil.toString(PA_INPUT.getValue(stack));
More information about the Swift-commit
mailing list