edu.rice.cs.cunit.util
Class StringOps

java.lang.Object
  extended by edu.rice.cs.cunit.util.StringOps

public class StringOps
extends java.lang.Object

String operations.

Author:
Mathias Ricken

Nested Class Summary
static interface StringOps.MatchResult
           
private static class StringOps.MatchResultDelegate
           
static class StringOps.StringOpsTest
          Test cases.
 
Constructor Summary
StringOps()
           
 
Method Summary
static StringOps.MatchResult match(java.lang.String s, java.lang.String pattern)
          Return the match result of the regex pattern in the string s, beginning at 0.
static StringOps.MatchResult match(java.lang.String s, java.lang.String pattern, int start)
          Return the match result of the regex pattern in the string s, beginning at start.
static java.lang.String replaceVariables(java.lang.String str, java.util.Hashtable<java.lang.Object,java.lang.Object> table)
          Replace variables of the form "%variable%" with the value associated with the string "variable" in the provided hash table.
static boolean stringMatches(java.lang.String str, char separatorChar, java.lang.String... stringPatterns)
          Returns true if the specified string matches one of the patterns.
static java.lang.String toStringMillis(long millis)
          Return a human-readable representation of a duration in milliseconds, up to days.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringOps

public StringOps()
Method Detail

toStringMillis

public static java.lang.String toStringMillis(long millis)
Return a human-readable representation of a duration in milliseconds, up to days.

Parameters:
millis - length of time in milliseconds
Returns:
string representing the same duration in seconds, minutes, etc.

replaceVariables

public static java.lang.String replaceVariables(java.lang.String str,
                                                java.util.Hashtable<java.lang.Object,java.lang.Object> table)
Replace variables of the form "%variable%" with the value associated with the string "variable" in the provided hash table. To give the "%" character its literal meaning, it needs to be escaped as "%%" (double percent).

Parameters:
str - input string
table - hash table with variable-value pairs
Returns:
string with variables replaced by values

stringMatches

public static boolean stringMatches(java.lang.String str,
                                    char separatorChar,
                                    java.lang.String... stringPatterns)
Returns true if the specified string matches one of the patterns. ! = make sure class name does NOT match this pattern (first character prefix only) ? = one character * = zero or more characters except separatorChar (e.g. '/' for Unix file names or '.' for class names) *** = zero or more characters including separatorChar [abc] = Either a, b or c [a-mA-M] = A letter from the ranges a-m or A-M (inclusive) Foo|Bar = either "Foo" or "Bar" () can be used for grouping: "(Integer|Float)Constant" matches "IntegerConstant" and "FloatConstant". The entire file name has to match the pattern, i.e. the regex characters ^ and $ are implicit.

Parameters:
str - string
separatorChar - the character that ends matches of * but not of *** ('.', '/' or '\\' supported)
stringPatterns - variable argument list of patterns
Returns:
true if the specified string matches one of the patterns

match

public static StringOps.MatchResult match(java.lang.String s,
                                          java.lang.String pattern,
                                          int start)
Return the match result of the regex pattern in the string s, beginning at start.

Parameters:
s - the original string
pattern - the regex
start - the character offset where to start
Returns:
the match result; will have found() returning false if not found

match

public static StringOps.MatchResult match(java.lang.String s,
                                          java.lang.String pattern)
Return the match result of the regex pattern in the string s, beginning at 0.

Parameters:
s - the original string
pattern - the regex
Returns:
the match result; will have found() returning false if not found