Package com.e1c.langtool.common
Class StringUtils
java.lang.Object
com.e1c.langtool.common.StringUtils
The common utilities to process or check string content.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe empty stringstatic final String[]The empty array of stringsstatic final PatternThe Constant to find that string not contains words RegEx: ^[\s\W_\d]+$static final PatternRegular expression pattern to extract parameters enclosed in percent signs from a string.static final PatternRegular expression pattern to extract parameters enclosed in square brackets from a string. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalize(String source) Capitalize the string.getParamsIndexesFromString(String text, List<Pattern> patterns) Gets parameters from a string.static booleanReturns true if the given string is whitespace or null.static booleanisCamelCase(String text) Returns true if the given string is written inCamelCase.static booleanisLowerCase(String content) Checks if the content is lower case.static booleanisNotEmpty(String string) Checks if given string is not empty.static booleanChecks if the string is not word or contains words.static booleanisNullOrEmpty(String string) Returnstrueif the given string is null or is the empty string.static booleanisUpperCase(String content) Checks if the content is upper case.static StringnameToText(String nameInput) Convert CamleCase Name string to text with spaces.replaceStringLiteralParams(String original, List<String> translations) Replaces parameters of the form %Parameter% or [Parameter] in the translated string with their original values.static StringtextToCamelCase(String name) Converts name in plain text to camel case.
-
Field Details
-
EMPTY_ARRAY
The empty array of strings -
EMPTY
The empty string- See Also:
-
NON_WORD_PATTERN
The Constant to find that string not contains words RegEx: ^[\s\W_\d]+$ -
SQUARE_BRACKETS_PARAMETER_PATTERN
Regular expression pattern to extract parameters enclosed in square brackets from a string. Used for parsing and processing strings containing parameters in square brackets. -
PERCENT_PARAMETER_PATTERN
Regular expression pattern to extract parameters enclosed in percent signs from a string. Used for parsing and processing strings containing parameters in percent signs, e.g., %Parameter%.
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
isNullOrEmpty
Returnstrueif the given string is null or is the empty string.- Parameters:
string- a string reference to check- Returns:
trueif the string is null or is the empty string
-
isNotEmpty
Checks if given string is not empty.- Parameters:
string- the string to check- Returns:
true, if the string is not empty
-
capitalize
Capitalize the string. Has no effect for capitalized, null or empty strings.- Parameters:
source- the source string to capitalize, can benullor empty.- Returns:
- the capitalized string
-
isCamelCase
Returns true if the given string is written inCamelCase.StringUtils.isCamelCase("MrRobot") = true StringUtils.isCamelCase("mrRobot") = true StringUtils.isCamelCase("mrrobot") = true StringUtils.isCamelCase("Mr Robot") = false StringUtils.isCamelCase(" MrRobot ") = true StringUtils.isCamelCase("Mr.Robot") = true StringUtils.isCamelCase("mr.robot") = true StringUtils.isCamelCase("Mr. Robot") = false StringUtils.isCamelCase(null) = false StringUtils.isCamelCase("") = false StringUtils.isCamelCase(" ") = false- Parameters:
text- the string to check aCamelCasenotation- Returns:
- true if the given string is written in
CamelCase
-
isBlank
Returns true if the given string is whitespace or null.StringUtils.isBlank(null) = true StringUtils.isBlank(" ") = true StringUtils.isBlank("\t \n") = true StringUtils.isBlank("12") = false StringUtils.isBlank(" 12 ") = false- Parameters:
str- the string to check (it may be null)- Returns:
- true if the given string is whitespace or null
-
isNotWord
Checks if the string is not word or contains words. All special symbols ±!@#$%^&*()~`<>?/\ etc. or digits or spaces, tabs, new line etc. are non word.- Parameters:
str- the sting to check- Returns:
- true, if it is not word
-
textToCamelCase
Converts name in plain text to camel case.- Parameters:
name- a name in plain text- Returns:
- the given name converted to camel case
-
nameToText
Convert CamleCase Name string to text with spaces.- Parameters:
nameInput- the name input- Returns:
- the string
-
isUpperCase
Checks if the content is upper case.- Parameters:
content- the content to check for upper case, cannot benull.- Returns:
- true, if the content is upper case only
-
isLowerCase
Checks if the content is lower case.- Parameters:
content- the content to check for lower case, cannot benull.- Returns:
- true, if the content is lower case only
-
getParamsIndexesFromString
public static List<Pair<Integer,Integer>> getParamsIndexesFromString(String text, List<Pattern> patterns) Gets parameters from a string. Parameters can be enclosed in [parameter] or %parameter%- Parameters:
text- the text, cannot benullpatterns- the patterns, list of patterns, cannot benull- Returns:
- the list of index parameters from string, cannot be
null
-
replaceStringLiteralParams
Replaces parameters of the form %Parameter% or [Parameter] in the translated string with their original values. Such parameters are translated separately.- Parameters:
original- the original string, cannot benulltranslations- the translations, cannot benull- Returns:
- the list of replaced translations, cannot be
null
-