* If a String is longer than the desired length, * it will not be truncated, however no padding * will be added. * * @param s String to be padded. * @param length desired length of result. * @return padded String. * @throws NullPointerException if s is null. * * @since ostermillerutils 1.00.00 */ public static String prepad(String s, int length){ return prepad(s, length, ' '); } /** * Pre-pend the given character to the String until * the result is the desired length. *
* If a String is longer than the desired length, * it will not be truncated, however no padding * will be added. * * @param s String to be padded. * @param length desired length of result. * @param c padding character. * @return padded String. * @throws NullPointerException if s is null. * * @since ostermillerutils 1.00.00 */ public static String prepad(String s, int length, char c){ int needed = length - s.length(); if (needed <= 0){ return s; } char padding[] = new char[needed]; java.util.Arrays.fill(padding, c); StringBuffer sb = new StringBuffer(length); sb.append(padding); sb.append(s); return sb.toString(); } /** * Pad the end of the given String with spaces until * the String is of the given length. *
* If a String is longer than the desired length, * it will not be truncated, however no padding * will be added. * * @param s String to be padded. * @param length desired length of result. * @return padded String. * @throws NullPointerException if s is null. * * @since ostermillerutils 1.00.00 */ public static String postpad(String s, int length){ return postpad(s, length, ' '); } /** * Append the given character to the String until * the result is the desired length. *
* If a String is longer than the desired length, * it will not be truncated, however no padding * will be added. * * @param s String to be padded. * @param length desired length of result. * @param c padding character. * @return padded String. * @throws NullPointerException if s is null. * * @since ostermillerutils 1.00.00 */ public static String postpad(String s, int length, char c){ int needed = length - s.length(); if (needed <= 0){ return s; } char padding[] = new char[needed]; java.util.Arrays.fill(padding, c); StringBuffer sb = new StringBuffer(length); sb.append(s); sb.append(padding); return sb.toString(); } /** * Pad the beginning and end of the given String with spaces until * the String is of the given length. The result is that the original * String is centered in the middle of the new string. *
* If the number of characters to pad is even, then the padding * will be split evenly between the beginning and end, otherwise, * the extra character will be added to the end. *
* If a String is longer than the desired length, * it will not be truncated, however no padding * will be added. * * @param s String to be padded. * @param length desired length of result. * @return padded String. * @throws NullPointerException if s is null. * * @since ostermillerutils 1.00.00 */ public static String midpad(String s, int length){ return midpad(s, length, ' '); } /** * Pad the beginning and end of the given String with the given character * until the result is the desired length. The result is that the original * String is centered in the middle of the new string. *
* If the number of characters to pad is even, then the padding * will be split evenly between the beginning and end, otherwise, * the extra character will be added to the end. *
* If a String is longer than the desired length, * it will not be truncated, however no padding * will be added. * * @param s String to be padded. * @param length desired length of result. * @param c padding character. * @return padded String. * @throws NullPointerException if s is null. * * @since ostermillerutils 1.00.00 */ public static String midpad(String s, int length, char c){ int needed = length - s.length(); if (needed <= 0){ return s; } int beginning = needed / 2; int end = beginning + needed % 2; char prepadding[] = new char[beginning]; java.util.Arrays.fill(prepadding, c); char postpadding[] = new char[end]; java.util.Arrays.fill(postpadding, c); StringBuffer sb = new StringBuffer(length); sb.append(prepadding); sb.append(s); sb.append(postpadding); return sb.toString(); } /** * Split the given String into tokens. *
* This method is meant to be similar to the split * function in other programming languages but it does * not use regular expressions. Rather the String is * split on a single String literal. *
* Unlike java.util.StringTokenizer which accepts * multiple character tokens as delimiters, the delimiter * here is a single String literal. *
* Each null token is returned as an empty String. * Delimiters are never returned as tokens. *
* If there is no delimiter because it is either empty or * null, the only element in the result is the original String. *
* StringHelper.split("1-2-3", "-");
* result: {"1","2","3"}
* StringHelper.split("-1--2-", "-");
* result: {"","1","","2",""}
* StringHelper.split("123", "");
* result: {"123"}
* StringHelper.split("1-2---3----4", "--");
* result: {"1-2","-3","","4"}
*
* @param s String to be split.
* @param delimiter String literal on which to split.
* @return an array of tokens.
* @throws NullPointerException if s is null.
*
* @since ostermillerutils 1.00.00
*/
public static String[] split(String s, String delimiter){
int delimiterLength;
// the next statement has the side effect of throwing a null pointer
// exception if s is null.
int stringLength = s.length();
if (delimiter == null || (delimiterLength = delimiter.length()) == 0){
// it is not inherently clear what to do if there is no delimiter
// On one hand it would make sense to return each character because
// the null String can be found between each pair of characters in
// a String. However, it can be found many times there and we don'
// want to be returning multiple null tokens.
// returning the whole String will be defined as the correct behavior
// in this instance.
return new String[] {s};
}
// a two pass solution is used because a one pass solution would
// require the possible resizing and copying of memory structures
// In the worst case it would have to be resized n times with each
// resize having a O(n) copy leading to an O(n^2) algorithm.
int count;
int start;
int end;
// Scan s and count the tokens.
count = 0;
start = 0;
while((end = s.indexOf(delimiter, start)) != -1){
count++;
start = end + delimiterLength;
}
count++;
// allocate an array to return the tokens,
// we now know how big it should be
String[] result = new String[count];
// Scan s again, but this time pick out the tokens
count = 0;
start = 0;
while((end = s.indexOf(delimiter, start)) != -1){
result[count] = (s.substring(start, end));
count++;
start = end + delimiterLength;
}
end = stringLength;
result[count] = s.substring(start, end);
return (result);
}
/**
* Split the given String into tokens. Delimiters will
* be returned as tokens.
*
* This method is meant to be similar to the split * function in other programming languages but it does * not use regular expressions. Rather the String is * split on a single String literal. *
* Unlike java.util.StringTokenizer which accepts * multiple character tokens as delimiters, the delimiter * here is a single String literal. *
* Each null token is returned as an empty String. * Delimiters are never returned as tokens. *
* If there is no delimiter because it is either empty or * null, the only element in the result is the original String. *
* StringHelper.split("1-2-3", "-");
* result: {"1","-","2","-","3"}
* StringHelper.split("-1--2-", "-");
* result: {"","-","1","-","","-","2","-",""}
* StringHelper.split("123", "");
* result: {"123"}
* StringHelper.split("1-2--3---4----5", "--");
* result: {"1-2","--","3","--","-4","--","","--","5"}
*
* @param s String to be split.
* @param delimiter String literal on which to split.
* @return an array of tokens.
* @throws NullPointerException if s is null.
*
* @since ostermillerutils 1.05.00
*/
public static String[] splitIncludeDelimiters(String s, String delimiter){
int delimiterLength;
// the next statement has the side effect of throwing a null pointer
// exception if s is null.
int stringLength = s.length();
if (delimiter == null || (delimiterLength = delimiter.length()) == 0){
// it is not inherently clear what to do if there is no delimiter
// On one hand it would make sense to return each character because
// the null String can be found between each pair of characters in
// a String. However, it can be found many times there and we don'
// want to be returning multiple null tokens.
// returning the whole String will be defined as the correct behavior
// in this instance.
return new String[] {s};
}
// a two pass solution is used because a one pass solution would
// require the possible resizing and copying of memory structures
// In the worst case it would have to be resized n times with each
// resize having a O(n) copy leading to an O(n^2) algorithm.
int count;
int start;
int end;
// Scan s and count the tokens.
count = 0;
start = 0;
while((end = s.indexOf(delimiter, start)) != -1){
count+=2;
start = end + delimiterLength;
}
count++;
// allocate an array to return the tokens,
// we now know how big it should be
String[] result = new String[count];
// Scan s again, but this time pick out the tokens
count = 0;
start = 0;
while((end = s.indexOf(delimiter, start)) != -1){
result[count] = (s.substring(start, end));
count++;
result[count] = delimiter;
count++;
start = end + delimiterLength;
}
end = stringLength;
result[count] = s.substring(start, end);
return (result);
}
/**
* Join all the elements of a string array into a single
* String.
*
* If the given array empty an empty string * will be returned. Null elements of the array are allowed * and will be treated like empty Strings. * * @param array Array to be joined into a string. * @return Concatenation of all the elements of the given array. * @throws NullPointerException if array is null. * * @since ostermillerutils 1.05.00 */ public static String join(String[] array){ return join(array, ""); } /** * Join all the elements of a string array into a single * String. *
* If the given array empty an empty string
* will be returned. Null elements of the array are allowed
* and will be treated like empty Strings.
*
* @param array Array to be joined into a string.
* @param delimiter String to place between array elements.
* @return Concatenation of all the elements of the given array with the the delimiter in between.
* @throws NullPointerException if array or delimiter is null.
*
* @since ostermillerutils 1.05.00
*/
public static String join(String[] array, String delimiter){
// Cache the length of the delimiter
// has the side effect of throwing a NullPointerException if
// the delimiter is null.
int delimiterLength = delimiter.length();
// Nothing in the array return empty string
// has the side effect of throwing a NullPointerException if
// the array is null.
if (array.length == 0) return "";
// Only one thing in the array, return it.
if (array.length == 1){
if (array[0] == null) return "";
return array[0];
}
// Make a pass through and determine the size
// of the resulting string.
int length = 0;
for (int i=0; i
* Any data that will appear as text on a web page should
* be be escaped. This is especially important for data
* that comes from untrusted sources such as Internet users.
* A common mistake in CGI programming is to ask a user for
* data and then put that data on a web page. For example:
* This method will replace HTML characters such as > with their
* HTML entity reference (>) so that the html parser will
* be sure to interpret them as plain text rather than HTML or script.
*
* This method should be used for both data to be displayed in text
* in the html document, and data put in form elements. For example:
* Any data that will be put in an SQL query should
* be be escaped. This is especially important for data
* that comes from untrusted sources such as Internet users.
*
* For example if you had the following SQL query:
* Another way to avoid this problem is to use a PreparedStatement
* with appropriate place holders.
*
* @param s String to be escaped
* @return escaped String
* @throws NullPointerException if s is null.
*
* @since ostermillerutils 1.00.00
*/
public static String escapeSQL(String s){
int length = s.length();
int newLength = length;
// first check for characters that might
// be dangerous and calculate a length
// of the string that has escapes.
for (int i=0; i
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it contains any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getContainsAnyPattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?s).*");
buildFindAnyPattern(terms, sb);
sb.append(".*");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* equals any of the given terms.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it equals any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getEqualsAnyPattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?s)\\A");
buildFindAnyPattern(terms, sb);
sb.append("\\z");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* starts with any of the given terms.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it starts with any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getStartsWithAnyPattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?s)\\A");
buildFindAnyPattern(terms, sb);
sb.append(".*");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* ends with any of the given terms.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it ends with any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getEndsWithAnyPattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?s).*");
buildFindAnyPattern(terms, sb);
sb.append("\\z");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* contains any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it contains any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getContainsAnyIgnoreCasePattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?i)(?u)(?s).*");
buildFindAnyPattern(terms, sb);
sb.append(".*");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* equals any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it equals any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getEqualsAnyIgnoreCasePattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?i)(?u)(?s)\\A");
buildFindAnyPattern(terms, sb);
sb.append("\\z");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* starts with any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it starts with any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getStartsWithAnyIgnoreCasePattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?i)(?u)(?s)\\A");
buildFindAnyPattern(terms, sb);
sb.append(".*");
return Pattern.compile(sb.toString());
}
/**
* Compile a pattern that can will match a string if the string
* ends with any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* Usage:
* If multiple strings are matched against the same set of terms,
* it is more efficient to reuse the pattern returned by this function.
*
* @param terms Array of search strings.
* @return Compiled pattern that can be used to match a string to see if it ends with any of the terms.
*
* @since ostermillerutils 1.02.25
*/
public static Pattern getEndsWithAnyIgnoreCasePattern(String[] terms){
StringBuffer sb = new StringBuffer();
sb.append("(?i)(?u)(?s).*");
buildFindAnyPattern(terms, sb);
sb.append("\\z");
return Pattern.compile(sb.toString());
}
/**
* Tests to see if the given string contains any of the given terms.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getContainsAnyPattern(String[])
*
* @param s String that may contain any of the given terms.
* @param terms list of substrings that may be contained in the given string.
* @return true iff one of the terms is a substring of the given string.
*
* @since ostermillerutils 1.02.25
*/
public static boolean containsAny(String s, String[] terms){
return getContainsAnyPattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string equals any of the given terms.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getEqualsAnyPattern(String[])
*
* @param s String that may equal any of the given terms.
* @param terms list of strings that may equal the given string.
* @return true iff one of the terms is equal to the given string.
*
* @since ostermillerutils 1.02.25
*/
public static boolean equalsAny(String s, String[] terms){
return getEqualsAnyPattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string starts with any of the given terms.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getStartsWithAnyPattern(String[])
*
* @param s String that may start with any of the given terms.
* @param terms list of strings that may start with the given string.
* @return true iff the given string starts with one of the given terms.
*
* @since ostermillerutils 1.02.25
*/
public static boolean startsWithAny(String s, String[] terms){
return getStartsWithAnyPattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string ends with any of the given terms.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getEndsWithAnyPattern(String[])
*
* @param s String that may end with any of the given terms.
* @param terms list of strings that may end with the given string.
* @return true iff the given string ends with one of the given terms.
*
* @since ostermillerutils 1.02.25
*/
public static boolean endsWithAny(String s, String[] terms){
return getEndsWithAnyPattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string contains any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getContainsAnyIgnoreCasePattern(String[])
*
* @param s String that may contain any of the given terms.
* @param terms list of substrings that may be contained in the given string.
* @return true iff one of the terms is a substring of the given string.
*
* @since ostermillerutils 1.02.25
*/
public static boolean containsAnyIgnoreCase(String s, String[] terms){
return getContainsAnyIgnoreCasePattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string equals any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getEqualsAnyIgnoreCasePattern(String[])
*
* @param s String that may equal any of the given terms.
* @param terms list of strings that may equal the given string.
* @return true iff one of the terms is equal to the given string.
*
* @since ostermillerutils 1.02.25
*/
public static boolean equalsAnyIgnoreCase(String s, String[] terms){
return getEqualsAnyIgnoreCasePattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string starts with any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getStartsWithAnyIgnoreCasePattern(String[])
*
* @param s String that may start with any of the given terms.
* @param terms list of strings that may start with the given string.
* @return true iff the given string starts with one of the given terms.
*
* @since ostermillerutils 1.02.25
*/
public static boolean startsWithAnyIgnoreCase(String s, String[] terms){
return getStartsWithAnyIgnoreCasePattern(terms).matcher(s).matches();
}
/**
* Tests to see if the given string ends with any of the given terms.
*
* Case is ignored when matching using Unicode case rules.
*
* This implementation is more efficient than the brute force approach
* of testing the string against each of the terms. It instead compiles
* a single regular expression that can test all the terms at once, and
* uses that expression against the string.
*
* This is a convenience method. If multiple strings are tested against
* the same set of terms, it is more efficient not to compile the regular
* expression multiple times.
* @see #getEndsWithAnyIgnoreCasePattern(String[])
*
* @param s String that may end with any of the given terms.
* @param terms list of strings that may end with the given string.
* @return true iff the given string ends with one of the given terms.
*
* @since ostermillerutils 1.02.25
*/
public static boolean endsWithAnyIgnoreCase(String s, String[] terms){
return getEndsWithAnyIgnoreCasePattern(terms).matcher(s).matches();
}
}
* StringHelper.replace("-1--2-", "-", "|");
* result: "|1||2|"
* StringHelper.replace("123", "", "|");
* result: "123"
* StringHelper.replace("1-2---3----4", "--", "|");
* result: "1-2|-3||4"
* StringHelper.replace("1-2---3----4", "--", "---");
* result: "1-2----3------4"
*
* @param s String to be modified.
* @param find String to find.
* @param replace String to replace.
* @return a string with all the occurrences of the string to find replaced.
* @throws NullPointerException if s is null.
*
* @since ostermillerutils 1.00.00
*/
public static String replace(String s, String find, String replace){
int findLength;
// the next statement has the side effect of throwing a null pointer
// exception if s is null.
int stringLength = s.length();
if (find == null || (findLength = find.length()) == 0){
// If there is nothing to find, we won't try and find it.
return s;
}
if (replace == null){
// a null string and an empty string are the same
// for replacement purposes.
replace = "";
}
int replaceLength = replace.length();
// We need to figure out how long our resulting string will be.
// This is required because without it, the possible resizing
// and copying of memory structures could lead to an unacceptable runtime.
// In the worst case it would have to be resized n times with each
// resize having a O(n) copy leading to an O(n^2) algorithm.
int length;
if (findLength == replaceLength){
// special case in which we don't need to count the replacements
// because the count falls out of the length formula.
length = stringLength;
} else {
int count;
int start;
int end;
// Scan s and count the number of times we find our target.
count = 0;
start = 0;
while((end = s.indexOf(find, start)) != -1){
count++;
start = end + findLength;
}
if (count == 0){
// special case in which on first pass, we find there is nothing
// to be replaced. No need to do a second pass or create a string buffer.
return s;
}
length = stringLength - (count * (findLength - replaceLength));
}
int start = 0;
int end = s.indexOf(find, start);
if (end == -1){
// nothing was found in the string to replace.
// we can get this if the find and replace strings
// are the same length because we didn't check before.
// in this case, we will return the original string
return s;
}
// it looks like we actually have something to replace
// *sigh* allocate memory for it.
StringBuffer sb = new StringBuffer(length);
// Scan s and do the replacements
while (end != -1){
sb.append(s.substring(start, end));
sb.append(replace);
start = end + findLength;
end = s.indexOf(find, start);
}
end = stringLength;
sb.append(s.substring(start, end));
return (sb.toString());
}
/**
* Replaces characters that may be confused by a HTML
* parser with their equivalent character entity references.
*
* Server: What is your name?
* User: <b>Joe<b>
* Server: Hello Joe, Welcome
* If the name is put on the page without checking that it doesn't
* contain HTML code or without sanitizing that HTML code, the user
* could reformat the page, insert scripts, and control the the
* content on your web server.
*
* <html><body>This in not a <tag>
* in HTML</body></html>
* and
* <form><input type="hidden" name="date" value="This data could
* be "malicious""></form>
* In the second example, the form data would be properly be resubmitted
* to your CGI script in the URLEncoded format:
* This data could be %22malicious%22
*
* @param s String to be escaped
* @return escaped String
* @throws NullPointerException if s is null.
*
* @since ostermillerutils 1.00.00
*/
public static String escapeHTML(String s){
int length = s.length();
int newLength = length;
boolean someCharacterEscaped = false;
// first check for characters that might
// be dangerous and calculate a length
// of the string that has escapes.
for (int i=0; i
* "SELECT * FROM addresses WHERE name='" + name + "' AND private='N'"
* Without this function a user could give " OR 1=1 OR ''='"
* as their name causing the query to be:
* "SELECT * FROM addresses WHERE name='' OR 1=1 OR ''='' AND private='N'"
* which will give all addresses, including private ones.
* Correct usage would be:
* "SELECT * FROM addresses WHERE name='" + StringHelper.escapeSQL(name) + "' AND private='N'"
*
* boolean b = getContainsAnyPattern(terms).matcher(s).matches();
*
* boolean b = getEqualsAnyPattern(terms).matcher(s).matches();
*
* boolean b = getStartsWithAnyPattern(terms).matcher(s).matches();
*
* boolean b = getEndsWithAnyPattern(terms).matcher(s).matches();
*
* boolean b = getContainsAnyPattern(terms).matcher(s).matches();
*
* boolean b = getEqualsAnyPattern(terms).matcher(s).matches();
*
* boolean b = getStartsWithAnyPattern(terms).matcher(s).matches();
*
* boolean b = getEndsWithAnyPattern(terms).matcher(s).matches();
*