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

Didier Ernotte didier at ernotte.com
Sun Jul 17 08:52:49 EDT 2005


Hi,

I want to display in a textbox a windows-1251 encoded string that comes
from the source of a web page (loaded from an XmlHttpRequest object). I
guess I have to encode it into a UTF-8 string before displaying it in a
textbox (direct display shows me garbage). 
I try to use 

var uConv =
Components.classes['@mozilla.org/intl/utf8converterservice;1'].
  createInstance(Components.interfaces.nsIUTF8ConverterService);
var str = uConv.convertStringToUTF8(gRssXmlHttpRequest.responseText,
gRssXmlHttpRequest.getResponseHeader("Content-Encoding"), false);
document.getElementById("inforss.html.code").value =
gRssXmlHttpRequest.str;

without success. I have also tried

var unicodeConverter =
Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
unicodeConverter.charset =
gRssXmlHttpRequest.getResponseHeader("Content-Encoding");
var str = unicodeConverter.ConvertToUnicode(
gRssXmlHttpRequest.responseText ) + unicodeConverter.Finish();
document.getElementById("inforss.html.code").value =
gRssXmlHttpRequest.str;

without success. 

I have saw that in the localization XPCOM object there are "Character
Set Detectors". How can I use them to check the encoding of the source
string ?

Does anyone have a clue  ?

Thanks

Didier


More information about the Project_owners mailing list