Giter Site home page Giter Site logo

fuzzymatch's Introduction

fuzzymatch

Dead-simple, efficient string and array fuzzy matching library.

Usable for everyone:

  • GC & phobos range users
  • betterC users (case-sensitive dstring or no-decode array check only)
  • @nogc users (in all cases)
  • string, wstring, dstring users
import fuzzymatch;

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("game.txt"));
assert(!"path/to/game.txt".fuzzyMatchesString("work.txt"));

Documentation

Implements a fuzzy search algorithm, yielding the same results as what the fuzzy match algorithm in VSCode matches. This is basically a fuzzy contains / canFind method for strings and arrays.

However this library does not offer any fuzzy match scoring. This functionality might be added in the future in new methods. The check-only methods are ideal if the result is intended to be passed into other systems that are responsible for display and sorting. (e.g. from DCD / serve-d into VSCode, IDEs or other editors)

It is quite efficient, allocates no memory and works with character ranges as well as simple arrays. Pre-compiled string versions are available for reduced compilation time for simple string/wstring/dstring matches.

This works by going through the search string character by character, on every matching character, the matcher string advances by one character. If the matcher string is completely checked, the fuzzy match returns true.

Methods:

  • fuzzyMatchesUni - fuzzy contains method with unicode decoding
  • fuzzyMatchesRaw - fuzzy contains method on arbitrary arrays

fuzzyMatchesUni

// rough definitions:
bool fuzzyMatchesUni(
	bool caseSensitive = false, R1, R2
)(
	in /* any char range or string */ R1 doesThis,
	in /* any char range or string */ R2 matchThis
) @safe pure nothrow @nogc

// pre-compiled case-insensitive variant:
bool fuzzyMatchesString(
	in string /* or wstring or dstring */ doesThis,
	in string /* or wstring or dstring */ matchThis
) @safe pure nothrow @nogc

// case-sensitive variant:
bool fuzzyMatchesStringCS(...) @safe pure nothrow @nogc

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 fuzzyMatchesStringCS method is another pre-compiled version of this fuzzyMatchesUni function, but performs caseSensitive checks.

See_Also:

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

fuzzyMatchesRaw

// rough definitions:
bool fuzzyMatchesRaw(R1, R2)(
	in /* any range or array */ R1 doesThis,
	in /* any range or array */ R2 matchThis
) @safe pure nothrow @nogc

Works like fuzzyMatchesUni, but does not do any UTF decoding, but rather just goes through the arrays element-by-element.

This method works case-sensitive if dstrings are passed into it.

This method has no dependency on the standard library and should work with betterC.

fuzzymatch's People

Contributors

webfreak001 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.