Class StringUtils
- java.lang.Object
-
- org.eclipse.jgit.util.StringUtils
-
public final class StringUtils extends java.lang.ObjectMiscellaneous string comparison utility methods.
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]LC
-
Constructor Summary
Constructors Modifier Constructor Description privateStringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringcapitalize(java.lang.String str)Borrowed from commons-langStringUtils.capitalize()method.static intcompareIgnoreCase(java.lang.String a, java.lang.String b)Compare two strings, ignoring case.static intcompareWithCase(java.lang.String a, java.lang.String b)Compare two strings, honoring case.static booleanequalsIgnoreCase(java.lang.String a, java.lang.String b)Test if two strings are equal, ignoring case.static booleanisEmptyOrNull(java.lang.String stringValue)Test if a string is empty or null.static java.lang.Stringjoin(java.util.Collection<java.lang.String> parts, java.lang.String separator)Join a collection of Strings together using the specified separator.static java.lang.Stringjoin(java.util.Collection<java.lang.String> parts, java.lang.String separator, java.lang.String lastSeparator)Join a collection of Strings together using the specified separator and a lastSeparator which is used for joining the second last and the last part.static java.lang.StringreplaceLineBreaksWithSpace(java.lang.String in)Replace CRLF, CR or LF with a single space.static booleantoBoolean(java.lang.String stringValue)Parse a string as a standard Git boolean value.static java.lang.BooleantoBooleanOrNull(java.lang.String stringValue)Parse a string as a standard Git boolean value.static chartoLowerCase(char c)Convert the input to lowercase.static java.lang.StringtoLowerCase(java.lang.String in)Convert the input string to lower case, according to the "C" locale.
-
-
-
Method Detail
-
toLowerCase
public static char toLowerCase(char c)
Convert the input to lowercase.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale. Only characters in the range 'A' through 'Z' are converted. All other characters are left as-is, even if they otherwise would have a lowercase character equivalent.
- Parameters:
c- the input character.- Returns:
- lowercase version of the input.
-
toLowerCase
public static java.lang.String toLowerCase(java.lang.String in)
Convert the input string to lower case, according to the "C" locale.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale. Only characters in the range 'A' through 'Z' are converted, all other characters are left as-is, even if they otherwise would have a lowercase character equivalent.
- Parameters:
in- the input string. Must not be null.- Returns:
- a copy of the input string, after converting characters in the range 'A'..'Z' to 'a'..'z'.
-
capitalize
public static java.lang.String capitalize(java.lang.String str)
Borrowed from commons-langStringUtils.capitalize()method.Capitalizes a String changing the first letter to title case as per
Character.toTitleCase(char). No other letters are changed.A
nullinput String returnsnull.- Parameters:
str- the String to capitalize, may be null- Returns:
- the capitalized String,
nullif null String input - Since:
- 4.0
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.String a, java.lang.String b)Test if two strings are equal, ignoring case.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.
- Parameters:
a- first string to compare.b- second string to compare.- Returns:
- true if a equals b
-
compareIgnoreCase
public static int compareIgnoreCase(java.lang.String a, java.lang.String b)Compare two strings, ignoring case.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.
- Parameters:
a- first string to compare.b- second string to compare.- Returns:
- an int.
- Since:
- 2.0
-
compareWithCase
public static int compareWithCase(java.lang.String a, java.lang.String b)Compare two strings, honoring case.This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.
- Parameters:
a- first string to compare.b- second string to compare.- Returns:
- an int.
- Since:
- 2.0
-
toBoolean
public static boolean toBoolean(java.lang.String stringValue)
Parse a string as a standard Git boolean value. SeetoBooleanOrNull(String).- Parameters:
stringValue- the string to parse.- Returns:
- the boolean interpretation of
value. - Throws:
java.lang.IllegalArgumentException- ifvalueis not recognized as one of the standard boolean names.
-
toBooleanOrNull
public static java.lang.Boolean toBooleanOrNull(java.lang.String stringValue)
Parse a string as a standard Git boolean value.The terms
yes,true,1,oncan all be used to meantrue.The terms
no,false,0,offcan all be used to meanfalse.Comparisons ignore case, via
equalsIgnoreCase(String, String).- Parameters:
stringValue- the string to parse.- Returns:
- the boolean interpretation of
valueor null in case the string does not represent a boolean value
-
join
public static java.lang.String join(java.util.Collection<java.lang.String> parts, java.lang.String separator)Join a collection of Strings together using the specified separator.- Parameters:
parts- Strings to joinseparator- used to join- Returns:
- a String with all the joined parts
-
join
public static java.lang.String join(java.util.Collection<java.lang.String> parts, java.lang.String separator, java.lang.String lastSeparator)Join a collection of Strings together using the specified separator and a lastSeparator which is used for joining the second last and the last part.- Parameters:
parts- Strings to joinseparator- separator used to join all but the two last elementslastSeparator- separator to use for joining the last two elements- Returns:
- a String with all the joined parts
-
isEmptyOrNull
public static boolean isEmptyOrNull(java.lang.String stringValue)
Test if a string is empty or null.- Parameters:
stringValue- the string to check- Returns:
trueif the string isnullor empty
-
replaceLineBreaksWithSpace
public static java.lang.String replaceLineBreaksWithSpace(java.lang.String in)
Replace CRLF, CR or LF with a single space.- Parameters:
in- A string with line breaks- Returns:
- in without line breaks
- Since:
- 3.1
-
-