Class Strings

java.lang.Object
app.babylon.text.Strings

public final class Strings extends Object
  • Field Details

  • Constructor Details

    • Strings

      public Strings()
  • Method Details

    • toCamelUpperPreserve

      public static CharSequence toCamelUpperPreserve(CharSequence x)
    • leftPad

      public static CharSequence leftPad(CharSequence s, int size, char padChar)
    • rightPad

      public static CharSequence rightPad(CharSequence s, int size, char padChar)
    • isAlpha

      public static boolean isAlpha(char c)
    • isAlphaNumeric

      public static boolean isAlphaNumeric(char c)
    • equals

      public static boolean equals(CharSequence s, int start, int length, CharSequence expected)
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(CharSequence s, int start, int length, CharSequence expected)
    • isEmpty

      public static boolean isEmpty(CharSequence s)
    • isEmpty

      public static boolean isEmpty(CharSequence s, int start, int length)
    • isStripxEmpty

      public static boolean isStripxEmpty(CharSequence s)
      Returns true when the supplied sequence is empty after applying stripx(CharSequence) rules.
    • isStripxEmpty

      public static boolean isStripxEmpty(CharSequence s, int start, int length)
      Returns true when the supplied slice is empty after applying the same edge stripping rules as stripx(CharSequence, int, int). Those rules remove normal Unicode whitespace and the additional ingestion artifacts documented on stripx.
    • indexOf

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

      public static int indexOf(CharSequence s, int start, int length, char c)
    • indexOfAny

      public static int indexOfAny(CharSequence s, char c, char... additional)
    • indexOfAny

      public static int indexOfAny(CharSequence s, int start, int length, char c, char... additional)
    • lastIndexOf

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

      public static int lastIndexOf(CharSequence s, int start, int length, char c)
    • lastIndexOfAny

      public static int lastIndexOfAny(CharSequence s, char c, char... additional)
    • lastIndexOfAny

      public static int lastIndexOfAny(CharSequence s, int start, int length, char c, char... additional)
    • trace

      public static BitSet trace(CharSequence s, char splitter)
      Finds every occurrence of splitter and returns the source indexes as marked bits.

      This is intentionally a raw delimiter trace: it does not strip text, remove empty fields, or otherwise apply Strings.Splitter policy. Use it when code needs delimiter positions directly, for example to size arrays or plan low-level parsing.

    • trace

      public static BitSet trace(CharSequence s, int start, int length, char splitter)
      Finds every occurrence of splitter in a slice and returns their indexes as marked bits.

      The returned BitSet is indexed against the original source sequence, not against the supplied slice. For example, a splitter at start sets bit start.

    • traceAny

      public static BitSet traceAny(CharSequence s, char splitter, char... additionalSplitters)
      Finds every occurrence of any supplied splitter and returns the source indexes as marked bits.

      This is the multi-delimiter form of trace(CharSequence, char). The single-character trace overload remains the fast path for the common case and avoids varargs array creation.

    • traceAny

      public static BitSet traceAny(CharSequence s, int start, int length, char splitter, char... additionalSplitters)
      Finds every occurrence of any supplied splitter in a slice and returns their indexes as marked bits.

      The returned BitSet is indexed against the original source sequence, not against the supplied slice.

    • split

      public static String[] split(CharSequence s, char splitter)
      Splits using splitter, with the same defaults as splitter(): withStripping(true) and withRemoveEmpty(true).

      This is convenient for one-off calls. For repeated use with the same delimiter, prefer a reusable immutable Strings.Splitter:

      
       private static final Strings.Splitter PIPE = Strings.splitter().withSplitter('|');
       
    • split

      public static String[] split(CharSequence s, int start, int length, char splitter)
      Splits a slice using splitter, with the same defaults as splitter(): withStripping(true) and withRemoveEmpty(true).

      This is convenient for one-off calls. For repeated use with the same delimiter, prefer a reusable immutable Strings.Splitter.

    • split

      public static String[] split(CharSequence s)
      Splits comma-separated text using the default Strings.Splitter settings.
    • compact

      public static String[] compact(String[] values)
      Returns a copy of values with null entries removed while preserving order.

      If values is already compact, the same array instance is returned. If values is null, an empty array is returned.

    • compact

      public static String[] compact(String[] values, Predicate<String> remove)
      Returns a copy of values with entries matching remove omitted while preserving order.

      If no entries match, the same array instance is returned. If values is null, an empty array is returned. If remove is null, no entries are removed.

    • splitter

      public static Strings.Splitter splitter()
      Creates a reusable splitter configuration.

      Defaults are comma delimiter, withStripping(true), and withRemoveEmpty(true). Stripping uses the same boundary rules as stripx(CharSequence), so it removes Unicode whitespace and common ingestion artifacts such as BOMs, non-breaking spaces, zero-width characters, and replacement characters.

      Because splitter configurations are immutable, configured instances can be stored as constants for repeated use:

      
       private static final Strings.Splitter PIPE = Strings.splitter().withSplitter('|');
       
    • isWholeNumber

      public static boolean isWholeNumber(CharSequence s)
    • isWholeNumber

      public static boolean isWholeNumber(CharSequence s, int start, int length)
    • isInt

      public static boolean isInt(CharSequence s)
    • isInt

      public static boolean isInt(CharSequence s, int start, int length)
    • isLong

      public static boolean isLong(CharSequence s)
    • isLong

      public static boolean isLong(CharSequence s, int start, int length)
    • isDouble

      public static boolean isDouble(CharSequence s)
    • isDouble

      public static boolean isDouble(CharSequence s, int start, int length)
    • strip

      public static CharSequence strip(CharSequence s)
      Unicode-aware edge stripping equivalent to String.strip() for CharSequence.
    • stripStart

      public static int stripStart(CharSequence s, int start, int length)
      Returns the inclusive start index of the trimmed slice after Unicode whitespace stripping.

      This is intended for slice-oriented parsing code that wants trimmed bounds without first creating a CharSequence.subSequence(int, int) view. Paired with stripEnd(CharSequence, int, int), callers can decide whether a slice changed and only materialize a subsequence if the downstream parser requires one.

      Typical usage:

      
       int strippedOffset = Strings.stripStart(s, offset, length);
       int strippedEnd = Strings.stripEnd(s, offset, length);
       if (strippedOffset < strippedEnd)
       {
           CharSequence candidate = s.subSequence(strippedOffset, strippedEnd);
       }
       

      This is generally preferable to a hypothetical strip(CharSequence, int, int) helper for low-level parsing, because it lets the caller keep control of whether a new view object is created.

    • stripEnd

      public static int stripEnd(CharSequence s, int start, int length)
      Returns the exclusive end index of the trimmed slice after Unicode whitespace stripping.

      The returned value follows the normal Java start/end convention used by CharSequence.subSequence(int, int) and String.substring(int, int):

      - start is inclusive

      - end is exclusive

      See Also:
    • stripx

      public static CharSequence stripx(CharSequence s)
      Unicode-aware edge stripping for external text. This behaves like String.strip() for normal whitespace, and also strips common ingestion artifacts that can appear at text boundaries:
      • non-breaking space (U+00A0), often copied from HTML, PDFs, and spreadsheets
      • zero-width space/non-joiner/joiner (U+200B, U+200C, U+200D), often introduced by copy/paste, web text, PDFs, or rich text editors
      • byte order mark (U+FEFF), often found at file or field boundaries
      • replacement character (U+FFFD), commonly produced by encoding damage
    • stripx

      public static CharSequence stripx(CharSequence s, int start, int length)
    • clean

      public static String clean(CharSequence s, char... removeCharacters)
      Strips external text with stripx(CharSequence), normalises any remaining whitespace run to a single space, and removes selected characters.

      Passing ' ' as one of the removable characters removes all normalised whitespace, including tabs and other whitespace characters. This is useful for cleaning human-readable tokens such as half-up, half_up, and half up to the same key before case conversion.

      Parameters:
      s - source text
      removeCharacters - characters to remove after whitespace normalisation
      Returns:
      normalised text or null
    • removeDiacritics

      public static CharSequence removeDiacritics(CharSequence s)
    • removeDiacritics

      public static CharSequence removeDiacritics(CharSequence s, int start, int length)