Package arc.util
Class Strings
java.lang.Object
arc.util.Strings
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic StringautoFixed(float value, int max) static floatbiasedLevenshtein(String x, String y) Returns the case-independent biased levenshtein distance between two strings.static StringbytesToHex(byte[] bytes) static StringConverts a Space Separated string to camelCase.static Stringstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic Stringcapitalize(String s) Converts a snake_case or kebab-case string to Upper Case.static intcompareVersion(String currentVersion, String newVersion) static intcompareVersion(String currentVersion, String newVersion, int maxDepth) Compare ifnewVersionis greater or less thancurrentVersion, e.g.static booleanString.contains(CharSequence)but with a predicate.static intcount(CharSequence s, char c) static intstatic Stringstatic Stringfixed(float d, int decimalPlaces) static StringBuilderfixedBuilder(float d, int decimalPlaces) static voidformat(StringBuilder out, String text, Object... args) static Stringstatic StringformatByteCount(long v) static StringformatDuration(long millis, boolean narrow) Convertmillisduration to localized human readable format (e.g.static StringformatMillis(long val) static StringformatSize(long value, int base, String unit) static StringgetFileExtension(String path) static StringgetFileName(String path) static Stringstatic Throwablestatic Stringstatic Stringstatic Stringstatic Stringstatic StringhueToColorTag(int hue) static voidhueToColorTag(StringBuilder builder, int hue) Re-implementation ofColor.fromHsv(float, float, float)that handles only the hue.static StringAdds spaces to a camel/pascal case string.static booleanstatic booleanstatic booleanisSafeFilename(String name) static booleanstatic booleanstatic booleanisVersionAtLeast(String currentVersion, String newVersion) static booleanisVersionAtLeast(String currentVersion, String newVersion, int maxDepth) static Stringjoin(CharSequence delimiter, CharSequence[] elements, int start, int end) static Stringstatic Stringstatic Stringstatic Stringstatic intlevenshtein(String x, String y) Returns the levenshtein distance between two strings.static booleanString.matches(String)but with a predicate.static booleanstatic Stringstatic Stringstatic StringRemoves colors, glyphs and leading spaces.static ColorparseColor(String s) Returns a new, blank color if parsing failed.static ColorparseColor(String s, Color defaultValue) static doubleparseDouble(String value) static doubleparseDouble(String value, double defaultValue) static doubleparseDouble(String value, int start, int end, double defaultValue) Faster double parser that doesn't throw exceptions.static floatparseFloat(String s) Returns Float.NEGATIVE_INFINITY if parsing failed.static floatparseFloat(String s, float defaultValue) static intReturns Integer.MIN_VALUE if parsing failed.static intstatic intstatic intstatic longstatic longstatic longstatic longstatic Stringrainbowify(String src, int startHue, int addedHue) static Stringrepeat(char c, int count) static StringTaken from theString.repeat(int)method of JDK 11static StringBuilderreplace(StringBuilder builder, char find, String replace) Replaces all instances offindwithreplace.static StringBuilderreplace(StringBuilder builder, String find, String replace) Replaces all instances offindwithreplace.static StringsanitizeFilename(String str) Replaces non-safe filename characters with '_'.static byte[]static StringstripColors(CharSequence str) static StringstripGlyphs(CharSequence str) static <T> StringtoSentence(Iterable<T> list, Func<T, String> stringifier) Converts a list to a human readable sentence.static <T> StringConverts a list to a human readable sentence.static <T> voidtoSentence(StringBuilder builder, Iterable<T> list, Cons2<StringBuilder, T> stringifier) Converts a list to a human readable sentence.static <T> voidtoSentence(StringBuilder builder, Iterable<T> list, Cons2<StringBuilder, T> stringifier, String or, String and) Converts a list to a human readable sentence.static Stringstatic String
-
Field Details
-
utf8
-
ascii
-
-
Constructor Details
-
Strings
public Strings()
-
-
Method Details
-
sha256
- Returns:
- sha256 hash of the given string
-
formatByteCount
-
formatSize
-
bytesToHex
-
getFileExtension
-
getFileName
-
getFileNameWithoutExtension
-
matches
- Returns:
- whether the name matches the query; case-insensitive. Always returns true if query is empty.
-
count
-
count
-
truncate
-
truncate
-
getCauses
-
getSimpleMessage
-
getSimpleMessages
-
getFinalMessage
-
getFinalCause
-
getStackTrace
-
neatError
- Returns:
- a neat error message of a throwable, with stack trace.
-
neatError
- Returns:
- a neat error message of a throwable, with stack trace.
-
stripColors
-
stripGlyphs
-
normalize
Removes colors, glyphs and leading spaces. -
sanitizeFilename
Replaces non-safe filename characters with '_'. Handles reserved window file names. -
isSafeFilename
-
encode
-
format
-
format
-
join
-
join
-
join
-
levenshtein
Returns the levenshtein distance between two strings. -
repeat
Taken from theString.repeat(int)method of JDK 11 -
repeat
-
biasedLevenshtein
Returns the case-independent biased levenshtein distance between two strings. -
animated
-
kebabToCamel
-
camelToKebab
-
kebabize
-
capitalize
Converts a snake_case or kebab-case string to Upper Case. For example: "test_string" -> "Test String" -
insertSpaces
Adds spaces to a camel/pascal case string. -
camelize
Converts a Space Separated string to camelCase. For example: "Camel Case" -> "camelCase" -
canParseInt
-
canParsePositiveInt
-
parseInt
Returns Integer.MIN_VALUE if parsing failed. -
parseInt
-
parseInt
-
parseInt
-
canParseLong
-
canParsePositiveLong
-
parseLong
-
parseLong
-
parseLong
-
parseLong
-
parseDouble
-
parseDouble
-
parseDouble
Faster double parser that doesn't throw exceptions. -
canParseFloat
-
canParsePositiveFloat
-
parseFloat
Returns Float.NEGATIVE_INFINITY if parsing failed. -
parseFloat
-
parseColor
Returns a new, blank color if parsing failed. -
parseColor
-
autoFixed
-
fixed
-
fixedBuilder
-
formatMillis
-
replace
Replaces all instances offindwithreplace. -
replace
Replaces all instances offindwithreplace. -
toSentence
Converts a list to a human readable sentence. E.g. [1, 2, 3, 4, 5] -> "1, 2, 3, 4 and 5" -
toSentence
public static <T> String toSentence(Iterable<T> list, Func<T, String> stringifier, String or, String and) Converts a list to a human readable sentence. E.g. [1, 2, 3, 4, 5] -> "1, 2, 3, 4 and 5" -
toSentence
public static <T> void toSentence(StringBuilder builder, Iterable<T> list, Cons2<StringBuilder, T> stringifier) Converts a list to a human readable sentence. E.g. [1, 2, 3, 4, 5] -> "1, 2, 3, 4 and 5" -
toSentence
public static <T> void toSentence(StringBuilder builder, Iterable<T> list, Cons2<StringBuilder, T> stringifier, String or, String and) Converts a list to a human readable sentence. E.g. [1, 2, 3, 4, 5] -> "1, 2, 3, 4 and 5" -
contains
String.contains(CharSequence)but with a predicate. -
matches
String.matches(String)but with a predicate. -
hueToColorTag
-
hueToColorTag
Re-implementation ofColor.fromHsv(float, float, float)that handles only the hue. -
rainbowify
-
isTrue
- Returns:
- whether the specified string mean true
-
isTrue
- Returns:
- whether the specified string mean true
-
isFalse
- Returns:
- whether the specified string mean false
-
isFalse
- Returns:
- whether the specified string mean false
-
isVersionAtLeast
-
isVersionAtLeast
-
compareVersion
-
compareVersion
Compare ifnewVersionis greater or less thancurrentVersion, e.g. "v146" > "124.1".
maxDepthdefines the number of comparisons of version segments, allowing sub-versions to be ignored. (default is 0) -
formatDuration
Convertmillisduration to localized human readable format (e.g. 123456 -> 2 minutes and 3 seconds), using the logger system.- Parameters:
millis- milliseconds to convert to durationnarrow- use short units or not. E.g. "5 months" iffalse, "5mo" iftrue
-