Class CollationMatching

java.lang.Object
dev.frostlake.functions.CollationMatching

public final class CollationMatching extends Object
Text matching under a collation, for the functions that compare rather than merely carry one: CONTAINS, STARTSWITH, ENDSWITH, POSITION, CHARINDEX, REPLACE, SPLIT and SPLIT_PART all look for a substring the collation calls equal, not one that matches byte for byte.

A collation can call texts of DIFFERENT lengths equal (an accent-insensitive one folds a combining mark away), so a match is looked for by comparing candidate substrings rather than by indexing — the shortest substring at the earliest position wins, which is what an ordinary indexOf means.

  • Method Details

    • equalUnder

      public static boolean equalUnder(CollationSpec rules, Object left, Object right)
      Whether two values are equal under a collation, or by ordinary equality when there is none or either side is not text.
      Parameters:
      rules - the collation, or null
      left - one value
      right - the other
      Returns:
      whether the collation calls them equal
    • findUnder

      public static int[] findUnder(CollationSpec rules, String haystack, String needle, int from)
      The first substring of haystack at or after from that the collation calls equal to needle.
      Parameters:
      rules - the collation
      haystack - the text searched
      needle - the text looked for
      from - the first index that may start a match
      Returns:
      {start, end} of the match, or null when there is none
    • containsUnder

      public static boolean containsUnder(CollationSpec rules, String haystack, String needle)
      Whether haystack holds a substring the collation calls equal to needle.
      Parameters:
      rules - the collation
      haystack - the text searched
      needle - the text looked for
      Returns:
      whether it occurs
    • startsWithUnder

      public static boolean startsWithUnder(CollationSpec rules, String haystack, String prefix)
      Whether some prefix of haystack is equal to prefix under the collation.
      Parameters:
      rules - the collation
      haystack - the text searched
      prefix - the prefix looked for
      Returns:
      whether it starts with it
    • endsWithUnder

      public static boolean endsWithUnder(CollationSpec rules, String haystack, String suffix)
      Whether some suffix of haystack is equal to suffix under the collation.
      Parameters:
      rules - the collation
      haystack - the text searched
      suffix - the suffix looked for
      Returns:
      whether it ends with it
    • replaceUnder

      public static String replaceUnder(CollationSpec rules, String haystack, String needle, String replacement)
      Every occurrence of needle in haystack replaced, matching under the collation.
      Parameters:
      rules - the collation
      haystack - the text
      needle - the text replaced
      replacement - what replaces it
      Returns:
      the result
    • splitUnder

      public static List<String> splitUnder(CollationSpec rules, String haystack, String separator)
      haystack split on every occurrence of separator, matching under the collation.
      Parameters:
      rules - the collation
      haystack - the text split
      separator - the separator
      Returns:
      the parts, in order