Package org.apache.any23.util
Class StringUtils
- java.lang.Object
-
- org.apache.any23.util.StringUtils
-
public class StringUtils extends Object
This class provides a set of string utility methods.- Author:
- Michele Mostarda (mostarda@fbk.eu)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcountNL(String in)Counts the number ofNLin the given in string.static intcountOccurrences(String container, String content)Counts how many timescontentappears withincontainerwithout string overlapping.static StringescapeAsJSONString(String in)Escapes theinstring as JSON string to let it being embeddable within a string field.static StringescapeDoubleQuotes(String in)Escapes all the unescaped double quotes when needed.static StringimplementJavaNaming(String in)Changes string with following convention: Changes '-' -> '_' remove space characters and make first letter word uppercase: 'some string' -> 'someString' If input string does not contains a whitespace than return unchanged.static booleanisPrefix(String candidatePrefix, String container)Check whether stringcandidatePrefixis prefix of stringcontainer.static booleanisSuffix(String candidateSuffix, String container)Check whether stringcandidateSuffixis suffix of stringcontainer.static Stringjoin(String delimiter, String... data)Joins the given input stingdatalist using the specifieddelimiter.static Stringmultiply(char c, int times)Builds a string composed of the given charcntimes.
-
-
-
Method Detail
-
join
public static String join(String delimiter, String... data)
Joins the given input stingdatalist using the specifieddelimiter.- Parameters:
delimiter- string delimiter.data- list of data to be joined.- Returns:
- the joined string.
-
countOccurrences
public static int countOccurrences(String container, String content)
Counts how many timescontentappears withincontainerwithout string overlapping.- Parameters:
container- container string.content- content string.- Returns:
- occurrences count.
-
countNL
public static int countNL(String in)
Counts the number ofNLin the given in string.- Parameters:
in- input string.- Returns:
- the number of new line chars.
-
isPrefix
public static boolean isPrefix(String candidatePrefix, String container)
Check whether stringcandidatePrefixis prefix of stringcontainer.- Parameters:
candidatePrefix- prefix to checkcontainer- container to check against- Returns:
trueifcandidatePrefixis prefix ofcontainer,falseotherwise.
-
isSuffix
public static boolean isSuffix(String candidateSuffix, String container)
Check whether stringcandidateSuffixis suffix of stringcontainer.- Parameters:
candidateSuffix- suffix to checkcontainer- container to check against- Returns:
trueifcandidateSuffixis prefix ofcontainer,falseotherwise.
-
escapeDoubleQuotes
public static String escapeDoubleQuotes(String in)
Escapes all the unescaped double quotes when needed.- Parameters:
in- input string.- Returns:
- unescaped output.
-
escapeAsJSONString
public static String escapeAsJSONString(String in)
Escapes theinstring as JSON string to let it being embeddable within a string field.- Parameters:
in- string to be escaped.- Returns:
- escaped string.
-
multiply
public static String multiply(char c, int times)
Builds a string composed of the given charcntimes.- Parameters:
c- char to be multiplied.times- number of times.- Returns:
- the string containing the multiplied char.
-
implementJavaNaming
public static String implementJavaNaming(String in)
Changes string with following convention:- Changes '-' -> '_'
- remove space characters and make first letter word uppercase: 'some string' -> 'someString'
- Parameters:
in- an input string to convert to Java code convention- Returns:
- the correctly formatter string as per Java spec.
-
-