Class TextUtils
java.lang.Object
gaiasky.util.TextUtils
Utilities to manipulate strings and text.
-
Constructor Summary
Constructors -
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 StringarrayToStr(String[] arr) static StringarrayToStr(String[] arr, String pre, String post, String sep) static StringbreakCharacters(CharSequence in, int breakChars) Breaks the string with new line ('\n') characters so that the lines have approximatelybreakCharscharacters.static StringbreakCharacters(String in, int breakChars) Breaks the string with new line ('\n') characters so that the lines have approximatelybreakCharscharacters.static StringbreakCharacters(String in, int breakChars, boolean forceBreak) Breaks the string with new line ('\n') characters so that the lines have approximatelybreakCharscharacters.static StringbreakSpaces(String in, int breakSpaces) static Stringcapitalise(String line) Returns the given string with the first letter capitalisedstatic Stringstatic Stringstatic StringclassSimpleName(String className) static String[]Concatenates the base with each of the strings in suffixesstatic Stringconcatenate(String split, String... strings) Concatenates the strings using the given splitstatic Stringconcatenate(String split, List<String> strings) Concatenates the strings using the given splitstatic booleanstatic booleanstatic booleanstatic booleancontainsOrMatches(String[][] list, String key, boolean ignoreCase) static booleancontainsOrMatches(String[] list, String key, boolean ignoreCase) static longcountLines(String str) static StringensureStartsWith(String base, String start) static StringEscape a give String to make it safe to be printed or stored.static Stringstatic StringgetFormattedTimeWarp(double warp) static inthashFast(char[] val) static intstatic inthashFNV1(char[] data, long seed) static intstatic inthashMurmur(char[] data, int seed) static inthashMurmur(String str) static StringRemoves the tags and unescapes the given HTML code into a plain string.static booleanisValidURL(String url) Check if a string is a valid URL.static StringPads the given string with the given character to be the given length.static StringpropertyToMethodName(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 StringsanitizeFilename(String input) Sanitizes the given input string so that it can be used as a file name.static StringsecondsToTimeUnit(double seconds) static Stringstatic Stringstatic booleanstartsWith(String[] list, String prefix) static StringstripAnsiCodes(String input) Removes ANSI color codes from the input string.static Stringstatic Stringstatic StringtrueCapitalise(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
-
stripAnsiCodes
-
escape
-
surroundBrackets
-
surround
-
breakCharacters
Breaks the string with new line ('\n') characters so that the lines have approximatelybreakCharscharacters.- Parameters:
in- The character sequence.breakChars- The number of characters per line.- Returns:
- The string, broken into lines.
-
breakCharacters
-
breakCharacters
Breaks the string with new line ('\n') characters so that the lines have approximatelybreakCharscharacters.- 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
-
capitalise
-
trueCapitalise
-
concatenate
-
concatenate
-
arrayToStr
-
arrayToStr
-
setToStr
-
setToStr
-
getFormattedTimeWarp
-
getFormattedTimeWarp
-
secondsToTimeUnit
-
concatAll
-
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
-
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.
-
isValidURL
Check if a string is a valid URL.- Parameters:
url- The string to check.- Returns:
- True if the string is a valid URL.
-
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
-
sanitizeFilename
-