Package arc.util

Class Strings

java.lang.Object
arc.util.Strings

public class Strings extends Object
  • Field Details

    • utf8

      public static final Charset utf8
  • Constructor Details

    • Strings

      public Strings()
  • Method Details

    • 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)
    • 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.
    • 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
    • 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)
    • 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.
    • 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)
      Returns:
      whether newVersion is greater than currentVersion. (e.g. "v146" > "124.1")