Skip to content

Commit

Permalink
Based on a patch by Garrett Wollman.
Browse files Browse the repository at this point in the history
Compile regexes in ColorTest.


git-svn-id: http://codeswarm.googlecode.com/svn/trunk@148 eda9c206-d64f-0410-a2f2-67f3fa0499ed
  • Loading branch information
michael.ogawa committed Jul 11, 2008
1 parent 5efe07a commit f93ca26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ColorAssigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ColorAssigner()
public void addRule( String label, String expr, int c1, int c2 )
{
ColorTest t = new ColorTest();
t.expr = expr;
t.expr = java.util.regex.Pattern.compile( expr );
t.label = label;
t.c1 = c1;
t.c2 = c2;
Expand Down
12 changes: 7 additions & 5 deletions src/ColorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
*/

import java.awt.Color;
import java.util.regex.*;
import processing.core.PApplet;
import processing.core.PConstants;

class ColorTest
{
String expr;
Pattern expr;
String label;
int c1, c2;

public boolean passes( String s )
{
return s.matches( expr );
Matcher m = expr.matcher(s);
return m.matches();
}

public int assign()
Expand All @@ -48,9 +50,9 @@ public void loadProperty( String value )
tokens = firstpart.split( "\"" );
label = tokens[0];
if (tokens.length == 3) {
expr = tokens[2];
expr = Pattern.compile( tokens[2] );
} else {
expr = tokens[0];
expr = Pattern.compile( tokens[0] );
}
// then the comma delimited colors
String rest = value.substring( lastQ + 1 );
Expand All @@ -75,7 +77,7 @@ public static void main( String [] args )
ColorTest ct = new ColorTest();
System.out.println( "input=" + args[0] );
ct.loadProperty( args[0] );
System.out.println( "regex=" + ct.expr );
//System.out.println( "regex=" + ct.expr );
System.out.println( "color1=" + Integer.toHexString(ct.c1) );
System.out.println( "color2=" + Integer.toHexString(ct.c2) );
}
Expand Down

0 comments on commit f93ca26

Please sign in to comment.