string - Is Javascript's toUpperCase() language safe? -
will javascript's string prototype method touppercase()
deliver naturally expected result in every utf-8-supported language/charset?
i've tried simplified chinese, south korean, tamil, japanese , cyrillic , results seemed reasonable far. can rely on method being language-safe?
example:
"イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス".touppercase() > "イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス"
edit: @quentin pointed out, there string.prototype.tolocaleuppercase()
"safer" use, have support ie 8 , above, webkit-based browsers. since part of ecmascript 3 standard, should available on browsers, right?
does know of cases using delivers naturally unexpected results?
what expect?
javascript's touppercase()
method supposed use "locale invariant upper case mapping" defined unicode standard. so, basically, "i".touppercase()
supposed i
in cases. in cases locale invariant upper case mapping consists of multiple letters, browsers not upper case them correctly, example "ß".touppercase()
not ss
.
also, there locales have different uppercase rules rest of world, notable example being turkish, uppercase version of i
İ
(and vice versa) , lowercase version of i
ı
(and vice versa).
if want behaviour, need browser set turkish locale, , have use tolocaleuppercase()
method.
also note writing systems have third case, "title case", applied first letter of word when want "capitalize" it. defined unicode standard (for example, title case of ligature nj
is Nj
while upper case NJ
), (as far know) not available javascript. therefore if try capitalize word using substring
, touppercase
, expect wrong in rare cases.
Comments
Post a Comment