fuzzyMatchesUni

Checks if doesThis contains matchThis in a way that a fuzzy search would find it.

Performs basic case-insensitivity checks. UTF decodes strings and wstrings, skipping invalid characters. Note that the case-insensitive version does not check for unicode sequences, such as German ß matching ss, but only by comparing single codepoints using their upper variant.

To perform no UTF decoding, either call this method with dstrings (UTF32 strings) or, if you checked that the string ONLY contains single code unit per user-conceived character, by using .representation and then fuzzyMatchesRaw - note that this method only works case-sensitive and won't perform any case-transformations!

If you have strings, you can save compilation speed by using the pre-compiled method fuzzyMatchesString, which accepts strings, wstring or dstrings.

The $(LEF fuzzyMatchesStringCS) method is another pre-compiled version of this fuzzyMatchesUni function, but performs caseSensitive checks.

  1. bool fuzzyMatchesUni(R1 doesThis, R2 matchThis)
    version(HasUnicodeFuzzymatch)
    @safe pure nothrow @nogc
    bool
    fuzzyMatchesUni
    (
    bool caseSensitive = false
    R1
    R2
    )
    (
    scope R1 doesThis
    ,
    scope R2 matchThis
    )
    if (
    !(
    is(R1 == dstring) &&
    is(R2 == dstring)
    &&
    caseSensitive
    )
    )
  2. bool fuzzyMatchesUni(R1 doesThis, R2 matchThis)

Examples

assert( "foo".fuzzyMatchesString(""));
assert( "foo".fuzzyMatchesString("Fo"));
assert(!"foo".fuzzyMatchesString("b"));

assert( "foo".fuzzyMatchesStringCS(""));
assert(!"foo".fuzzyMatchesStringCS("Fo"));
assert( "foo".fuzzyMatchesStringCS("fo"));
assert(!"foo".fuzzyMatchesStringCS("b"));

assert( "path/to/game.txt".fuzzyMatchesString("path/to/game.txt"));
assert( "path/to/game.txt".fuzzyMatchesString("path/to/game."));
assert( "path/to/game.txt".fuzzyMatchesString("pathgametxt"));
assert( "path/to/game.txt".fuzzyMatchesString("ptg"));
assert(!"path/to/game.txt".fuzzyMatchesString("ptf"));
assert("path/to/game.txt".fuzzyMatchesString("game.txt"));
assert(!"path/to/game.txt".fuzzyMatchesString("work.txt"));
import std.path : chainPath;
assert( chainPath("path", "to", "game.txt").fuzzyMatchesUni("ptg"w));
assert(!chainPath("path", "to", "game.txt").fuzzyMatchesUni("root"w));

See Also

- fuzzyMatchesRaw - performs no unicode decoding, not usable with strings, but with representations.

Meta