-
public final class StringsA minimal String utility class. Designed for internal dom use only.
-
-
Field Summary
Fields Modifier and Type Field Description public final static Array<String>emptyStringArraypublic final static charCOMMApublic final static StringCOMMA_STRpublic final static charESCAPE_CHARpublic final static PatternHTML_CHARSET_PATTERNpublic final static PatternPRICE_PATTERNpublic final static StringDEFAULT_KEEP_CHARSpublic final static StringHTML_TAG_REGEXpublic final static StringFLOAT_REGEXpublic static PatternFLOAT_PATTERNpublic static PatternHTML_TAG_PATTERNpublic final static StringNUMERIC_LIKE_REGEXpublic static PatternNUMERIC_LIKE_PATTERNpublic final static StringMONEY_LIKE_REGEXpublic static PatternMONEY_LIKE_PATTERNpublic final static StringCHINESE_PHONE_NUMBER_LIKE_REGEXpublic static PatternCHINESE_PHONE_NUMBER_LIKE_PATTERNpublic final static StringIP_PORT_REGEXpublic final static PatternIP_PORT_PATTERNpublic final static intCODE_KEYBOARD_WHITESPACEpublic final static intCODE_NBSPpublic final static StringKEYBOARD_WHITESPACEpublic final static StringNBSPpublic final static Array<char>HEX_DIGITSpublic final static Array<String>paddingpublic final static Comparator<String>LongerFirstComparatorpublic final static Comparator<String>ShorterFirstComparatorpublic final static PatternPatternTime
-
Method Summary
Modifier and Type Method Description static intcountTimeString(String text)countTimeString. static booleanisActuallyWhitespace(int c)Tests if a code point is "whitespace" as defined by what it looks like. static StringtoHexString(ByteBuffer buf)Convenience call for toHexString, where sep = null; lineLen = Integer.MAX_VALUE.static StringtoHexString(ByteBuffer buf, String sep, int lineLen)Get a text representation of a ByteBuffer as hexadecimal String, where eachpair of hexadecimal digits corresponds to consecutive bytes in the array. static StringtoHexString(Array<byte> buf)Convenience call for toHexString, where sep = null; lineLen = Integer.MAX_VALUE.static StringtoHexString(Array<byte> buf, String sep, int lineLen)Get a text representation of a byte[] as hexadecimal String, where eachpair of hexadecimal digits corresponds to consecutive bytes in the array. static StringtoHexString(Array<byte> buf, int of, int cb, String sep, int lineLen)Get a text representation of a byte[] as hexadecimal String, where eachpair of hexadecimal digits corresponds to consecutive bytes in the array. static booleanisChinese(char c)isChinese. static booleanisChinese(String text)isChinese. static booleanisMainlyChinese(String text, double percentage)isMainlyChinese. static intcountChinese(String text)countChinese. static booleanisChineseByREG(String str)isChineseByREG. static booleanisChineseCharByREG(char ch)isChineseCharByREG. static booleanisChineseByName(String str)isChineseByName. static StringstripNonChar(String text)stripNonChar. static StringstripNonChar(String text, String keeps)stripNonChar. static StringtrimNonChar(String text)trimNonChar. static StringtrimNonChar(String text, String keeps)trimNonChar. static booleanisCJK(char ch)isCJK. static StringstripNonCJKChar(String text)stripNonCJKChar. static StringstripNonCJKChar(String text, String keeps)stripNonCJKChar. static StringtrimNonCJKChar(String text)trimNonCJKChar. static StringtrimNonCJKChar(String text, String keeps)trimNonCJKChar. static StringstripNonPrintableChar(String text)stripNonPrintableChar. static booleanisPrintableUnicodeChar(char ch)isPrintableUnicodeChar. static StringcleanField(String value)Copy from pulsar , remove "�" static StringgetLongestPart(String text, Pattern pattern)getLongestPart. static StringgetLongestPart(String text, String regex)getLongestPart. static Stringcsslize(String text)csslize. static Stringhumanize(String text)humanize. static Stringhumanize(String text, String seperator)humanize. static Stringhumanize(String text, String suffix, String seperator)humanize. static Stringhumanize(Class clazz, String suffix, String seperator)humanize. static intgetLeadingInteger(String s, int defaultValue)getLeadingInteger. static intgetTailingInteger(String s, int defaultValue)getTailingInteger. static intgetFirstInteger(String s, int defaultValue)getFirstInteger. static intgetLastInteger(String s, int defaultValue)getLastInteger. static floatgetFirstFloatNumber(String s, float defaultValue)getFirstFloatNumber. static floatgetLastFloatNumber(String s, float defaultValue)getLastFloatNumber. static booleancontains(String text, Array<CharSequence> searchCharSequences)contains. static booleancontainsAny(String text, Array<CharSequence> searchCharSequences)containsAny. static booleancontainsNone(String text, Array<CharSequence> searchCharSequences)containsNone. static StringstringifyException(Throwable e)stringifyException. static StringsimplifyException(@NotNull() Throwable e)simplifyException. static Stringreverse(String s)reverse. static StringdoubleQuoteIfContainsWhitespace(String s)doubleQuoteIfContainsWhitespace. static StringreadableBytes(int bytes)readableBytes. static StringreadableBytes(long bytes)readableBytes. static StringreadableBytes(int bytes, boolean si)readableBytes. static StringreadableBytes(long bytes, boolean si)readableBytes. static StringreadableBytes(int bytes, int scale, boolean si)readableBytes. static StringreadableBytes(long bytes, int scale, boolean si)readableBytes. static Map<String, String>parseKvs(String line)Parse key-value pairs in a line, for example :"a=1 b=2 c=3", "x:1 y:2 z:3" static Map<String, String>parseKvs(String line, String delimiter)Parse key-value pairs in a line, for example :"a=1 b=2 c=3", "x:1 y:2 z:3" static List<String>getUnslashedLines(String allLines)All lines separated by back slashes are merged together static List<String>getUnslashedLines(String allLines, String EOL)getUnslashedLines. static StringmergeSlashedLine(String slashedLine)Merge lines concatenated with back slash, for example :The line "Java Stream API is very very usefull \\\n"" and we use them everywhere "can be merged into "Java Stream API is very very usefull and we use them everywhere" static List<String>mergeSlashedLines(Iterable<String> linesWithSlash)All lines separated by back slashes are merged together static intgetLongestCommonSubstring(String a, String b)getLongestCommonSubstring. static StringreplaceCharsetInHtml(String html, String charset)Not completely tested static Array<String>getStrings(String str)Returns an arraylist of strings. static StringarrayToString(Array<String> strs)arrayToString. static Collection<String>getStringCollection(String str)Returns a collection of strings. static Collection<String>getStringCollection(String str, String delim)Returns a collection of strings. static Collection<String>getTrimmedStringCollection(String str)Splits a comma separated value String, trimming leading and trailing whitespace on each value.Duplicate and empty values are removed.static Array<String>getTrimmedStrings(String str)Splits a comma separated value String, trimming leading and trailing whitespace on each value.static booleanhasHTMLTags(String text)hasHTMLTags. static booleanisFloat(String text)isFloat. static booleanisNumericLike(String text)isNumericLike. static booleanisMoneyLike(String text)https://www.regextester. static booleanisIpPortLike(String text)isIpPortLike. static booleanisIpLike(String text)isIpLike. -
-
Method Detail
-
countTimeString
static int countTimeString(String text)
countTimeString.
- Parameters:
text- a java.lang.String object.
-
isActuallyWhitespace
static boolean isActuallyWhitespace(int c)
Tests if a code point is "whitespace" as defined by what it looks like. Used for Element.text etc.
- Parameters:
c- code point to test
-
toHexString
static String toHexString(ByteBuffer buf)
Convenience call for toHexString, where
sep = null; lineLen = Integer.MAX_VALUE.- Parameters:
buf- The byte buffer
-
toHexString
static String toHexString(ByteBuffer buf, String sep, int lineLen)
Get a text representation of a ByteBuffer as hexadecimal String, where eachpair of hexadecimal digits corresponds to consecutive bytes in the array.
- Parameters:
buf- input datasep- separate every pair of hexadecimal digits with this separator, ornull if no separation is needed.lineLen- break the output String into lines containing output for lineLenbytes.
-
toHexString
static String toHexString(Array<byte> buf)
Convenience call for toHexString, where
sep = null; lineLen = Integer.MAX_VALUE.- Parameters:
buf- the buffer
-
toHexString
static String toHexString(Array<byte> buf, String sep, int lineLen)
Get a text representation of a byte[] as hexadecimal String, where eachpair of hexadecimal digits corresponds to consecutive bytes in the array.
- Parameters:
buf- input datasep- separate every pair of hexadecimal digits with this separator, ornull if no separation is needed.lineLen- break the output String into lines containing output for lineLenbytes.
-
toHexString
static String toHexString(Array<byte> buf, int of, int cb, String sep, int lineLen)
Get a text representation of a byte[] as hexadecimal String, where eachpair of hexadecimal digits corresponds to consecutive bytes in the array.
- Parameters:
buf- input dataof- the offset into the byte[] to start readingcb- the number of bytes to read from the byte[]sep- separate every pair of hexadecimal digits with this separator, ornull if no separation is needed.lineLen- break the output String into lines containing output for lineLenbytes.
-
isChinese
static boolean isChinese(char c)
isChinese.
- Parameters:
c- a char.
-
isChinese
static boolean isChinese(String text)
isChinese.
- Parameters:
text- a java.lang.String object.
-
isMainlyChinese
static boolean isMainlyChinese(String text, double percentage)
isMainlyChinese.
- Parameters:
text- a java.lang.String object.percentage- a double.
-
countChinese
static int countChinese(String text)
countChinese.
- Parameters:
text- a java.lang.String object.
-
isChineseByREG
static boolean isChineseByREG(String str)
isChineseByREG.
- Parameters:
str- a java.lang.String object.
-
isChineseCharByREG
static boolean isChineseCharByREG(char ch)
isChineseCharByREG.
- Parameters:
ch- a char.
-
isChineseByName
static boolean isChineseByName(String str)
isChineseByName.
- Parameters:
str- a java.lang.String object.
-
stripNonChar
static String stripNonChar(String text)
stripNonChar.
- Parameters:
text- a java.lang.String object.
-
stripNonChar
static String stripNonChar(String text, String keeps)
stripNonChar.
- Parameters:
text- a java.lang.String object.keeps- a java.lang.String object.
-
trimNonChar
static String trimNonChar(String text)
trimNonChar.
- Parameters:
text- a java.lang.String object.
-
trimNonChar
static String trimNonChar(String text, String keeps)
trimNonChar.
- Parameters:
text- a java.lang.String object.keeps- a java.lang.String object.
-
isCJK
static boolean isCJK(char ch)
isCJK.
- Parameters:
ch- a char.
-
stripNonCJKChar
static String stripNonCJKChar(String text)
stripNonCJKChar.
- Parameters:
text- a java.lang.String object.
-
stripNonCJKChar
static String stripNonCJKChar(String text, String keeps)
stripNonCJKChar.
- Parameters:
text- a java.lang.String object.keeps- a java.lang.String object.
-
trimNonCJKChar
static String trimNonCJKChar(String text)
trimNonCJKChar.
- Parameters:
text- a java.lang.String object.
-
trimNonCJKChar
static String trimNonCJKChar(String text, String keeps)
trimNonCJKChar.
- Parameters:
text- a java.lang.String object.keeps- a java.lang.String object.
-
stripNonPrintableChar
static String stripNonPrintableChar(String text)
stripNonPrintableChar.
- Parameters:
text- a java.lang.String object.
-
isPrintableUnicodeChar
static boolean isPrintableUnicodeChar(char ch)
isPrintableUnicodeChar.
- Parameters:
ch- a char.
-
cleanField
static String cleanField(String value)
Copy from pulsar , remove "�"
- Parameters:
value- the dirty String value.
-
getLongestPart
static String getLongestPart(String text, Pattern pattern)
getLongestPart.
- Parameters:
text- a java.lang.String object.pattern- a java.util.regex.Pattern object.
-
getLongestPart
static String getLongestPart(String text, String regex)
getLongestPart.
- Parameters:
text- a java.lang.String object.regex- a java.lang.String object.
-
csslize
static String csslize(String text)
csslize.
- Parameters:
text- a java.lang.String object.
-
humanize
static String humanize(String text)
humanize.
- Parameters:
text- a java.lang.String object.
-
humanize
static String humanize(String text, String seperator)
humanize.
- Parameters:
text- a java.lang.String object.seperator- a java.lang.String object.
-
humanize
static String humanize(String text, String suffix, String seperator)
humanize.
- Parameters:
text- a java.lang.String object.suffix- a java.lang.String object.seperator- a java.lang.String object.
-
humanize
static String humanize(Class clazz, String suffix, String seperator)
humanize.
- Parameters:
clazz- a java.lang.Class object.suffix- a java.lang.String object.seperator- a java.lang.String object.
-
getLeadingInteger
static int getLeadingInteger(String s, int defaultValue)
getLeadingInteger.
- Parameters:
s- a java.lang.String object.defaultValue- a int.
-
getTailingInteger
static int getTailingInteger(String s, int defaultValue)
getTailingInteger.
- Parameters:
s- a java.lang.String object.defaultValue- a int.
-
getFirstInteger
static int getFirstInteger(String s, int defaultValue)
getFirstInteger.
- Parameters:
s- The string that might contain a integer number.defaultValue- the default value if the string has no any integer number.
-
getLastInteger
static int getLastInteger(String s, int defaultValue)
getLastInteger.
TODO: do not support prefix +-
- Parameters:
s- The string that might contain a integer number.defaultValue- the default value if the string has no any integer number.
-
getFirstFloatNumber
static float getFirstFloatNumber(String s, float defaultValue)
getFirstFloatNumber.
- Parameters:
s- The string that might contain a float number.defaultValue- the default value if the string has no any float number.
-
getLastFloatNumber
static float getLastFloatNumber(String s, float defaultValue)
getLastFloatNumber.
- Parameters:
s- The string that might contain a float number.defaultValue- the default value if the string has no any float number.
-
contains
static boolean contains(String text, Array<CharSequence> searchCharSequences)
contains.
- Parameters:
text- a java.lang.String object.searchCharSequences- a java.lang.CharSequence object.
-
containsAny
static boolean containsAny(String text, Array<CharSequence> searchCharSequences)
containsAny.
- Parameters:
text- a java.lang.String object.searchCharSequences- a java.lang.CharSequence object.
-
containsNone
static boolean containsNone(String text, Array<CharSequence> searchCharSequences)
containsNone.
- Parameters:
text- a java.lang.String object.searchCharSequences- a java.lang.CharSequence object.
-
stringifyException
static String stringifyException(Throwable e)
stringifyException.
- Parameters:
e- a java.lang.Throwable object.
-
simplifyException
static String simplifyException(@NotNull() Throwable e)
simplifyException.
- Parameters:
e- a java.lang.Throwable object.
-
reverse
static String reverse(String s)
reverse.
- Parameters:
s- a java.lang.String object.
-
doubleQuoteIfContainsWhitespace
static String doubleQuoteIfContainsWhitespace(String s)
doubleQuoteIfContainsWhitespace.
- Parameters:
s- a java.lang.String object.
-
readableBytes
static String readableBytes(int bytes)
readableBytes.
- Parameters:
bytes- a long.
-
readableBytes
static String readableBytes(long bytes)
readableBytes.
- Parameters:
bytes- a long.
-
readableBytes
static String readableBytes(int bytes, boolean si)
readableBytes.
- Parameters:
bytes- a long.si- a boolean.
-
readableBytes
static String readableBytes(long bytes, boolean si)
readableBytes.
- Parameters:
bytes- a long.si- a boolean.
-
readableBytes
static String readableBytes(int bytes, int scale, boolean si)
readableBytes.
- Parameters:
bytes- a long.scale- a int.si- a boolean.
-
readableBytes
static String readableBytes(long bytes, int scale, boolean si)
readableBytes.
- Parameters:
bytes- a long.scale- a int.si- a boolean.
-
parseKvs
static Map<String, String> parseKvs(String line)
Parse key-value pairs in a line, for example :"a=1 b=2 c=3", "x:1 y:2 z:3"
- Parameters:
line- The line to parse
-
parseKvs
static Map<String, String> parseKvs(String line, String delimiter)
Parse key-value pairs in a line, for example :"a=1 b=2 c=3", "x:1 y:2 z:3"
- Parameters:
line- The line to parsedelimiter- a java.lang.String object.
-
getUnslashedLines
static List<String> getUnslashedLines(String allLines)
All lines separated by back slashes are merged together
- Parameters:
allLines- All lines separated by "\n", some of them are separated by back slash
-
getUnslashedLines
static List<String> getUnslashedLines(String allLines, String EOL)
getUnslashedLines.
- Parameters:
allLines- a java.lang.String object.EOL- a java.lang.String object.
-
mergeSlashedLine
static String mergeSlashedLine(String slashedLine)
Merge lines concatenated with back slash, for example :The line "Java Stream API is very very usefull \\\n"" and we use them everywhere "can be merged into "Java Stream API is very very usefull and we use them everywhere"
- Parameters:
slashedLine- a java.lang.String object.
-
mergeSlashedLines
static List<String> mergeSlashedLines(Iterable<String> linesWithSlash)
All lines separated by back slashes are merged together
- Parameters:
linesWithSlash- Lines with back slash
-
getLongestCommonSubstring
static int getLongestCommonSubstring(String a, String b)
getLongestCommonSubstring.
- Parameters:
a- a java.lang.String object.b- a java.lang.String object.
-
replaceCharsetInHtml
static String replaceCharsetInHtml(String html, String charset)
Not completely tested
- Parameters:
html- a java.lang.String object.charset- a java.lang.String object.
-
getStrings
static Array<String> getStrings(String str)
Returns an arraylist of strings.
- Parameters:
str- the comma seperated string values
-
arrayToString
static String arrayToString(Array<String> strs)
arrayToString.
- Parameters:
strs- an array of java.lang.String objects.
-
getStringCollection
static Collection<String> getStringCollection(String str)
Returns a collection of strings.
- Parameters:
str- comma seperated string values
-
getStringCollection
static Collection<String> getStringCollection(String str, String delim)
Returns a collection of strings.
- Parameters:
str- String to parsedelim- delimiter to separate the values
-
getTrimmedStringCollection
static Collection<String> getTrimmedStringCollection(String str)
Splits a comma separated value
String, trimming leading and trailing whitespace on each value.Duplicate and empty values are removed.- Parameters:
str- a comma separated string with values
-
getTrimmedStrings
static Array<String> getTrimmedStrings(String str)
Splits a comma separated value
String, trimming leading and trailing whitespace on each value.- Parameters:
str- a comma separated String with values
-
hasHTMLTags
static boolean hasHTMLTags(String text)
hasHTMLTags.
- Parameters:
text- a java.lang.String object.
-
isFloat
static boolean isFloat(String text)
isFloat.
- Parameters:
text- a java.lang.String object.
-
isNumericLike
static boolean isNumericLike(String text)
isNumericLike.
- Parameters:
text- a java.lang.String object.
-
isMoneyLike
static boolean isMoneyLike(String text)
https://www.regextester.com/97725
- Parameters:
text- a java.lang.String object.
-
isIpPortLike
static boolean isIpPortLike(String text)
isIpPortLike.
- Parameters:
text- a java.lang.String object.
-
isIpLike
static boolean isIpLike(String text)
isIpLike.
- Parameters:
text- a java.lang.String object.
-
-
-
-