public final class UtilText
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_ESCAPE_CHARACTERS
Default escape characters : \ (see
StringExtractor ) |
static java.lang.String |
DEFAULT_SEPARATORS
Default escape separators : [space], [Line return \n], [tabulation \t], [carriage return \r] and [\f] (see
StringExtractor ) |
static java.lang.String |
DEFAULT_STRING_LIMITERS
Default string limiters : " and ' (see
StringExtractor ) |
static java.nio.charset.Charset |
UTF8
UTF-8 char set
|
Modifier | Constructor and Description |
---|---|
private |
UtilText()
To avoid instance
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addAntiSlash(java.lang.String string,
boolean simpleQuote)
Add \ before each " we can chose do treat the ' as normal character or add \ before it also
|
private static void |
appendObject(java.lang.StringBuffer stringBuffer,
java.lang.Object object)
Append an object to string buffer
|
static java.lang.String[] |
capture(java.lang.String pattern,
java.lang.String text) |
static java.lang.String |
colorText(int color)
Color to text representation
|
static int |
computeDistance(java.lang.String text1,
java.lang.String text2,
boolean caseSensitive,
java.lang.String wordDelimiters)
Compute "distance" between two texts.
|
static java.lang.String |
computeNotInsideName(java.lang.String base,
java.util.Collection<java.lang.String> names)
Compute a name not inside a set of name
|
static java.lang.String |
computeOtherName(java.lang.String name)
Compute an other name for a String name.
|
static java.lang.String |
concatenate(java.lang.Object... objects)
Concatenate several object to make a string representation
|
static java.lang.String[] |
cutSringInPart(java.lang.String string,
char separator)
Cut String in several parts
|
static int |
indexOf(java.lang.CharSequence charSequence,
char... characters)
Compute the first index in the char sequence of one of given characters
|
static int |
indexOf(java.lang.CharSequence charSequence,
int offset,
char... characters)
Compute the first index >= at the given offset in the char sequence of one of given characters
|
static int |
indexOf(java.lang.String[] tableau,
java.lang.String chaine)
Index of a string in string array
|
static int |
indexOfIgnoreString(java.lang.String string,
char character)
Compute the index of a character in a string on ignoring characters between " or ' an in ignore characters with \ just
before them
|
static int |
indexOfIgnoreStrings(java.lang.String text,
java.lang.String search,
int startIndex,
java.lang.String stringLimiters)
Give index of a string inside an other one on ignoring characters bettwen string delimiters.
|
static java.lang.String |
interpretAntiSlash(java.lang.String string)
Replace character that follow an \ by it's symbol : \n by carriage return, \t by tabulation and \<other> by
<other>
|
static int |
lastIndexOf(java.lang.CharSequence charSequence,
char... characters)
Compute the last index in the char sequence of one of given characters
|
static int |
lastIndexOf(java.lang.CharSequence charSequence,
int offset,
char... characters)
Compute the last index <= of given offset in the char sequence of one of given characters
|
static int |
parseHexaString(java.lang.String string)
Parse an hexadecimal string to integer
|
static int |
parseInteger(java.lang.String string)
Parse a string to integer
|
static java.lang.String |
readUTF8(byte[] array,
int offset,
int length)
Read a UTF-8 string from a part of byte array
|
static java.lang.String |
removeWhiteCharacters(java.lang.String string)
Remove all white characters of a string
|
static java.lang.String |
repeat(char character,
int time)
Create a String full of same character
|
static java.lang.String |
repeat(java.lang.String string,
int time)
Create string that repeat always the same string
|
static java.lang.String |
replaceHole(java.lang.String originalString,
java.lang.String... replacement)
Replace "hole" by a value.
|
static java.lang.String |
replaceSeveral(java.lang.String originalString,
int... values)
Replace holes like {0} or {2_s} or {1_###eet} or ...
|
static java.lang.String |
toHexadecimal(byte[] array)
Convert a byte array to hexadecimal representation
|
static byte[] |
toUTF8(java.lang.String string)
Convert string to UTF-8 array
|
static java.lang.String |
upperCaseWithoutAccent(java.lang.String text)
Compute the upper case version of of string, and remove all accent.
|
public static final java.lang.String DEFAULT_ESCAPE_CHARACTERS
StringExtractor
)public static final java.lang.String DEFAULT_SEPARATORS
StringExtractor
)public static final java.lang.String DEFAULT_STRING_LIMITERS
StringExtractor
)public static final java.nio.charset.Charset UTF8
private static void appendObject(java.lang.StringBuffer stringBuffer, java.lang.Object object)
stringBuffer
- Where appendobject
- Object to appendpublic static java.lang.String addAntiSlash(java.lang.String string, boolean simpleQuote)
string
- String to replacesimpleQuote
- Indicates if we also add \ before 'public static java.lang.String[] capture(java.lang.String pattern, java.lang.String text)
public static java.lang.String colorText(int color)
color
- Color to convertpublic static int computeDistance(java.lang.String text1, java.lang.String text2, boolean caseSensitive, java.lang.String wordDelimiters)
text1
- First texttext2
- Second textcaseSensitive
- Indicates if for word comparison case is important or notwordDelimiters
- List of delimiters of words (Each characters of this string are see as separator and only them)public static java.lang.String computeNotInsideName(java.lang.String base, java.util.Collection<java.lang.String> names)
base
- Base namenames
- Set of namespublic static java.lang.String computeOtherName(java.lang.String name)
name
- Name basepublic static java.lang.String concatenate(java.lang.Object... objects)
objects
- Objects to concatenatepublic static java.lang.String[] cutSringInPart(java.lang.String string, char separator)
string
- String to cutseparator
- Separator where cutpublic static int indexOf(java.lang.CharSequence charSequence, char... characters)
charSequence
- Char sequence where search one charactercharacters
- Characters searchpublic static int indexOf(java.lang.CharSequence charSequence, int offset, char... characters)
charSequence
- Char sequence where search one characteroffset
- The offset where start the searchcharacters
- Characters searchpublic static int indexOf(java.lang.String[] tableau, java.lang.String chaine)
tableau
- Array where searchchaine
- String searchpublic static int indexOfIgnoreString(java.lang.String string, char character)
string
- String where searchcharacter
- Looking for characterpublic static int indexOfIgnoreStrings(java.lang.String text, java.lang.String search, int startIndex, java.lang.String stringLimiters)
text
- Text where searchsearch
- Searched textstartIndex
- Index where start the searchstringLimiters
- String limiters to usepublic static java.lang.String interpretAntiSlash(java.lang.String string)
string
- String to replacepublic static int lastIndexOf(java.lang.CharSequence charSequence, char... characters)
charSequence
- Char sequence where search one charactercharacters
- Characters searchpublic static int lastIndexOf(java.lang.CharSequence charSequence, int offset, char... characters)
charSequence
- Char sequence where search one characteroffset
- Offset maximum for searchcharacters
- Characters searchpublic static int parseHexaString(java.lang.String string)
string
- String to parsepublic static int parseInteger(java.lang.String string)
string
- String to parsepublic static java.lang.String readUTF8(byte[] array, int offset, int length)
array
- Array to readoffset
- Start read index in arraylength
- Number of bytes to readpublic static java.lang.String removeWhiteCharacters(java.lang.String string)
string
- String to "clean"public static java.lang.String repeat(char character, int time)
character
- Character to repeattime
- Number of characterpublic static java.lang.String repeat(java.lang.String string, int time)
string
- String to repeattime
- Number of repeatpublic static java.lang.String replaceHole(java.lang.String originalString, java.lang.String... replacement)
I want exchange this {0} with this {1} | hammer, apple | I want exchange this hammer with this apple |
I saw a {0} run after a {1}. I wonder if the {1} can escape from the {0} | dog, cat | I saw a dog run after a cat. I wonder if the cat can escape from the dog |
originalString
- String with "holes"replacement
- List of replacement for "holes". First replace hole {0}, second {1}, third {2} ,....public static java.lang.String replaceSeveral(java.lang.String originalString, int... values)
There {0} cat{0_s} and {1} foot{1_###eet} | 1, 1 | There 1 cat and 1 foot |
There {0} cat{0_s} and {1} foot{1_###eet} | 5,1 | There 5 cats and 1 foot |
There {0} cat{0_s} and {1} foot{1_###eet} | 1,3 | There 1 cat and 3 feet |
There {0} cat{0_s} and {1} foot{1_###eet} | 5, 3 | There 5 cats and 3 feet |
originalString
- String with "holes"values
- List of values for "holes". First evaluate hole {0}, second {1}, third {2} ,....public static java.lang.String toHexadecimal(byte[] array)
array
- Array to convertpublic static byte[] toUTF8(java.lang.String string)
string
- String to convertpublic static java.lang.String upperCaseWithoutAccent(java.lang.String text)
text
- Text to upper case