Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  test_serializers_entities.js   Sprache: JAVA

 
const encoders = {
  xml: doc => {
    let enc = Cu.createDocumentEncoder("text/xml");
    enc.init(doc, "text/xml", Ci.nsIDocumentEncoder.OutputLFLineBreak);
    return enc;
  },
  html: doc => {
    let enc = Cu.createDocumentEncoder("text/html");
    enc.init(doc, "text/html", Ci.nsIDocumentEncoder.OutputLFLineBreak);
    return enc;
  },
  htmlBasic: doc => {
    let enc = Cu.createDocumentEncoder("text/html");
    enc.init(
      doc,
      "text/html",
      Ci.nsIDocumentEncoder.OutputEncodeBasicEntities |
        Ci.nsIDocumentEncoder.OutputLFLineBreak
    );
    return enc;
  },
  xhtml: doc => {
    let enc = Cu.createDocumentEncoder("application/xhtml+xml");
    enc.init(
      doc,
      "application/xhtml+xml",
      Ci.nsIDocumentEncoder.OutputLFLineBreak
    );
    return enc;
  },
};

// Which characters should we encode as entities?  It depends on the serializer.
const encodeAll = { html: true, htmlBasic: true, xhtml: true, xml: true };
const encodeHTMLBasic = {
  html: false,
  htmlBasic: true,
  xhtml: false,
  xml: false,
};
const encodeXML = { html: false, htmlBasic: false, xhtml: true, xml: true };
const encodeNone = { html: false, htmlBasic: false, xhtml: false, xml: false };
const encodingInfoMap = new Map([
  // Basic sanity chars '<', '>', '"', '&' get encoded in all cases.
  ["<", encodeAll],
  [">", encodeAll],
  ["&", encodeAll],
  // nbsp is only encoded with the HTML encoder when encoding basic entities.
  ["\xA0", encodeHTMLBasic],
]);

const encodingMap = new Map([
  ["<""<"],
  [">"">"],
  ["&""&"],
  // nbsp is only encoded with the HTML encoder when encoding basic entities.
  ["\xA0"" "],
]);

function encodingInfoForChar(c) {
  var info = encodingInfoMap.get(c);
  if (info) {
    return info;
  }
  return encodeNone;
}

function encodingForChar(c, type) {
  var info = encodingInfoForChar(c);
  if (!info[type]) {
    return c;
  }
  return encodingMap.get(c);
}

const doc = new DOMParser().parseFromString("""text/xml");
const root = doc.documentElement;
for (let i = 0; i < 255; ++i) {
  let el = doc.createElement("span");
  el.textContent = String.fromCharCode(i);
  root.appendChild(el);
}
for (let type of ["xml""xhtml""htmlBasic""html"]) {
  let str = encoders[type](doc).encodeToString();
  const prefix = "";
  const suffix = "
"
;
  Assert.ok(str.startsWith(prefix), `${type} serialization starts correctly`);
  Assert.ok(str.endsWith(suffix), `${type} serialization ends correctly`);
  str = str.substring(prefix.length, str.length - suffix.length);
  let encodings = str.split("");
  for (let i = 0; i < 255; ++i) {
    let c = String.fromCharCode(i);
    Assert.equal(
      encodingForChar(c, type),
      encodings[i],
      `${type} encoding of char ${i} is correct`
    );
  }
}

Messung V0.5
C=96 H=89 G=92

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge