Package gaiasky.util
Class TextUtils
java.lang.Object
gaiasky.util.TextUtils
Utilities to manipulate strings and text.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
addToBeginningOfArray
(T[] elements, T element) Returns a new array with the given element inserted at the beginning (index 0).static String
arrayToStr
(String[] arr) static String
arrayToStr
(String[] arr, String pre, String post, String sep) static String
breakCharacters
(CharSequence in, int breakChars) Breaks the string with new line ('\n') characters so that the lines have approximatelybreakChars
characters.static String
breakCharacters
(String in, int breakChars) Breaks the string with new line ('\n') characters so that the lines have approximatelybreakChars
characters.static String
breakCharacters
(String in, int breakChars, boolean forceBreak) Breaks the string with new line ('\n') characters so that the lines have approximatelybreakChars
characters.static String
breakSpaces
(String in, int breakSpaces) static String
capitalise
(String line) Returns the given string with the first letter capitalisedstatic String
static String
static String
classSimpleName
(String className) static String[]
Concatenates the base with each of the strings in suffixesstatic String
concatenate
(String split, String... strings) Concatenates the strings using the given splitstatic String
concatenate
(String split, List<String> strings) Concatenates the strings using the given splitstatic boolean
static boolean
static boolean
static boolean
containsOrMatches
(String[][] list, String key, boolean ignoreCase) static boolean
containsOrMatches
(String[] list, String key, boolean ignoreCase) static long
countLines
(String str) static String
ensureStartsWith
(String base, String start) static String
Escape a give String to make it safe to be printed or stored.static String
static String
getFormattedTimeWarp
(double warp) static int
hashFast
(char[] val) static int
static int
hashFNV1
(char[] data, long seed) static int
static int
hashMurmur
(char[] data, int seed) static int
hashMurmur
(String str) static String
Removes the tags and unescapes the given HTML code into a plain string.static String
Pads the given string with the given character to be the given length.static String
propertyToMethodName
(String property) Converts from property displayName to method displayName by removing the separator dots and capitalising each chunk.readFirstLine
(Path file) Reads the first line of a file.static String
secondsToTimeUnit
(double seconds) static String
static String
static boolean
startsWith
(String[] list, String prefix) static String
static String
static String
trueCapitalise
(String line) Returns the given string with the first letter capitalised and all the others in lower casestatic String
-
Constructor Details
-
TextUtils
public TextUtils()
-
-
Method Details
-
escape
Escape a give String to make it safe to be printed or stored.- Parameters:
s
- The input String.- Returns:
- The output String.
-
surroundBrackets
-
surround
-
breakCharacters
Breaks the string with new line ('\n') characters so that the lines have approximatelybreakChars
characters.- Parameters:
in
- The character sequence.breakChars
- The number of characters per line.- Returns:
- The string, broken into lines.
-
breakCharacters
Breaks the string with new line ('\n') characters so that the lines have approximatelybreakChars
characters.- Parameters:
in
- The string.breakChars
- The number of characters per line.- Returns:
- The string, broken into lines.
-
breakCharacters
Breaks the string with new line ('\n') characters so that the lines have approximatelybreakChars
characters.- Parameters:
in
- The string.breakChars
- The number of characters per line.forceBreak
- Break the string even when there are no separator characters.- Returns:
- The string, broken into lines.
-
countLines
-
breakSpaces
-
capString
-
capString
-
propertyToMethodName
Converts from property displayName to method displayName by removing the separator dots and capitalising each chunk. Example: model.texture.bump -> ModelTextureBump- Parameters:
property
- The property displayName- Returns:
- The method name
-
capitalise
Returns the given string with the first letter capitalised- Parameters:
line
- The input string- Returns:
- The string with its first letter capitalised
-
trueCapitalise
Returns the given string with the first letter capitalised and all the others in lower case- Parameters:
line
- The input string- Returns:
- The string with its first letter capitalised and the others in lower case
-
concatenate
Concatenates the strings using the given split- Parameters:
split
- The splitstrings
- The strings- Returns:
- The concatenation
-
concatenate
Concatenates the strings using the given split- Parameters:
split
- The splitstrings
- The strings- Returns:
- The concatenation
-
arrayToStr
-
arrayToStr
-
setToStr
-
setToStr
-
getFormattedTimeWarp
-
getFormattedTimeWarp
-
secondsToTimeUnit
-
concatAll
Concatenates the base with each of the strings in suffixes- Parameters:
base
- The base stringsuffixes
- All the suffixes- Returns:
- The result
-
addToBeginningOfArray
public static <T> T[] addToBeginningOfArray(T[] elements, T element) Returns a new array with the given element inserted at the beginning (index 0).- Type Parameters:
T
- The type of objects contained in the arrays.- Parameters:
elements
- The array.element
- The new element to insert.- Returns:
- The new array.
-
contains
-
contains
-
startsWith
-
ensureStartsWith
-
contains
-
containsOrMatches
-
containsOrMatches
-
html2text
Removes the tags and unescapes the given HTML code into a plain string.- Parameters:
html
- The HTML code.- Returns:
- Unescaped plain text without HTML tags or codes.
-
unescape
-
classSimpleName
-
padString
Pads the given string with the given character to be the given length.- Parameters:
str
- The string to pad.length
- The target length.padChar
- The padding character to use.- Returns:
- The padded string, or the original string if its length was greater than the given target length.
-
hashFast
-
hashFast
public static int hashFast(char[] val) -
hashFNV1
-
hashFNV1
public static int hashFNV1(char[] data, long seed) -
hashMurmur
-
hashMurmur
public static int hashMurmur(char[] data, int seed) -
readFirstLine
Reads the first line of a file.- Parameters:
file
- The path pointing to the file to read.- Returns:
- The first line as a string.
-