Skip to content

Commit

Permalink
Run the formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
moffatman committed Jul 8, 2024
1 parent 3ee0eaa commit be90498
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 93 deletions.
178 changes: 95 additions & 83 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -394,40 +394,52 @@ const mathmlTextIntegrationPointElements = [
];

class Charcode {
static const int kNull = 0x00;
/// '\t'
static const int kTab = 0x09;
/// '\n'
static const int kLineFeed = 0x0A;
static const int kFormFeed = 0x0C;
/// '\r'
static const int kCarriageReturn = 0x0D;
/// ' '
static const int kSpace = 0x20;
/// '"'
static const int kDoubleQuote = 0x22;
/// '&'
static const int kAmpersand = 0x26;
/// "'"
static const int kSingleQuote = 0x27;
/// '-'
static const int kHyphen = 0x2D;
/// '<'
static const int kLessThan = 0x3C;
/// '='
static const int kEquals = 0x3D;
/// '>'
static const int kGreaterThan = 0x3E;
/// '`'
static const int kGraveAccent = 0x60;
static const int kNull = 0x00;

/// '\t'
static const int kTab = 0x09;

/// '\n'
static const int kLineFeed = 0x0A;
static const int kFormFeed = 0x0C;

/// '\r'
static const int kCarriageReturn = 0x0D;

/// ' '
static const int kSpace = 0x20;

/// '"'
static const int kDoubleQuote = 0x22;

/// '&'
static const int kAmpersand = 0x26;

/// "'"
static const int kSingleQuote = 0x27;

/// '-'
static const int kHyphen = 0x2D;

/// '<'
static const int kLessThan = 0x3C;

/// '='
static const int kEquals = 0x3D;

/// '>'
static const int kGreaterThan = 0x3E;

/// '`'
static const int kGraveAccent = 0x60;
}

const spaceCharacters = {
Charcode.kSpace,
Charcode.kLineFeed,
Charcode.kCarriageReturn,
Charcode.kTab,
Charcode.kFormFeed
Charcode.kSpace,
Charcode.kLineFeed,
Charcode.kCarriageReturn,
Charcode.kTab,
Charcode.kFormFeed
};

bool isWhitespace(String? char) {
Expand Down Expand Up @@ -457,58 +469,58 @@ const List<String> tableInsertModeElements = [

// TODO(jmesserly): remove these in favor of the test functions
const asciiLetters = {
0x41,
0x42,
0x43,
0x44,
0x45,
0x46,
0x47,
0x48,
0x49,
0x4A,
0x4B,
0x4C,
0x4D,
0x4E,
0x4F,
0x50,
0x51,
0x52,
0x53,
0x54,
0x55,
0x56,
0x57,
0x58,
0x59,
0x5A,
0x61,
0x62,
0x63,
0x64,
0x65,
0x66,
0x67,
0x68,
0x69,
0x6A,
0x6B,
0x6C,
0x6D,
0x6E,
0x6F,
0x70,
0x71,
0x72,
0x73,
0x74,
0x75,
0x76,
0x77,
0x78,
0x79,
0x7A,
0x41,
0x42,
0x43,
0x44,
0x45,
0x46,
0x47,
0x48,
0x49,
0x4A,
0x4B,
0x4C,
0x4D,
0x4E,
0x4F,
0x50,
0x51,
0x52,
0x53,
0x54,
0x55,
0x56,
0x57,
0x58,
0x59,
0x5A,
0x61,
0x62,
0x63,
0x64,
0x65,
0x66,
0x67,
0x68,
0x69,
0x6A,
0x6B,
0x6C,
0x6D,
0x6E,
0x6F,
0x70,
0x71,
0x72,
0x73,
0x74,
0x75,
0x76,
0x77,
0x78,
0x79,
0x7A,
};

const _zeroCode = 48;
Expand Down
12 changes: 9 additions & 3 deletions lib/src/html_input_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class HtmlInputStream {

return String.fromCharCodes(_chars.sublist(start, _offset));
}

String charsUntil1(int charCode, [bool opposite = false]) {
final start = _offset;
int? c;
Expand All @@ -267,19 +268,24 @@ class HtmlInputStream {

return String.fromCharCodes(_chars.sublist(start, _offset));
}

String charsUntil2(int charCode1, int charCode2, [bool opposite = false]) {
final start = _offset;
int? c;
while ((c = peekCodeUnit()) != null && (charCode1 == c! || charCode2 == c) == opposite) {
while ((c = peekCodeUnit()) != null &&
(charCode1 == c! || charCode2 == c) == opposite) {
_offset += 1;
}

return String.fromCharCodes(_chars.sublist(start, _offset));
}
String charsUntil3(int charCode1, int charCode2, int charCode3, [bool opposite = false]) {

String charsUntil3(int charCode1, int charCode2, int charCode3,
[bool opposite = false]) {
final start = _offset;
int? c;
while ((c = peekCodeUnit()) != null && (charCode1 == c! || charCode2 == c || charCode3 == c) == opposite) {
while ((c = peekCodeUnit()) != null &&
(charCode1 == c! || charCode2 == c || charCode3 == c) == opposite) {
_offset += 1;
}

Expand Down
16 changes: 11 additions & 5 deletions lib/src/tokenizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ class HtmlTokenizer implements Iterator<Token> {
// have already been appended to lastFourChars and will have broken
// any <!-- or --> sequences
} else {
final chars = stream.charsUntil3(Charcode.kAmpersand, Charcode.kLessThan, Charcode.kNull);
final chars = stream.charsUntil3(
Charcode.kAmpersand, Charcode.kLessThan, Charcode.kNull);
_addToken(CharactersToken('$data$chars'));
}
return true;
Expand Down Expand Up @@ -778,7 +779,8 @@ class HtmlTokenizer implements Iterator<Token> {
} else if (data == eof) {
state = dataState;
} else {
final chars = stream.charsUntil3(Charcode.kLessThan, Charcode.kHyphen, Charcode.kNull);
final chars = stream.charsUntil3(
Charcode.kLessThan, Charcode.kHyphen, Charcode.kNull);
_addToken(CharactersToken('$data$chars'));
}
return true;
Expand Down Expand Up @@ -1176,7 +1178,8 @@ class HtmlTokenizer implements Iterator<Token> {
state = dataState;
} else {
_attributeValue.write(data);
_attributeValue.write(stream.charsUntil2(Charcode.kDoubleQuote, Charcode.kAmpersand));
_attributeValue.write(
stream.charsUntil2(Charcode.kDoubleQuote, Charcode.kAmpersand));
}
return true;
}
Expand All @@ -1198,7 +1201,8 @@ class HtmlTokenizer implements Iterator<Token> {
state = dataState;
} else {
_attributeValue.write(data);
_attributeValue.write(stream.charsUntil2(Charcode.kSingleQuote, Charcode.kAmpersand));
_attributeValue.write(
stream.charsUntil2(Charcode.kSingleQuote, Charcode.kAmpersand));
}
return true;
}
Expand Down Expand Up @@ -1400,7 +1404,9 @@ class HtmlTokenizer implements Iterator<Token> {
_addToken(currentToken!);
state = dataState;
} else {
currentStringToken.add(data!).add(stream.charsUntil2(Charcode.kHyphen, Charcode.kNull));
currentStringToken
.add(data!)
.add(stream.charsUntil2(Charcode.kHyphen, Charcode.kNull));
}
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions test/parser_feature_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ On line 4, column 3 of ParseError: Unexpected DOCTYPE. Ignored.
expect(parser.errors[0].errorCode, 'expected-doctype-but-got-chars');
expect(parser.errors[0].message,
'Unexpected non-space characters. Expected DOCTYPE.');
expect(
parser.errors[0].toString(),
expect(parser.errors[0].toString(),
'Unexpected non-space characters. Expected DOCTYPE.');
});

Expand Down

0 comments on commit be90498

Please sign in to comment.