Package arc.util

Class Strings

java.lang.Object
arc.util.Strings

public class Strings extends Object
  • Field Details

    • utf8

      public static final Charset utf8
    • ascii

      public static final Charset ascii
  • Constructor Details

    • Strings

      public Strings()
  • Method Details

    • sha256

      public static byte[] sha256(String str)
      Returns:
      sha256 hash of the given string
    • formatByteCount

      public static String formatByteCount(long v)
    • formatSize

      public static String formatSize(long value, int base, String unit)
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
    • getFileExtension

      public static String getFileExtension(String path)
    • getFileName

      public static String getFileName(String path)
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(String path)
    • matches

      public static boolean matches(String query, String name)
      Returns:
      whether the name matches the query; case-insensitive. Always returns true if query is empty.
    • count

      public static int count(CharSequence s, char c)
    • count

      public static int count(String str, String substring)
    • truncate

      public static String truncate(String s, int length)
    • truncate

      public static String truncate(String s, int length, String ellipsis)
    • getCauses

      public static Seq<Throwable> getCauses(Throwable e)
    • getSimpleMessage

      public static String getSimpleMessage(Throwable e)
    • getSimpleMessages

      public static String getSimpleMessages(Throwable e)
    • getFinalMessage

      public static String getFinalMessage(Throwable e)
    • getFinalCause

      public static Throwable getFinalCause(Throwable e)
    • getStackTrace

      public static String getStackTrace(Throwable e)
    • neatError

      public static String neatError(Throwable e)
      Returns:
      a neat error message of a throwable, with stack trace.
    • neatError

      public static String neatError(Throwable e, boolean stacktrace)
      Returns:
      a neat error message of a throwable, with stack trace.
    • stripColors

      public static String stripColors(CharSequence str)
    • stripGlyphs

      public static String stripGlyphs(CharSequence str)
    • normalize

      public static String normalize(String str)
      Removes colors, glyphs and leading spaces.
    • sanitizeFilename

      public static String sanitizeFilename(String str)
      Replaces non-safe filename characters with '_'. Handles reserved window file names.
    • isSafeFilename

      public static boolean isSafeFilename(String name)
    • encode

      public static String encode(String str)
    • format

      public static String format(String text, Object... args)
    • format

      public static void format(StringBuilder out, String text, Object... args)
    • join

      public static String join(String separator, String... strings)
    • join

      public static String join(String separator, Iterable<String> strings)
    • join

      public static String join(CharSequence delimiter, CharSequence[] elements, int start, int end)
    • levenshtein

      public static int levenshtein(String x, String y)
      Returns the levenshtein distance between two strings.
    • repeat

      public static String repeat(String str, int count)
      Taken from the String.repeat(int) method of JDK 11
    • repeat

      public static String repeat(char c, int count)
    • biasedLevenshtein

      public static float biasedLevenshtein(String x, String y)
      Returns the case-independent biased levenshtein distance between two strings.
    • animated

      public static String animated(float time, int length, float scale, String replacement)
    • kebabToCamel

      public static String kebabToCamel(String s)
    • camelToKebab

      public static String camelToKebab(String s)
    • kebabize

      public static String kebabize(String s)
    • capitalize

      public static String capitalize(String s)
      Converts a snake_case or kebab-case string to Upper Case. For example: "test_string" -> "Test String"
    • insertSpaces

      public static String insertSpaces(String s)
      Adds spaces to a camel/pascal case string.
    • camelize

      public static String camelize(String s)
      Converts a Space Separated string to camelCase. For example: "Camel Case" -> "camelCase"
    • canParseInt

      public static boolean canParseInt(String s)
    • canParsePositiveInt

      public static boolean canParsePositiveInt(String s)
    • parseInt

      public static int parseInt(String s)
      Returns Integer.MIN_VALUE if parsing failed.
    • parseInt

      public static int parseInt(String s, int defaultValue)
    • parseInt

      public static int parseInt(String s, int radix, int defaultValue)
    • parseInt

      public static int parseInt(String s, int radix, int defaultValue, int start, int end)
    • canParseLong

      public static boolean canParseLong(String s)
    • canParsePositiveLong

      public static boolean canParsePositiveLong(String s)
    • parseLong

      public static long parseLong(String s)
    • parseLong

      public static long parseLong(String s, long defaultValue)
    • parseLong

      public static long parseLong(String s, int radix, long defaultValue)
    • parseLong

      public static long parseLong(String s, int radix, int start, int end, long defaultValue)
    • parseDouble

      public static double parseDouble(String value)
    • parseDouble

      public static double parseDouble(String value, double defaultValue)
    • parseDouble

      public static double parseDouble(String value, int start, int end, double defaultValue)
      Faster double parser that doesn't throw exceptions.
    • canParseFloat

      public static boolean canParseFloat(String s)
    • canParsePositiveFloat

      public static boolean canParsePositiveFloat(String s)
    • parseFloat

      public static float parseFloat(String s)
      Returns Float.NEGATIVE_INFINITY if parsing failed.
    • parseFloat

      public static float parseFloat(String s, float defaultValue)
    • parseColor

      public static Color parseColor(String s)
      Returns a new, blank color if parsing failed.
    • parseColor

      public static Color parseColor(String s, Color defaultValue)
    • autoFixed

      public static String autoFixed(float value, int max)
    • fixed

      public static String fixed(float d, int decimalPlaces)
    • fixedBuilder

      public static StringBuilder fixedBuilder(float d, int decimalPlaces)
    • formatMillis

      public static String formatMillis(long val)
    • replace

      public static StringBuilder replace(StringBuilder builder, String find, String replace)
      Replaces all instances of find with replace.
    • replace

      public static StringBuilder replace(StringBuilder builder, char find, String replace)
      Replaces all instances of find with replace.
    • toSentence

      public static <T> String toSentence(Iterable<T> list, Func<T,String> 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> 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

      public static boolean contains(String src, Boolf<Character> predicate)
      String.contains(CharSequence) but with a predicate.
    • matches

      public static boolean matches(String src, Boolf<Character> predicate)
      String.matches(String) but with a predicate.
    • hueToColorTag

      public static String hueToColorTag(int hue)
    • hueToColorTag

      public static void hueToColorTag(StringBuilder builder, int hue)
      Re-implementation of Color.fromHsv(float, float, float) that handles only the hue.
    • rainbowify

      public static String rainbowify(String src, int startHue, int addedHue)
    • isTrue

      public static boolean isTrue(String str)
      Returns:
      whether the specified string mean true
    • isTrue

      public static boolean isTrue(String str, boolean isValue)
      Returns:
      whether the specified string mean true
    • isFalse

      public static boolean isFalse(String str)
      Returns:
      whether the specified string mean false
    • isFalse

      public static boolean isFalse(String str, boolean isValue)
      Returns:
      whether the specified string mean false
    • isVersionAtLeast

      public static boolean isVersionAtLeast(String currentVersion, String newVersion)
    • isVersionAtLeast

      public static boolean isVersionAtLeast(String currentVersion, String newVersion, int maxDepth)
    • compareVersion

      public static int compareVersion(String currentVersion, String newVersion)
    • compareVersion

      public static int compareVersion(String currentVersion, String newVersion, int maxDepth)
      Compare if newVersion is greater or less than currentVersion, e.g. "v146" > "124.1".
      maxDepth defines the number of comparisons of version segments, allowing sub-versions to be ignored. (default is 0)
    • formatDuration

      public static String formatDuration(long millis, boolean narrow)
      Convert millis duration to localized human readable format (e.g. 123456 -> 2 minutes and 3 seconds), using the logger system.
      Parameters:
      millis - milliseconds to convert to duration
      narrow - use short units or not. E.g. "5 months" if false, "5mo" if true