refactor(HtmlLexer): process carriage returns in one pass

Closes #5867
This commit is contained in:
Georgios Kalpakas 2015-12-13 17:40:06 +02:00 committed by Georgios Kalpakas
parent 539c5633bf
commit 1607ef8782
1 changed files with 2 additions and 4 deletions

View File

@ -84,8 +84,7 @@ const $x = 120;
const $NBSP = 160;
var CRLF_REGEXP = /\r\n/g;
var CR_REGEXP = /\r/g;
var CR_OR_CRLF_REGEXP = /\r\n?/g;
function unexpectedCharacterErrorMsg(charCode: number): string {
var char = charCode === $EOF ? 'EOF' : StringWrapper.fromCharCode(charCode);
@ -127,8 +126,7 @@ class _HtmlTokenizer {
// http://www.w3.org/TR/html5/syntax.html#preprocessing-the-input-stream
// In order to keep the original position in the source, we can not pre-process it.
// Instead CRs are processed right before instantiating the tokens.
content = StringWrapper.replaceAll(content, CRLF_REGEXP, '\r');
return StringWrapper.replaceAll(content, CR_REGEXP, '\n');
return StringWrapper.replaceAll(content, CR_OR_CRLF_REGEXP, '\n');
}
tokenize(): HtmlTokenizeResult {