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 int
countNL(String in)
Counts the number ofNL
in the given in string.static int
countOccurrences(String container, String content)
Counts how many timescontent
appears withincontainer
without string overlapping.static String
escapeAsJSONString(String in)
Escapes thein
string as JSON string to let it being embeddable within a string field.static String
escapeDoubleQuotes(String in)
Escapes all the unescaped double quotes when needed.static String
implementJavaNaming(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 boolean
isPrefix(String candidatePrefix, String container)
Check whether stringcandidatePrefix
is prefix of stringcontainer
.static boolean
isSuffix(String candidateSuffix, String container)
Check whether stringcandidateSuffix
is suffix of stringcontainer
.static String
join(String delimiter, String... data)
Joins the given input stingdata
list using the specifieddelimiter
.static String
multiply(char c, int times)
Builds a string composed of the given charc
n
times.
-
-
-
Method Detail
-
join
public static String join(String delimiter, String... data)
Joins the given input stingdata
list 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 timescontent
appears withincontainer
without string overlapping.- Parameters:
container
- container string.content
- content string.- Returns:
- occurrences count.
-
countNL
public static int countNL(String in)
Counts the number ofNL
in 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 stringcandidatePrefix
is prefix of stringcontainer
.- Parameters:
candidatePrefix
- prefix to checkcontainer
- container to check against- Returns:
true
ifcandidatePrefix
is prefix ofcontainer
,false
otherwise.
-
isSuffix
public static boolean isSuffix(String candidateSuffix, String container)
Check whether stringcandidateSuffix
is suffix of stringcontainer
.- Parameters:
candidateSuffix
- suffix to checkcontainer
- container to check against- Returns:
true
ifcandidateSuffix
is prefix ofcontainer
,false
otherwise.
-
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 thein
string 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 charc
n
times.- 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.
-
-