From fde39beb4bc27db6d9362bc9d7ba9e35d2c81829 Mon Sep 17 00:00:00 2001 From: Ashamandi Date: Tue, 28 Nov 2017 14:54:48 +0200 Subject: [PATCH 1/4] add arabic normalization function --- addon/search/searchcursor.js | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/addon/search/searchcursor.js b/addon/search/searchcursor.js index 58bc47c2c3..e6df6f2fb5 100644 --- a/addon/search/searchcursor.js +++ b/addon/search/searchcursor.js @@ -114,11 +114,43 @@ } } } + + //Normalization for Arabic + var normalizeArabicChars = function (s) { + function filter(c) { + // ALEF Chars + if ((c =='\u0625') || (c =='\u0623') || (c =='\u0622') || (c =='\u0675') || + (c =='\u0673')|| (c =='\u0672') || (c =='\u0671') || (c =='\u0670') || + (c =='\u0674') ) + return '\u0627' + // TAAA MARBOTA Chars + else if ((c =='\u06c3') || (c =='\u06c2') || (c =='\u06c0') || (c =='\u06c1') || + (c =='\u0647') ) + return '\u0629' + // YAAA Chars + else if ((c =='\u0649') || (c =='\u064a') || (c =='\u0678') || (c =='\u064a') ) + return '\u0620' + else if (c =='\u0626') + return '\u0620\u0621' + else + return c + } + var normalized = "", i, l + for (i = 0, l = s.length; i < l; i = i + 1) { + normalized = normalized + filter(s.charAt(i)) + } + return normalized + } + + function isArabic(str) { + var pattern = /[\u0600-\u06FF\u0750-\u077F]/; + return pattern.test(str); + } var doFold, noFold if (String.prototype.normalize) { - doFold = function(str) { return str.normalize("NFD").toLowerCase() } - noFold = function(str) { return str.normalize("NFD") } + doFold = function(str) { return isArabic(str)? normalizeArabicChars(str) : str.normalize("NFD").toLowerCase() } + noFold = function(str) { return isArabic(str)? normalizeArabicChars(str) : str.normalize("NFD") } } else { doFold = function(str) { return str.toLowerCase() } noFold = function(str) { return str } From 9fca3eac20be63760f142b521b6652de5b9c2c9c Mon Sep 17 00:00:00 2001 From: Ashamandi Date: Wed, 6 Dec 2017 10:20:49 +0200 Subject: [PATCH 2/4] handle style comments --- addon/search/searchcursor.js | 42 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/addon/search/searchcursor.js b/addon/search/searchcursor.js index e6df6f2fb5..85f84e349e 100644 --- a/addon/search/searchcursor.js +++ b/addon/search/searchcursor.js @@ -114,26 +114,34 @@ } } } - + //Normalization for Arabic var normalizeArabicChars = function (s) { function filter(c) { - // ALEF Chars - if ((c =='\u0625') || (c =='\u0623') || (c =='\u0622') || (c =='\u0675') || - (c =='\u0673')|| (c =='\u0672') || (c =='\u0671') || (c =='\u0670') || - (c =='\u0674') ) - return '\u0627' - // TAAA MARBOTA Chars - else if ((c =='\u06c3') || (c =='\u06c2') || (c =='\u06c0') || (c =='\u06c1') || - (c =='\u0647') ) - return '\u0629' - // YAAA Chars - else if ((c =='\u0649') || (c =='\u064a') || (c =='\u0678') || (c =='\u064a') ) - return '\u0620' - else if (c =='\u0626') - return '\u0620\u0621' - else - return c + switch (c) { + // ALEF Chars + case 'إ' : + case 'أ' : + case 'آ' : + case 'ٵ' : + case 'ٳ' : + case 'ٲ' : + case 'ٱ' : + return 'ا' + // TAAA MARBOTA Chars + case 'ۃ' : + case 'ہ' : + return 'ة' + // YAAA Chars + case 'ى' : + case 'ي' : + case 'ٸ' : + return 'ي' + case 'ئ': + return 'ي ء' + default : + return c + } } var normalized = "", i, l for (i = 0, l = s.length; i < l; i = i + 1) { From 06f207e448e4bea66d4302fb2ebfa37fd3afea8c Mon Sep 17 00:00:00 2001 From: Ashamandi Date: Wed, 6 Dec 2017 12:46:54 +0200 Subject: [PATCH 3/4] add normalizeArabicChars to doFold and noFold --- addon/search/searchcursor.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/addon/search/searchcursor.js b/addon/search/searchcursor.js index 85f84e349e..c4ca90b0e1 100644 --- a/addon/search/searchcursor.js +++ b/addon/search/searchcursor.js @@ -150,18 +150,26 @@ return normalized } - function isArabic(str) { + function hasArabic(str) { var pattern = /[\u0600-\u06FF\u0750-\u077F]/; return pattern.test(str); } var doFold, noFold - if (String.prototype.normalize) { - doFold = function(str) { return isArabic(str)? normalizeArabicChars(str) : str.normalize("NFD").toLowerCase() } - noFold = function(str) { return isArabic(str)? normalizeArabicChars(str) : str.normalize("NFD") } - } else { - doFold = function(str) { return str.toLowerCase() } - noFold = function(str) { return str } + doFold = function(str){ + str = str.toLowerCase() + if (String.prototype.normalize) + str = str.normalize("NFD") + if (hasArabic(str)) + return normalizeArabicChars(str) + return str + } + noFold = function(str){ + if (String.prototype.normalize) + str = str.normalize("NFD") + if (hasArabic(str)) + return normalizeArabicChars(str) + return str } // Maps a position in a case-folded line back to a position in the original line From 576b990906ce921bf7e06b9c1d977ec6953d9d0b Mon Sep 17 00:00:00 2001 From: Ashamandi Date: Wed, 6 Dec 2017 13:01:47 +0200 Subject: [PATCH 4/4] removing space between Al-HAMZAH and Al-YAA --- addon/search/searchcursor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/search/searchcursor.js b/addon/search/searchcursor.js index c4ca90b0e1..5c2564186d 100644 --- a/addon/search/searchcursor.js +++ b/addon/search/searchcursor.js @@ -138,7 +138,7 @@ case 'ٸ' : return 'ي' case 'ئ': - return 'ي ء' + return 'يء' default : return c }