Chrome和Safari处理UTF-8则不同Firefox和IE,如果UTF-8字符不难codeD问题? [英] Chrome and Safari handles utf 8 differently then Firefox and IE if utf 8 character not hard coded issue?

查看:179
本文介绍了Chrome和Safari处理UTF-8则不同Firefox和IE,如果UTF-8字符不难codeD问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注:问题的标题是如本元 Q&放讨论变化; A

我使用的口音插件 jQuery的bassistance自动完成插件,所以我有免费的口音,自动完成。雅绅特的地图是这样的:

 地图= {'A​​':'A','我':'I'};

我有字符问题,我(土耳其大写我点)。之后,我删除的口音和转换为小写的,我有这个code:

 (伊斯坦布尔)。的indexOf(是)

Firefox和IE给出了 0 ,而Chrome和Safari给 1

字符$ C $猫(0)给出所有的浏览器相同的结果。

看来,Chrome和Safari对待正常的和重音的的不同。

修改

喜再次,约5个月后,我终于可以添加更多的源我的问题。结果
幸运的是质疑的日期和我的备份在该日期帮助我找到源$ C ​​$ C。

之前(土耳其语İBUG)当我改变我的code是 AFTER(工程确定)。结果是固定的
下面我也将我的文档charshet(这是土耳其语)

我不是单code专家,但是如果你让我猜测的Chrome VS FF的问题:结果
镀铬处理与源$ C ​​$ C的characther,我的意思是像\\ u0128结果
FF与看得见的characher处理它,我的意思是像我

之前(土耳其语我BUG)

 函数remove_accent(STR){VAR map={'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'AE','Ç':'C','È':'E','É':'E','Ê':'E','Ë':'E','Ì':'I','Í':'I','Î':'I','Ï':'I','Ð':'D','Ñ':'N','Ò':'O','Ó':'O','Ô':'O','Õ':'O','Ö':'O','Ø':'O','Ù':'U','Ú':'U','Û':'U','Ü':'U','Ý':'Y','ß':'s','à':'a','á':'a','â':'a','ã':'a','ä':'a','å':'a','æ':'ae','ç':'c','è':'e','é':'e','ê':'e','ë':'e','ì':'i','í':'i','î':'i','ï':'i','ñ':'n','ò':'o','ó':'o','ô':'o','õ':'o','ö':'o','ø':'o','ù':'u','ú':'u','û':'u','ü':'u','ý':'y','ÿ':'y','Ā':'A','ā':'a','Ă':'A','ă':'a','Ą':'A','ą':'a','Ć':'C','ć':'c','Ĉ':'C','ĉ':'c','Ċ':'C','ċ':'c','Č':'C','č':'c','Ď':'D','ď':'d','Đ':'D','đ':'d','Ē':'E','ē':'e','Ĕ':'E','ĕ':'e','Ė':'E','ė':'e','Ę':'E','ę':'e','Ě':'E','ě':'e','Ĝ':'G','ĝ':'g','Ğ':'G','ğ':'g','Ġ':'G','ġ':'g','Ģ':'G','ģ':'g','Ĥ':'H','ĥ':'h','Ħ':'H','ħ':'h','Ĩ':'I','ĩ':'i','Ī':'I','ī':'i','Ĭ':'I','ĭ':'i','Į':'I','į':'i','İ':'I','ı':'i','IJ':'IJ','ij':'ij','Ĵ':'J','ĵ':'j','Ķ':'K','ķ':'k','Ĺ':'L','ĺ':'l','Ļ':'L','ļ':'l','Ľ':'L','ľ':'l','Ŀ':'L','ŀ':'l','Ł':'L','ł':'l','Ń':'N','ń':'n','Ņ':'N','ņ':'n','Ň':'N','ň':'n','ʼn':'n','Ō':'O','ō':'o','Ŏ':'O','ŏ':'o','Ő':'O','ő':'o','Œ':'OE','œ':'oe','Ŕ':'R','ŕ':'r','Ŗ':'R','ŗ':'r','Ř':'R','ř':'r','Ś':'S','ś':'s','Ŝ':'S','ŝ':'s','Ş':'S','ş':'s','Š':'S','š':'s','Ţ':'T','ţ':'t','Ť':'T','ť':'t','Ŧ':'T','ŧ':'t','Ũ':'U','ũ':'u','Ū':'U','ū':'u','Ŭ':'U','ŭ':'u','Ů':'U','ů':'u','Ű':'U','ű':'u','Ų':'U','ų':'u','Ŵ':'W','ŵ':'w','Ŷ':'Y','ŷ':'y','Ÿ':'Y','Ź':'Z','ź':'z','Ż':'Z','ż':'z','Ž':'Z','ž':'z','ſ':'s','ƒ':'f','Ơ':'O','ơ':'o','Ư':'U','ư':'u','Ǎ':'A','ǎ':'a','Ǐ':'I','ǐ':'i','Ǒ':'O','ǒ':'o','Ǔ':'U','ǔ':'u','Ǖ':'U','ǖ':'u','Ǘ':'U','ǘ':'u','Ǚ':'U','ǚ':'u','Ǜ':'U','ǜ':'u','Ǻ':'A','ǻ':'a','Ǽ':'AE','ǽ':'ae','Ǿ':'O','ǿ':'o'};var RES ='';为(VAR I = 0; I< str.length;我++){C = str.charAt(I); RES + =图[C] ||℃;}返回水库;}

AFTER(工程确定)

  VAR charToAccentedCharClassMap = {
// A至H
    '一世': '[Iiı\\xcc-\\xcf\\xec-\\xef\Ĩ-\İ\IJ\ij\Ǐ\ǐ\Ȉ-\ȋ\ᴵ\ᵢ\Ḭ\ḭ\Ỉ-\ị\ⁱ\ℐ\ℑ\ℹ\ⅈ\Ⅰ-\Ⅳ\Ⅵ-\Ⅸ\Ⅺ\Ⅻ\ⅰ-\ⅳ\ⅵ-\ⅸ\ⅺ\ⅻ\⒤\Ⓘ\ⓘ\㍺\㏌\㏕\fi\ffi\I\i]'
∥焦到Z
    };


功能deaccent(accentedString){
    VAR的结果= accentedString;
    对(在charToAccentedCharClassMap VAR键){
        结果= result.replace(新的RegExp(charToAccentedCharClassMap [键],G),键);
    }
    //console.log(accentedString)
    返回result.toLowerCase();
}

功能remove_accent(STR){
    返回deaccent(STR).toLowerCase();
    返回海峡;
}

EDIT2 小校正(SO用户编辑的问题,但失误İ他的键盘):结果
他将接替(伊斯坦布尔)。的indexOf(是)的(伊斯坦布尔)。的indexOf(是)


解决方案

 (伊斯坦布尔)。的indexOf(是)
(伊斯坦布尔)。与toLowerCase()的indexOf(是)

小写的'我'是'我'。是这里发生了什么?

编辑:

可能为时已晚,但是我现在还记得我遇到了一个非常相似的情况下,@是从@不同,因为它是一个不同的UNI code字符。我解决它由像在字符串中的硬编码统一code号 \\ u0040

note: question title is change as discussed in this meta Q&A

I'm using the jQuery bassistance autocomplete plugin with the accent plugin, so I have accent-free autocomplete. Accent map is like this:

map={'À':'A', 'İ':'I'};

I have problems with the character İ (turkish uppercase I with point). After I remove accents and convert to lowercase, I have this code:

   ("İstanbul").indexOf("is")

Firefox and IE gives 0, but Chrome and Safari gives -1.

charCodeAt(0) gives the same result in all browsers.

It seems that Chrome and Safari treats the normal I and the unaccented I different.

EDIT

Hi again, after about 5 months, I can finally add more source to my question.
Fortunately question date and my backups at that date helps me find source code.

BEFORE(TURKISH İ BUG) was fixed when I change my code with AFTER (WORKS OK).
Below I added also my document charshet(which is turkish)

I am not unicode expert, but if you let me guess about the "chrome vs ff" issue:
chrome handles the characther with "source code", I mean like \u0128
ff handles it with "visible characher", I mean like "İ"

BEFORE(TURKISH I BUG)

function remove_accent(str) {var map={'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'AE','Ç':'C','È':'E','É':'E','Ê':'E','Ë':'E','Ì':'I','Í':'I','Î':'I','Ï':'I','Ð':'D','Ñ':'N','Ò':'O','Ó':'O','Ô':'O','Õ':'O','Ö':'O','Ø':'O','Ù':'U','Ú':'U','Û':'U','Ü':'U','Ý':'Y','ß':'s','à':'a','á':'a','â':'a','ã':'a','ä':'a','å':'a','æ':'ae','ç':'c','è':'e','é':'e','ê':'e','ë':'e','ì':'i','í':'i','î':'i','ï':'i','ñ':'n','ò':'o','ó':'o','ô':'o','õ':'o','ö':'o','ø':'o','ù':'u','ú':'u','û':'u','ü':'u','ý':'y','ÿ':'y','Ā':'A','ā':'a','Ă':'A','ă':'a','Ą':'A','ą':'a','Ć':'C','ć':'c','Ĉ':'C','ĉ':'c','Ċ':'C','ċ':'c','Č':'C','č':'c','Ď':'D','ď':'d','Đ':'D','đ':'d','Ē':'E','ē':'e','Ĕ':'E','ĕ':'e','Ė':'E','ė':'e','Ę':'E','ę':'e','Ě':'E','ě':'e','Ĝ':'G','ĝ':'g','Ğ':'G','ğ':'g','Ġ':'G','ġ':'g','Ģ':'G','ģ':'g','Ĥ':'H','ĥ':'h','Ħ':'H','ħ':'h','Ĩ':'I','ĩ':'i','Ī':'I','ī':'i','Ĭ':'I','ĭ':'i','Į':'I','į':'i','İ':'I','ı':'i','IJ':'IJ','ij':'ij','Ĵ':'J','ĵ':'j','Ķ':'K','ķ':'k','Ĺ':'L','ĺ':'l','Ļ':'L','ļ':'l','Ľ':'L','ľ':'l','Ŀ':'L','ŀ':'l','Ł':'L','ł':'l','Ń':'N','ń':'n','Ņ':'N','ņ':'n','Ň':'N','ň':'n','ʼn':'n','Ō':'O','ō':'o','Ŏ':'O','ŏ':'o','Ő':'O','ő':'o','Œ':'OE','œ':'oe','Ŕ':'R','ŕ':'r','Ŗ':'R','ŗ':'r','Ř':'R','ř':'r','Ś':'S','ś':'s','Ŝ':'S','ŝ':'s','Ş':'S','ş':'s','Š':'S','š':'s','Ţ':'T','ţ':'t','Ť':'T','ť':'t','Ŧ':'T','ŧ':'t','Ũ':'U','ũ':'u','Ū':'U','ū':'u','Ŭ':'U','ŭ':'u','Ů':'U','ů':'u','Ű':'U','ű':'u','Ų':'U','ų':'u','Ŵ':'W','ŵ':'w','Ŷ':'Y','ŷ':'y','Ÿ':'Y','Ź':'Z','ź':'z','Ż':'Z','ż':'z','Ž':'Z','ž':'z','ſ':'s','ƒ':'f','Ơ':'O','ơ':'o','Ư':'U','ư':'u','Ǎ':'A','ǎ':'a','Ǐ':'I','ǐ':'i','Ǒ':'O','ǒ':'o','Ǔ':'U','ǔ':'u','Ǖ':'U','ǖ':'u','Ǘ':'U','ǘ':'u','Ǚ':'U','ǚ':'u','Ǜ':'U','ǜ':'u','Ǻ':'A','ǻ':'a','Ǽ':'AE','ǽ':'ae','Ǿ':'O','ǿ':'o'};var res='';for (var i=0;i<str.length;i++){c=str.charAt(i);res+=map[c]||c;}return res;}  

AFTER (WORKS OK)

var charToAccentedCharClassMap = {
// A to H
    'I': '[Iiı\xcc-\xcf\xec-\xef\u0128-\u0130\u0132\u0133\u01cf\u01d0\u0208-\u020b\u1d35\u1d62\u1e2c\u1e2d\u1ec8-\u1ecb\u2071\u2110\u2111\u2139\u2148\u2160-\u2163\u2165-\u2168\u216a\u216b\u2170-\u2173\u2175-\u2178\u217a\u217b\u24a4\u24be\u24d8\u337a\u33cc\u33d5\ufb01\ufb03\uff29\uff49]'
// J to Z
    };

function deaccent(accentedString) { var result = accentedString; for (var key in charToAccentedCharClassMap) { result = result.replace(new RegExp(charToAccentedCharClassMap[key], "g"), key); } //console.log(accentedString) return result.toLowerCase(); }

function remove_accent(str) { return deaccent(str).toLowerCase(); return str; }

EDIT2 little correction (SO user edited question but misses İ his keyboard):
He replaces ("İstanbul").indexOf("is") by ("istanbul").indexOf("is")

解决方案

("istanbul").indexOf("is")
("Istanbul").toLowerCase().indexOf("ıs")

Lowercase 'I' is 'ı'. Is that what is happening here?

EDIT:

Probably too late, but I remember now I encountered a very similar case where "@" was different from "@" because it was a different unicode character. I solved it by hardcoding the Unicode number in the string like "\u0040"

这篇关于Chrome和Safari处理UTF-8则不同Firefox和IE,如果UTF-8字符不难codeD问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆