diff options
author | Max <post@wickenrode.com> | 2015-03-07 20:48:55 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-03-07 20:48:55 +0100 |
commit | 96b765ffbcb6c7fda058fbe8028b2e128007134a (patch) | |
tree | a4ac6c9fb75b5b810f7c42f1d159937caa6c2dda /Source/SPStringAdditions.h | |
parent | ed38f229a052a678d3a5022afd3806b1c3b434cf (diff) | |
download | sequelpro-96b765ffbcb6c7fda058fbe8028b2e128007134a.tar.gz sequelpro-96b765ffbcb6c7fda058fbe8028b2e128007134a.tar.bz2 sequelpro-96b765ffbcb6c7fda058fbe8028b2e128007134a.zip |
Added an internal algorithm for fuzzy string matching
* This works similar to a regex matching "abc" as /a.*b.*c/ (ie. all characters of $needle need to be contained in $haystack in the correct order but not neccesarily consecutive). Additionaly some unicode equivalencies are handled.
* Changed a tiny helper function from ObjC to plain C
Diffstat (limited to 'Source/SPStringAdditions.h')
-rw-r--r-- | Source/SPStringAdditions.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index 3296326f..c6871e2a 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -81,4 +81,23 @@ static inline id NSMutableAttributedStringAttributeAtIndex(NSMutableAttributedSt - (CGFloat)levenshteinDistanceWithWord:(NSString *)stringB; +/** + * Checks if the string other is contained in self on a per-character basis. + * In regex-speak that would mean "abc" is matched as /a.*b.*c/ (not anchored). + * This is a SEARCH function, NOT a MATCHING function! + * Namely the following options will be applied when matching: + * NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch|NSDiacriticInsensitiveSearch + * Additionaly this method might match even when it should not. + * + * @param other String to match against self + * @param submatches Pass the pointer to a variable that will be set to an NSArray * + * of NSNumber *s of NSRanges. This will only be the case if + * the method also returns YES. The variable will not be modified + * otherwise. + * Pass NULL if you don't care for the ranges. + * The object will be set to autorelase. + * @return YES if self contains all characters from other in the order given in other + * @warning This method is NOT thread-safe (probably), NOT constant-time and DOES NOT check binary equivalence + */ +- (BOOL)nonConsecutivelySearchString:(NSString *)other matchingRanges:(NSArray **)submatches; @end |