diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 877604f4c..cb5b23917 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -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;