Package dev.frostlake.functions
Class CollationMatching
java.lang.Object
dev.frostlake.functions.CollationMatching
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 Summary
Modifier and TypeMethodDescriptionstatic booleancontainsUnder(CollationSpec rules, String haystack, String needle) Whetherhaystackholds a substring the collation calls equal toneedle.static booleanendsWithUnder(CollationSpec rules, String haystack, String suffix) Whether some suffix ofhaystackis equal tosuffixunder the collation.static booleanequalUnder(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.static int[]findUnder(CollationSpec rules, String haystack, String needle, int from) The first substring ofhaystackat or afterfromthat the collation calls equal toneedle.static StringreplaceUnder(CollationSpec rules, String haystack, String needle, String replacement) Every occurrence ofneedleinhaystackreplaced, matching under the collation.splitUnder(CollationSpec rules, String haystack, String separator) haystacksplit on every occurrence ofseparator, matching under the collation.static booleanstartsWithUnder(CollationSpec rules, String haystack, String prefix) Whether some prefix ofhaystackis equal toprefixunder the collation.
-
Method Details
-
equalUnder
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 nullleft- one valueright- the other- Returns:
- whether the collation calls them equal
-
findUnder
The first substring ofhaystackat or afterfromthat the collation calls equal toneedle.- Parameters:
rules- the collationhaystack- the text searchedneedle- the text looked forfrom- the first index that may start a match- Returns:
{start, end}of the match, or null when there is none
-
containsUnder
Whetherhaystackholds a substring the collation calls equal toneedle.- Parameters:
rules- the collationhaystack- the text searchedneedle- the text looked for- Returns:
- whether it occurs
-
startsWithUnder
Whether some prefix ofhaystackis equal toprefixunder the collation.- Parameters:
rules- the collationhaystack- the text searchedprefix- the prefix looked for- Returns:
- whether it starts with it
-
endsWithUnder
Whether some suffix ofhaystackis equal tosuffixunder the collation.- Parameters:
rules- the collationhaystack- the text searchedsuffix- 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 ofneedleinhaystackreplaced, matching under the collation.- Parameters:
rules- the collationhaystack- the textneedle- the text replacedreplacement- what replaces it- Returns:
- the result
-
splitUnder
haystacksplit on every occurrence ofseparator, matching under the collation.- Parameters:
rules- the collationhaystack- the text splitseparator- the separator- Returns:
- the parts, in order
-