Krita Source Code Documentation
Loading...
Searching...
No Matches
kfts Namespace Reference

Namespaces

namespace  fuzzy_internal
 

Functions

static Q_DECL_UNUSED bool fuzzy_match (const QString pattern, const QString str, int &outScore)
 This should be the main function you should use. outscore is the score of this match and should be used to sort the results later. Without sorting of the results this function won't be as effective.
 
static Q_DECL_UNUSED bool fuzzy_match (const QString pattern, const QString str, int &outScore, uint8_t *matches, int maxMatches)
 
static Q_DECL_UNUSED bool fuzzy_match_sequential (const QString pattern, const QString str, int &outScore)
 This is a special case function which doesn't score separator matches higher than sequential matches. This is currently used in Kate's command bar where the string items are usually space separated names.
 
static Q_DECL_UNUSED bool fuzzy_match_simple (const QString pattern, const QString str)
 simple fuzzy matching of chars in pattern with chars in str sequentially
 
static Q_DECL_UNUSED QString to_fuzzy_matched_display_string (const QString pattern, QString &str, const QString &htmlTag, const QString &htmlTagClose)
 get string for display in treeview / listview. This should be used from style delegate. For example: with pattern = "kate", str = "kateapp" and @htmlTag = " the output will be kateapp which will be visible to user as kateapp.
 

Detailed Description

This is based on https://github.com/forrestthewoods/lib_fts/blob/master/code/fts_fuzzy_match.h with modifications for Qt

Dont include this file in a header file, please :)

Function Documentation

◆ fuzzy_match() [1/2]

static bool kfts::fuzzy_match ( const QString pattern,
const QString str,
int & outScore )
static

This should be the main function you should use. outscore is the score of this match and should be used to sort the results later. Without sorting of the results this function won't be as effective.

Definition at line 83 of file kfts_fuzzy_match.h.

84{
85 uint8_t matches[256];
86 return fuzzy_match(pattern, str, outScore, matches, sizeof(matches));
87}
static Q_DECL_UNUSED bool fuzzy_match(const QString pattern, const QString str, int &outScore)
This should be the main function you should use. outscore is the score of this match and should be us...

References fuzzy_match().

◆ fuzzy_match() [2/2]

static bool kfts::fuzzy_match ( const QString pattern,
const QString str,
int & outScore,
uint8_t * matches,
int maxMatches )
static

Definition at line 89 of file kfts_fuzzy_match.h.

90{
91 int recursionCount = 0;
92
93 auto strIt = str.cbegin();
94 auto patternIt = pattern.cbegin();
95 const auto patternEnd = pattern.cend();
96 const auto strEnd = str.cend();
97
98 return fuzzy_internal::fuzzy_match_recursive(patternIt, strIt, outScore, strIt, strEnd, patternEnd, nullptr, matches, maxMatches, 0, recursionCount);
99}

References kfts::fuzzy_internal::fuzzy_match_recursive().

◆ fuzzy_match_sequential()

static bool kfts::fuzzy_match_sequential ( const QString pattern,
const QString str,
int & outScore )
static

This is a special case function which doesn't score separator matches higher than sequential matches. This is currently used in Kate's command bar where the string items are usually space separated names.

Definition at line 101 of file kfts_fuzzy_match.h.

102{
103 int recursionCount = 0;
104 uint8_t matches[256];
105 auto maxMatches = sizeof(matches);
106 auto strIt = str.cbegin();
107 auto patternIt = pattern.cbegin();
108 const auto patternEnd = pattern.cend();
109 const auto strEnd = str.cend();
110
111 return fuzzy_internal::fuzzy_match_recursive(patternIt, strIt, outScore, strIt, strEnd, patternEnd, nullptr, matches, maxMatches, 0, recursionCount, 40);
112}

References kfts::fuzzy_internal::fuzzy_match_recursive().

◆ fuzzy_match_simple()

static bool kfts::fuzzy_match_simple ( const QString pattern,
const QString str )
static

simple fuzzy matching of chars in pattern with chars in str sequentially

Definition at line 72 of file kfts_fuzzy_match.h.

73{
74 auto patternIt = pattern.cbegin();
75 for (auto strIt = str.cbegin(); strIt != str.cend() && patternIt != pattern.cend(); ++strIt) {
76 if (strIt->toLower() == patternIt->toLower()) {
77 ++patternIt;
78 }
79 }
80 return patternIt == pattern.cend();
81}

◆ to_fuzzy_matched_display_string()

static QString kfts::to_fuzzy_matched_display_string ( const QString pattern,
QString & str,
const QString & htmlTag,
const QString & htmlTagClose )
static

get string for display in treeview / listview. This should be used from style delegate. For example: with pattern = "kate", str = "kateapp" and @htmlTag = " the output will be kateapp which will be visible to user as kateapp.

TODO: improve this so that we don't have to put html tags on every char probably using some kind of interval container

FIXME Don't do so many appends. Instead consider using some interval based solution to wrap a range of text with the html <tag></tag>

FIXME Don't do so many appends. Instead consider using some interval based solution to wrap a range of text with the html <tag></tag>

Definition at line 273 of file kfts_fuzzy_match.h.

274{
279 int j = 0;
280 for (int i = 0; i < str.size() && j < pattern.size(); ++i) {
281 if (str.at(i).toLower() == pattern.at(j).toLower()) {
282 str.replace(i, 1, htmlTag + str.at(i) + htmlTagClose);
283 i += htmlTag.size() + htmlTagClose.size();
284 ++j;
285 }
286 }
287 return str;
288}