[Project_owners] Convert a windows-1251 encoded string into a UTF-8 string

Danil Ivanov mash-funky at mail.ru
Tue Jul 19 02:15:32 EDT 2005


> Maybe I'm not fully understand, sorry, but... are you mean bug 241739
> "nsXULDocument seems unable to deal with non-ascii scripts"?

Anyway, if it's that bug:

function convertW1251NonAscii(str) {
  var utf = Components.classes["@mozilla.org/intl/utf8converterservice;1"]
                      .createInstance(Components.interfaces.nsIUTF8ConverterService);
  string = utf.convertStringToUTF8(str, "windows-1251", "false");
  
  //~ Russian characters hash
  var transArray = {'\u0410':'\u0410','\u0411':'\u0411',[other_characters]};
  
  var s = '';
  for (var i=0; i<str.length; i++)
    s += transArray[str[i]] ? transArray[str[i]] : string[i];
  
  return s;
}

Something like this. "Ugly hack", but works for me on small text with
russians letters.

-- 
  Danil Ivanov aka Mash



More information about the Project_owners mailing list