public final class StringHelper extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
StringHelper.Renderer<T> |
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
BATCH_ID_PLACEHOLDER |
(专用程序包) byte[] |
BYTES_NEW_LINE |
(专用程序包) String[] |
EMPTY_ARRAY |
static String[] |
EMPTY_STRINGS |
static int |
INDEX_NOT_FOUND
Represents a failed index search.
|
static String |
WHITESPACE |
| 限定符和类型 | 方法和说明 |
|---|---|
static String[] |
add(String[] x,
String sep,
String[] y) |
static boolean |
booleanValue(String tfString) |
static String |
camelhumpToUnderline(String str)
将驼峰风格替换为下划线风格
|
static String |
collapse(String name)
Collapses a name.
|
static String |
collapseQualifier(String qualifier,
boolean includeDots)
Given a qualifier, collapse it.
|
static String |
collapseQualifierBase(String name,
String qualifierBase)
Cross between
collapse(java.lang.String) and partiallyUnqualify(java.lang.String, java.lang.String). |
static String |
convertByStyle(String str,
Style style)
根据指定的样式进行转换
|
static int |
countUnquoted(String string,
char character) |
static int |
firstIndexOfChar(String sqlString,
BitSet keys,
int startindex) |
static int |
firstIndexOfChar(String sqlString,
String string,
int startindex) |
static String |
generateAlias(String description) |
static String |
generateAlias(String description,
int unique)
Generate a nice alias for the given class name or collection role name and unique integer.
|
static char |
getFirstNonWhitespaceCharacter(String str) |
static char |
getLastNonWhitespaceCharacter(String str) |
static int |
indexOf(CharSequence seq,
CharSequence searchSeq)
Finds the first index within a CharSequence, handling
null. |
static int |
indexOf(CharSequence seq,
CharSequence searchSeq,
int startPos)
Finds the first index within a CharSequence, handling
null. |
static boolean |
isEmpty(CharSequence string) |
static boolean |
isEmptyOrWhiteSpace(String string) |
static boolean |
isLowercaseAlpha(char c) |
static boolean |
isNotEmpty(CharSequence string) |
static boolean |
isQuoted(String name)
Determine if the given string is quoted (wrapped by '`' characters at beginning and end).
|
static boolean |
isUppercaseAlpha(char c) |
static <T> String |
join(Collection<T> values,
StringHelper.Renderer<T> renderer) |
static String |
join(String separator,
Iterable objects) |
static String |
join(String seperator,
Iterator objects) |
static String |
join(String seperator,
String[] strings) |
static <T> String |
join(T[] values,
StringHelper.Renderer<T> renderer) |
static String |
joinWithQualifierAndSuffix(String[] values,
String qualifier,
String suffix,
String deliminator) |
static int |
lastIndexOf(CharSequence seq,
CharSequence searchSeq)
Finds the last index within a CharSequence, handling
null. |
static int |
lastIndexOf(CharSequence seq,
int searchChar)
Returns the index within
seq of the last occurrence of
the specified character. |
static int |
lastIndexOf(CharSequence seq,
int searchChar,
int startPos)
Returns the index within
seq of the last occurrence of
the specified character, searching backward starting at the
specified index. |
static int |
lastIndexOfLetter(String string) |
static int[] |
locateUnquoted(String string,
char character) |
static String |
moveAndToBeginning(String filter) |
static String[] |
multiply(String string,
Iterator placeholders,
Iterator replacements) |
static String |
nullIfEmpty(String value) |
static List<String> |
parseCommaSeparatedString(String incomingString) |
static String |
partiallyUnqualify(String name,
String qualifierBase)
Partially unqualifies a qualified name.
|
static String |
qualifier(String qualifiedName) |
static String |
qualify(String prefix,
String name) |
static String[] |
qualify(String prefix,
String[] names) |
static String |
qualifyConditionally(String prefix,
String name) |
static String[] |
qualifyIfNot(String prefix,
String[] names) |
static String |
quote(String name)
Return a representation of the given name ensuring quoting (wrapped with '`' characters).
|
static String |
repeat(char character,
int times) |
static String |
repeat(String string,
int times) |
static String |
repeat(String string,
int times,
String deliminator) |
static String[] |
replace(String[] templates,
String placeholder,
String replacement) |
static String |
replace(String template,
String placeholder,
String replacement) |
static String |
replace(String template,
String placeholder,
String replacement,
boolean wholeWords) |
static String |
replace(String template,
String placeholder,
String replacement,
boolean wholeWords,
boolean encloseInParensIfNecessary) |
static String |
replace(String beforePlaceholder,
String afterPlaceholder,
String placeholder,
String replacement,
boolean wholeWords,
boolean encloseInParensIfNecessary) |
static String |
replaceOnce(String template,
String placeholder,
String replacement) |
static String |
root(String qualifiedName) |
static String[] |
split(String separators,
String list) |
static String[] |
split(String separators,
String list,
boolean include) |
static String[] |
splitTrimmingTokens(String separators,
String list,
boolean include) |
static String |
substring(String str,
int start)
Gets a substring from the specified String avoiding exceptions.
|
static String |
substring(String str,
int start,
int end)
Gets a substring from the specified String avoiding exceptions.
|
static String[] |
suffix(String[] columns,
String suffix) |
static String[] |
toArrayElement(String s)
Takes a String s and returns a new String[1] with s as the only element.
|
static char |
toLowerAscii(char c) |
static String |
toString(Object[] array) |
static char |
toUpperAscii(char c) |
static String |
truncate(String string,
int length) |
static String |
underlineToCamelhump(String str)
将下划线风格替换为驼峰风格
|
static String |
unqualify(String qualifiedName) |
static String |
unqualifyEntityName(String entityName) |
static String |
unquote(String name)
Return the unquoted version of name (stripping the start and end '`' characters if present).
|
static String |
unroot(String qualifiedName) |
public static final int INDEX_NOT_FOUND
String[] EMPTY_ARRAY
byte[] BYTES_NEW_LINE
public static final String[] EMPTY_STRINGS
public static int lastIndexOfLetter(String string)
public static String joinWithQualifierAndSuffix(String[] values, String qualifier, String suffix, String deliminator)
public static String repeat(char character, int times)
public static String replace(String template, String placeholder, String replacement, boolean wholeWords)
public static String replace(String template, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary)
public static String replace(String beforePlaceholder, String afterPlaceholder, String placeholder, String replacement, boolean wholeWords, boolean encloseInParensIfNecessary)
public static char getLastNonWhitespaceCharacter(String str)
public static char getFirstNonWhitespaceCharacter(String str)
public static String replaceOnce(String template, String placeholder, String replacement)
public static String[] splitTrimmingTokens(String separators, String list, boolean include)
public static String collapse(String name)
name - The name to collapse.public static String collapseQualifier(String qualifier, boolean includeDots)
qualifier - The qualifier to collapse.includeDots - Should we include the dots in the collapsed form?public static String partiallyUnqualify(String name, String qualifierBase)
name - The (potentially) qualified name.qualifierBase - The qualifier base.public static String collapseQualifierBase(String name, String qualifierBase)
collapse(java.lang.String) and partiallyUnqualify(java.lang.String, java.lang.String). Functions much like collapse(java.lang.String)
except that only the qualifierBase is collapsed. For example, with a base of 'org.hibernate' the name
'org.hibernate.internal.util.StringHelper' would become 'o.h.util.StringHelper'.name - The (potentially) qualified name.qualifierBase - The qualifier base.public static boolean booleanValue(String tfString)
public static String[] multiply(String string, Iterator placeholders, Iterator replacements)
public static int countUnquoted(String string, char character)
public static int[] locateUnquoted(String string, char character)
public static boolean isNotEmpty(CharSequence string)
public static boolean isEmpty(CharSequence string)
public static boolean isEmptyOrWhiteSpace(String string)
public static int firstIndexOfChar(String sqlString, String string, int startindex)
public static String generateAlias(String description, int unique)
description - The base name (usually an entity-name or collection-role)unique - A uniquing valuepublic static boolean isQuoted(String name)
name - The name to check.public static String quote(String name)
name - The name to quote.public static String unquote(String name)
name - The name to be unquoted.public static String[] toArrayElement(String s)
s - public static List<String> parseCommaSeparatedString(String incomingString)
public static <T> String join(Collection<T> values, StringHelper.Renderer<T> renderer)
public static <T> String join(T[] values, StringHelper.Renderer<T> renderer)
public static String convertByStyle(String str, Style style)
str - style - public static boolean isUppercaseAlpha(char c)
public static boolean isLowercaseAlpha(char c)
public static char toUpperAscii(char c)
public static char toLowerAscii(char c)
public static int indexOf(CharSequence seq, CharSequence searchSeq, int startPos)
Finds the first index within a CharSequence, handling null.
This method uses String.indexOf(String, int) if possible.
A null CharSequence will return -1.
A negative start position is treated as zero.
An empty ("") search CharSequence always matches.
A start position greater than the string length only matches
an empty search CharSequence.
StringUtils.indexOf(null, *, *) = -1
StringUtils.indexOf(*, null, *) = -1
StringUtils.indexOf("", "", 0) = 0
StringUtils.indexOf("", *, 0) = -1 (except when * = "")
StringUtils.indexOf("aabaabaa", "a", 0) = 0
StringUtils.indexOf("aabaabaa", "b", 0) = 2
StringUtils.indexOf("aabaabaa", "ab", 0) = 1
StringUtils.indexOf("aabaabaa", "b", 3) = 5
StringUtils.indexOf("aabaabaa", "b", 9) = -1
StringUtils.indexOf("aabaabaa", "b", -1) = 2
StringUtils.indexOf("aabaabaa", "", 2) = 2
StringUtils.indexOf("abc", "", 9) = 3
seq - the CharSequence to check, may be nullsearchSeq - the CharSequence to find, may be nullstartPos - the start position, negative treated as zeronull string inputpublic static int indexOf(CharSequence seq, CharSequence searchSeq)
Finds the first index within a CharSequence, handling null.
This method uses String.indexOf(String, int) if possible.
A null CharSequence will return -1.
StringUtils.indexOf(null, *) = -1
StringUtils.indexOf(*, null) = -1
StringUtils.indexOf("", "") = 0
StringUtils.indexOf("", *) = -1 (except when * = "")
StringUtils.indexOf("aabaabaa", "a") = 0
StringUtils.indexOf("aabaabaa", "b") = 2
StringUtils.indexOf("aabaabaa", "ab") = 1
StringUtils.indexOf("aabaabaa", "") = 0
seq - the CharSequence to check, may be nullsearchSeq - the CharSequence to find, may be nullnull string inputpublic static int lastIndexOf(CharSequence seq, int searchChar)
seq of the last occurrence of
the specified character. For values of searchChar in the
range from 0 to 0xFFFF (inclusive), the index (in Unicode code
units) returned is the largest value k such that:
is true. For other values ofthis.charAt(k) == searchChar
searchChar, it is the
largest value k such that:
is true. In either case, if no such character occurs in this string, thenthis.codePointAt(k) == searchChar
-1 is returned. Furthermore, a null or empty ("")
CharSequence will return -1. The
seq CharSequence object is searched backwards
starting at the last character.
StringUtils.lastIndexOf(null, *) = -1
StringUtils.lastIndexOf("", *) = -1
StringUtils.lastIndexOf("aabaabaa", 'a') = 7
StringUtils.lastIndexOf("aabaabaa", 'b') = 5
seq - the CharSequence to check, may be nullsearchChar - the character to findnull string inputCharSequenceUtils call to behave more like Stringpublic static int lastIndexOf(CharSequence seq, int searchChar, int startPos)
seq of the last occurrence of
the specified character, searching backward starting at the
specified index. For values of searchChar in the range
from 0 to 0xFFFF (inclusive), the index returned is the largest
value k such that:
is true. For other values of(this.charAt(k) == searchChar) && (k <= startPos)
searchChar, it is the
largest value k such that:
is true. In either case, if no such character occurs in(this.codePointAt(k) == searchChar) && (k <= startPos)
seq
at or before position startPos, then
-1 is returned. Furthermore, a null or empty ("")
CharSequence will return -1. A start position greater
than the string length searches the whole string.
The search starts at the startPos and works backwards;
matches starting after the start position are ignored.
All indices are specified in char values
(Unicode code units).
StringUtils.lastIndexOf(null, *, *) = -1
StringUtils.lastIndexOf("", *, *) = -1
StringUtils.lastIndexOf("aabaabaa", 'b', 8) = 5
StringUtils.lastIndexOf("aabaabaa", 'b', 4) = 2
StringUtils.lastIndexOf("aabaabaa", 'b', 0) = -1
StringUtils.lastIndexOf("aabaabaa", 'b', 9) = 5
StringUtils.lastIndexOf("aabaabaa", 'b', -1) = -1
StringUtils.lastIndexOf("aabaabaa", 'a', 0) = 0
seq - the CharSequence to check, may be nullsearchChar - the character to findstartPos - the start positionnull string inputpublic static int lastIndexOf(CharSequence seq, CharSequence searchSeq)
Finds the last index within a CharSequence, handling null.
This method uses String.lastIndexOf(String) if possible.
A null CharSequence will return -1.
StringUtils.lastIndexOf(null, *) = -1
StringUtils.lastIndexOf(*, null) = -1
StringUtils.lastIndexOf("", "") = 0
StringUtils.lastIndexOf("aabaabaa", "a") = 7
StringUtils.lastIndexOf("aabaabaa", "b") = 5
StringUtils.lastIndexOf("aabaabaa", "ab") = 4
StringUtils.lastIndexOf("aabaabaa", "") = 8
seq - the CharSequence to check, may be nullsearchSeq - the CharSequence to find, may be nullnull string inputpublic static String substring(String str, int start)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start n
characters from the end of the String.
A null String will return null.
An empty ("") String will return "".
StringUtils.substring(null, *) = null
StringUtils.substring("", *) = ""
StringUtils.substring("abc", 0) = "abc"
StringUtils.substring("abc", 2) = "c"
StringUtils.substring("abc", 4) = ""
StringUtils.substring("abc", -2) = "bc"
StringUtils.substring("abc", -4) = "abc"
str - the String to get the substring from, may be nullstart - the position to start from, negative means
count back from the end of the String by this many charactersnull if null String inputpublic static String substring(String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n
characters from the end of the String.
The returned substring starts with the character in the start
position and ends before the end position. All position counting is
zero-based -- i.e., to start at the beginning of the string use
start = 0. Negative start and end positions can be used to
specify offsets relative to the end of the String.
If start is not strictly to the left of end, ""
is returned.
StringUtils.substring(null, *, *) = null
StringUtils.substring("", * , *) = "";
StringUtils.substring("abc", 0, 2) = "ab"
StringUtils.substring("abc", 2, 0) = ""
StringUtils.substring("abc", 2, 4) = "c"
StringUtils.substring("abc", 4, 6) = ""
StringUtils.substring("abc", 2, 2) = ""
StringUtils.substring("abc", -2, -1) = "b"
StringUtils.substring("abc", -4, 2) = "ab"
str - the String to get the substring from, may be nullstart - the position to start from, negative means
count back from the end of the String by this many charactersend - the position to end at (exclusive), negative means
count back from the end of the String by this many charactersnull if null String inputCopyright © 2019. All rights reserved.