rem: var str = ''; for (var i = 0; i < text.length; i++) { var c = text.charCodeAt(i); if ((c <= 0x7F) || !gEntityConverter) { if (text[i] == '<') str += '&amp;<span class="entity">lt;</span>'; else if (text[i] == '>') str += '&amp;<span class="entity">gt;</span>'; else if (text[i] == '&') str += '&amp;<span class="entity">amp;</span>'; else str += text[i]; } else { try { var unichar = gEntityConverter.ConvertToEntity(text[i], entityVersion); str += '&amp;<span class="entity">' +  unichar.substring(1, unichar.length) +  '</span>'; } catch(e) { str += text[i]; } } } 
add: const entityVersion = Components.interfaces.nsIEntityConverter.entityW3C;  var str = text;   str = str.replace(/[<>&"]/g, charTableLookup);   str = str.replace(/[^\0-\u007f]/g, convertEntity);  
context: function unicodeTOentity(text){  if (!gEntityConverter) {    try {      gEntityConverter = Components.classes["@mozilla.org/intl/entityconverter;1"]                                   .createInstance(Components.interfaces.nsIEntityConverter);    } catch(e) { }  }  var entityVersion = Components.interfaces.nsIEntityConverter.html40                    + Components.interfaces.nsIEntityConverter.mathml20;  var str = '';  for (var i = 0; i < text.length; i++) {    var c = text.charCodeAt(i);    if ((c <= 0x7F) || !gEntityConverter) {      if (text[i] == '<')        str += '&amp;<span class="entity">lt;</span>';      else if (text[i] == '>')        str += '&amp;<span class="entity">gt;</span>';      else if (text[i] == '&')        str += '&amp;<span class="entity">amp;</span>';      else        str += text[i];    }    else {      try {        var unichar = gEntityConverter.ConvertToEntity(text[i], entityVersion);        str += '&amp;<span class="entity">'            +  unichar.substring(1, unichar.length) // extract '&'            +  '</span>';      }      catch(e) {        str += text[i];      }    }  }  return str;}
meta: 9421	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/9421/87d41981addf2e045f5c8f7d792f12a31742f872/viewPartialSource.js/buggy/toolkit/components/viewsource/content/viewPartialSource.js