|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcomtest.StringUtilities
public class StringUtilities
A collection of static string handling functions to make the string handling in ComTest more easy.
| Field Summary | |
|---|---|
static java.lang.String |
QUOTES
Chars that are handled as quote chars |
| Constructor Summary | |
|---|---|
StringUtilities()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
addToName(java.lang.String fileName,
java.lang.String newPart)
Adds a new part to filename |
static int |
countEndIndex(java.lang.String start,
java.lang.String end)
Counts the index in ending word when the builded string should contain end-string as last characters. |
static Strings |
getFileContents(java.lang.String fileName)
Read the file and return the contents as a ArrayList |
static java.lang.String |
getLineIndent(java.lang.String line,
int pos)
Returns indent string copied from line. |
static int |
indexOfBack(java.lang.String s,
java.lang.String what,
int pos)
Searches what backwards from pos and returns position found |
static int |
indexOfNotInQuotes(java.lang.String s,
java.lang.String what)
Find first instance of what that is not inside of quotes |
static int |
indexOfNotInQuotes(java.lang.String s,
java.lang.String what,
java.lang.String quote)
Find first instance of what that is not inside of quotes |
static int |
indexOfNotInQuotes(java.lang.String s,
java.lang.String what,
java.lang.String quote,
int pos)
Find first instance of what that is not inside of quotes |
static boolean |
isEmpty(java.lang.String s)
Check if string is empty |
static java.lang.String |
justFilePart(java.lang.String fileName)
Returns just the file part from fileName. |
static java.lang.String |
remove(java.lang.String s,
java.lang.String what)
Removes from s the first instance of what |
static java.lang.String |
removeAllAfter(java.lang.String s,
java.lang.String afterWhat)
Returns a string where all after afterWhat string is removed Also the afterWhat is removed. |
static java.lang.String |
removeFromBegining(java.lang.String s,
java.lang.String what)
Removes all instances of what from the beginning of s |
static java.lang.String |
removeFromBegining(java.lang.String s,
java.lang.String what,
int n)
Removes n instances of what from the beginning of s |
static java.lang.String |
removeFromBeginingTrim(java.lang.String s,
java.lang.String what)
Removes all instances of what from the beginning of s If there is only spaces before s, then remove them also. |
static Strings |
splitBy(java.lang.String s,
java.lang.String where)
Splits s to pieces from where. |
static Strings |
splitBy(java.lang.String s,
java.lang.String where,
int jump)
Splits s to pieces from where. |
static Strings |
splitBy(java.lang.String s,
java.lang.String where,
int jump,
boolean trim)
Splits s to pieces from where. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String QUOTES
| Constructor Detail |
|---|
public StringUtilities()
| Method Detail |
|---|
public static Strings splitBy(java.lang.String s,
java.lang.String where,
int jump,
boolean trim)
s - string to splitwhere - from where to splitjump - how much delete from each parttrim - to trim or not the parts
String s = "first; second;\"third;3\";4;"; Strings p = splitBy(s,";",1); p.size() === 5 p.get(0) === "first"; p.get(1) === " second"; p.get(2) === "\"third;3\"" p.get(3) === "4"; p.get(4) === "" s = "first; second;\"third;3\";4"; p = splitBy(s,";",0,true); p.size() === 4 p.get(0) === "first;" p.get(1) === "second;" p.get(2) === "\"third;3\";" p.get(3) === "4"
public static Strings splitBy(java.lang.String s,
java.lang.String where,
int jump)
s - string to splitwhere - from where to splitjump - how much delete from each part
public static Strings splitBy(java.lang.String s,
java.lang.String where)
s - string to splitwhere - from where to split
Strings p;
p = splitBy("one|two|three","|");
p.size() === 3;
p.get(0) === "one";
p.get(1) === "two";
p.get(2) === "three";
p = splitBy("one|","|");
p.size() === 2;
p.get(0) === "one";
p.get(1) === "";
p = splitBy("one","|");
p.size() === 1;
p.get(0) === "one";
p = splitBy("","|");
p.size() === 1;
p.get(0) === "";
public static int indexOfNotInQuotes(java.lang.String s,
java.lang.String what,
java.lang.String quote,
int pos)
s - from where to findwhat - string to findquote - what chars are used as a quotepos - position where to start
public static int indexOfNotInQuotes(java.lang.String s,
java.lang.String what)
s - from where to findwhat - string to find
public static int indexOfNotInQuotes(java.lang.String s,
java.lang.String what,
java.lang.String quote)
s - from where to findwhat - string to findquote - what chars are used as a quote
indexOfNotInQuotes("a = a+1; // add one ", "//","\"") === 9
indexOfNotInQuotes("a = a+1; ", "//","\"") === -1
indexOfNotInQuotes("s = \"//\"; // s is comment", "//","\"") === 10
indexOfNotInQuotes("s = \"//\"; ", "//","\"") === -1
indexOfNotInQuotes("s = \"a\"; // \"//\" ", "//","\"") === 10
indexOfNotInQuotes("s = \"a\"; // \"//\" ", "\"","\"") === 4
indexOfNotInQuotes("s = \"a\"; // \"//\" ", "a","") === 5
indexOfNotInQuotes("s = \"a\"; c='a'; d=a; ", "a","\"'") === 18
public static java.lang.String removeFromBegining(java.lang.String s,
java.lang.String what,
int n)
s - where to removewhat - string what to removen - how many times to remove
removeFromBegining("* a=a+1;","*",2) === " a=a+1;"
removeFromBegining("*** a=a+1;","*",2) === "* a=a+1;"
removeFromBegining("* ** a=a+1;","*",2) === " ** a=a+1;"
public static java.lang.String removeFromBegining(java.lang.String s,
java.lang.String what)
s - where to removewhat - string what to remove
removeFromBegining("* a=a+1;","*") === " a=a+1;"
removeFromBegining("*** a=a+1;","*") === " a=a+1;"
removeFromBegining("* ** a=a+1;","*") === " ** a=a+1;"
public static java.lang.String removeFromBeginingTrim(java.lang.String s,
java.lang.String what)
s - where to removewhat - string what to remove
removeFromBeginingTrim(" * a=a+1;","*") === " a=a+1;"
removeFromBeginingTrim(" *** a=a+1;","*") === " a=a+1;"
removeFromBeginingTrim(" * ** a=a+1;","*") === " ** a=a+1;"
removeFromBeginingTrim(" a=a+1;","*") === " a=a+1;"
public static java.lang.String removeAllAfter(java.lang.String s,
java.lang.String afterWhat)
s - string to handleafterWhat - string to look for
removeAllAfter("a = a+1; // add one ", "//") === "a = a+1; "
removeAllAfter("a = a+1; ","//") === "a = a+1; "
removeAllAfter("s = \"//\"; // s is comment", "//" ) === "s = \"//\"; "
removeAllAfter("s = \"//\"; " ,"//") === "s = \"//\"; "
removeAllAfter("s = \"a\"; // \"//\" " ,"//") === "s = \"a\"; "
public static java.lang.String addToName(java.lang.String fileName,
java.lang.String newPart)
fileName - filename to changenewPart - part to add
addToName("my.java","Test") === "myTest.java"
addToName("my","Test") === "myTest"
public static java.lang.String justFilePart(java.lang.String fileName)
fileName -
justFilePart("myTest.java") === "myTest"
justFilePart("myTest") === "myTest"
justFilePart("/users/my/java/myTest.java") === "myTest"
justFilePart("/users/my.prg/java/myTest.java") === "myTest"
justFilePart("/users/my.prg/java/myTest") === "myTest"
justFilePart("/users/my.prg/java/myTest/") === ""
justFilePart("e:\\users\\my.prg\\java\\myTest") === "myTest"
justFilePart("\\users\\my.prg\\java\\myTest") === "myTest"
justFilePart("e:myTest.java") === "myTest"
public static java.lang.String remove(java.lang.String s,
java.lang.String what)
s - where to removewhat - what string to remove
remove($s,$what) === $result; $s | $what | $result ---------------------------------- "aab" | "a" | "ab" "bab" | "a" | "bb" "bba" | "a" | "bb",
remove($s,$what) === $result; $s | $what | $result ---------------------------------- "\"aa\"b" | "a" | "\"aa\"b" "\"a\"ab" | "a" | "\"a\"b"
public static Strings getFileContents(java.lang.String fileName)
fileName - the file name to read
Strings list = getFileContents("comtest/StringUtilities.java");
int lastn = list.size()-1;
lastn > 200 === true;
list.get(0) === "package comtest;";
list.get(lastn) === "}";
list = getFileContents("comtest/StringUtilitiesXYZ.java");
list === null;
public static int countEndIndex(java.lang.String start,
java.lang.String end)
start - The starting string.end - The required ending.
countEndIndex("#STATIC","#STATICIMPORT") === 7;
countEndIndex("ABCD","1234") === 0;
countEndIndex("ABCD","ABCD") === 4;
countEndIndex("1234567890#STATIC","#STATICIMPORT") === 7;
public static int indexOfBack(java.lang.String s,
java.lang.String what,
int pos)
s - where to searchwhat - to searchpos - where to start search
indexOfBack("0123456789","4",8) === 4;
indexOfBack("0123456789","9",8) === -1;
indexOfBack("0123456789","4",4) === 4;
indexOfBack("0123456789","4",3) === -1;
indexOfBack(null,"4",5) === -1;
indexOfBack(null,null,5) === -1;
indexOfBack("012345678",null,5) === -1;
indexOfBack("0123456789","4",18) === 4;
indexOfBack("0123456789","",18) === 10;
indexOfBack("0123456789","",5) === 5;
indexOfBack("0123456789","abc",15) === -1;
public static java.lang.String getLineIndent(java.lang.String line,
int pos)
line - line to look indent templatepos - where to start looking
getLineIndent("first\n second\n",15) === " ";
getLineIndent("first\n second\n",5) === " ";
getLineIndent("first\n second\n",4) === "";
getLineIndent(" first\n second\n",6) === " ";
public static boolean isEmpty(java.lang.String s)
s - string to check
isEmpty(null) === true;
isEmpty("") === true;
isEmpty(" ") === true;
isEmpty("a") === false;
isEmpty("\n") === false;
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||