Class StringUtils
java.lang.Object
org.apache.groovy.parser.antlr4.util.StringUtils
Utilities for handling strings
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSlashy kind for a$/.../$string.static final intSlashy kind for an ordinary string.static final intSlashy kind for a/.../string. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longCounts how many UTF-16 code units intextequalc.static booleanisEmpty(CharSequence cs) Copied from Apache commons-lang3-3.6static booleanReports whether the whole oftextmatchespattern.static StringReplaces every\r\nintextwith\n.static StringThe modified implementation is based on StringUtils#replace(String text, String searchString, String replacement, int max), Apache commons-lang3-3.6static StringreplaceEscapes(String text, int slashyType) Rewrites escapes intextaccording toslashyType.static StringreplaceHexEscapes(String text) Replaces each\uXXXXwhose leading backslashes are even with the corresponding character.static StringreplaceOctalEscapes(String text) Replaces an octal escape of up to three digits, when its leading backslashes are even, with the corresponding character.static StringreplaceStandardEscapes(String text) Replaces\b,\t,\n,\f,\r,\s(a space),\", and\'when the leading backslashes are even.static StringtrimQuotations(String text, int quotationLength) DropsquotationLengthcharacters from each end oftext.
-
Field Details
-
NONE_SLASHY
public static final int NONE_SLASHYSlashy kind for an ordinary string.replaceEscapes(java.lang.String, int)then rewrites hex, octal, and standard escapes, drops a backslash that continues a line, and turns\$into$.- See Also:
-
SLASHY
public static final int SLASHYSlashy kind for a/.../string.replaceEscapes(java.lang.String, int)rewrites hex escapes, drops a backslash that continues a line, and turns\/into/.- See Also:
-
DOLLAR_SLASHY
public static final int DOLLAR_SLASHYSlashy kind for a$/.../$string.replaceEscapes(java.lang.String, int)rewrites hex escapes, drops a backslash that continues a line, turns$/into/, and turns$$into$.- See Also:
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
replaceEscapes
Rewrites escapes intextaccording toslashyType.NONE_SLASHYapplies the full set used for an ordinary string.SLASHYandDOLLAR_SLASHYapply the smaller slashy sets. Any otherslashyTypeis rejected.- Parameters:
text- source text, still containing escape sequencesslashyType-NONE_SLASHY,SLASHY, orDOLLAR_SLASHY- Returns:
textwith those escapes replaced
-
replaceHexEscapes
Replaces each\uXXXXwhose leading backslashes are even with the corresponding character. A match with an odd run of backslashes is left unchanged. A string that contains no backslash is returned as it was given.- Parameters:
text- source text- Returns:
textwith those hex escapes replaced
-
replaceOctalEscapes
Replaces an octal escape of up to three digits, when its leading backslashes are even, with the corresponding character. A match with an odd run of backslashes is left unchanged. A string that contains no backslash is returned as it was given.- Parameters:
text- source text- Returns:
textwith those octal escapes replaced
-
replaceStandardEscapes
Replaces\b,\t,\n,\f,\r,\s(a space),\", and\'when the leading backslashes are even. Any other escaped character is kept. Each remaining\\then becomes one backslash. A string that contains no backslash is returned as it was given.- Parameters:
text- source text- Returns:
textwith those standard escapes replaced
-
removeCR
Replaces every\r\nintextwith\n. A lone\ris left in place.- Parameters:
text- source text- Returns:
textwith CRLF pairs folded to LF
-
countChar
Counts how many UTF-16 code units intextequalc.- Parameters:
text- source textc- code unit to count- Returns:
- how many times
coccurs
-
trimQuotations
DropsquotationLengthcharacters from each end oftext. Whentextis exactly twice that long, the result is empty.- Parameters:
text- quoted text, including the quote charactersquotationLength- number of characters in one quote delimiter- Returns:
- the characters between the two delimiters
-
matches
Reports whether the whole oftextmatchespattern.- Parameters:
text- text to testpattern- pattern applied withMatcher.matches()- Returns:
truewhenpatternmatches all oftext
-
replace
The modified implementation is based on StringUtils#replace(String text, String searchString, String replacement, int max), Apache commons-lang3-3.6Replaces all occurrences of a String within another String.
A
nullreference passed to this method is a no-op.StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace it with, may be null- Returns:
- the text with any replacements processed,
nullif null String input
-
isEmpty
Copied from Apache commons-lang3-3.6Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = falseNOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is empty or null
-