mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-18 22:41:18 +00:00
Support for diacritics aware strings comparison
This commit is contained in:
1 parent
4ea0d4d043
commit
bfbf8fb841
1 file changed
+39
@@ -55,6 +55,12 @@ CPAnchoredSearch = 8;
|
||||
@class CPString
|
||||
*/
|
||||
CPNumericSearch = 64;
|
||||
/*!
|
||||
Search ignores diacritic marks.
|
||||
@global
|
||||
@class CPString
|
||||
*/
|
||||
CPDiacriticInsensitiveSearch = 128;
|
||||
|
||||
var CPStringUIDs = new CFMutableDictionary();
|
||||
|
||||
@@ -469,6 +475,12 @@ var CPStringRegexSpecialCharacters = [
|
||||
rhs = rhs.toLowerCase();
|
||||
}
|
||||
|
||||
if(aMask & CPDiacriticInsensitiveSearch)
|
||||
{
|
||||
lhs = lhs.stripDiacritics();
|
||||
rhs = rhs.stripDiacritics();
|
||||
}
|
||||
|
||||
if (lhs < rhs)
|
||||
return CPOrderedAscending;
|
||||
else if (lhs > rhs)
|
||||
@@ -783,4 +795,31 @@ var CPStringRegexSpecialCharacters = [
|
||||
|
||||
@end
|
||||
|
||||
var diacritics = [[192,198],[224,230],[231,231],[232,235],[236,239],[242,246],[249,252]]; // Basic Latin ; Latin-1 Supplement.
|
||||
var normalized = [65,97,99,101,105,111,117];
|
||||
|
||||
String.prototype.stripDiacritics = function ()
|
||||
{
|
||||
var output = "";
|
||||
for (var indexSource = 0; indexSource < this.length; indexSource++)
|
||||
{
|
||||
var code = this.charCodeAt(indexSource);
|
||||
|
||||
for (var i = 0; i < diacritics.length; i++)
|
||||
{
|
||||
var drange = diacritics[i];
|
||||
|
||||
if (code >= drange[0] && code <= drange[drange.length-1])
|
||||
{
|
||||
code = normalized[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
output += String.fromCharCode(code);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
String.prototype.isa = CPString;
|
||||
Reference in new issue
Block a user