Skip to content

Commit

Permalink
refactor: use switches where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Oct 3, 2019
1 parent 55c0b1b commit edd86e1
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,14 @@ class SaxesParser {
const { chunk } = this;
while (true) {
const c = this.getCode();
if (c === NL) {
switch (c) {
case NL:
start = this.handleEOL(buffer, chunk, start);
}
else if (c === EOC) {
break;
case EOC:
this[buffer] += chunk.slice(start);
return EOC;
default:
}

if (chars.includes(c)) {
Expand All @@ -856,12 +858,14 @@ class SaxesParser {
const { chunk } = this;
while (true) {
const c = this.getCode();
if (c === NL) {
switch (c) {
case NL:
start = this.handleEOL(buffer, chunk, start);
}
else if (c === EOC) {
break;
case EOC:
this[buffer] += chunk.slice(start);
return false;
default:
}

if (c === char) {
Expand Down Expand Up @@ -993,10 +997,13 @@ class SaxesParser {
this.xmlDeclPossible = false;
}

if (c === LESS) {
switch (c) {
case LESS:
this.state = S_OPEN_WAKA;
}
else if (c !== EOC) {
break;
case EOC:
break;
default:
// have to process this as a text node.
// weird, but happens.
if (!this.reportedTextBeforeRoot) {
Expand Down Expand Up @@ -1230,15 +1237,18 @@ class SaxesParser {
/** @private */
sDoctype() {
const c = this.captureTo(DOCTYPE_TERMINATOR, "doctype");
if (c === GREATER) {
switch (c) {
case GREATER:
this.state = S_TEXT;
if (this.text.length !== 0) {
this.closeText();
}
this.ondoctype(this.doctype);
this.doctype = true; // just remember that we saw it.
}
else if (c !== EOC) {
break;
case EOC:
break;
default:
this.doctype += String.fromCodePoint(c);
if (c === OPEN_BRACKET) {
this.state = S_DTD;
Expand Down Expand Up @@ -1830,14 +1840,13 @@ class SaxesParser {
/** @private */
sAttribNameSawWhite() {
const c = this.skipSpaces();
if (c === EOC) {
switch (c) {
case EOC:
return;
}

if (c === EQUAL) {
case EQUAL:
this.state = S_ATTRIB_VALUE;
}
else {
break;
default:
this.fail("attribute without value.");
this.tag.attributes[this.name] = "";
this.text = "";
Expand Down Expand Up @@ -1932,14 +1941,17 @@ class SaxesParser {
/** @private */
sAttribValueUnquoted() {
const c = this.captureTo(ATTRIB_VALUE_UNQUOTED_TERMINATOR, "text");
if (c === AMP) {
switch (c) {
case AMP:
this.state = S_ENTITY;
this.entityReturnState = S_ATTRIB_VALUE_UNQUOTED;
}
else if (c === LESS) {
break;
case LESS:
this.fail("disallowed character.");
}
else if (c !== EOC) {
break;
case EOC:
break;
default:
if (this.text.includes("]]>")) {
this.fail("the string \"]]>\" is disallowed in char data.");
}
Expand Down Expand Up @@ -1970,11 +1982,13 @@ class SaxesParser {

/** @private */
sCloseTagSawWhite() {
const c = this.skipSpaces();
if (c === GREATER) {
switch (this.skipSpaces()) {
case GREATER:
this.closeTag();
}
else if (c !== EOC) {
break;
case EOC:
break;
default:
this.fail("disallowed character in closing tag.");
}
}
Expand Down

0 comments on commit edd86e1

Please sign in to comment.