Skip to content

Commit 68665e2

Browse files
committed
Obtain global tag prefix in one pass
1 parent 11a1044 commit 68665e2

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pkgs/yaml/lib/src/scanner.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -934,21 +934,28 @@ class Scanner {
934934

935935
_skipBlanks();
936936

937+
var prefix = '';
938+
937939
/// Both tag uri and local tags can be used as prefixes.
938940
///
939941
/// See: https://yaml.org/spec/1.2.2/#6822-tag-prefixes
940-
var prefix = _scanner.peekChar() == EXCLAMATION
941-
? _scanTagHandle(directive: true, isGlobalTagPrefix: true).tagHandle
942-
: '';
942+
if (_scanner.peekChar() == EXCLAMATION) {
943+
prefix = _scanTagHandle(
944+
directive: true,
945+
isGlobalTagPrefix: true,
946+
).tagHandle;
947+
} else {
948+
prefix = _scanTagUri();
943949

944-
prefix += _scanTagUri(); // Readability's sake
950+
if (prefix.isEmpty) {
951+
throw YamlException(
952+
'Expected a non-empty global tag prefix',
953+
_scanner.emptySpan,
954+
);
955+
}
956+
}
945957

946-
if (prefix.isEmpty) {
947-
throw YamlException(
948-
'Expected a non-empty global tag prefix',
949-
_scanner.emptySpan,
950-
);
951-
} else if (!_isBlankOrEnd) {
958+
if (!_isBlankOrEnd) {
952959
throw YamlException('Expected whitespace.', _scanner.emptySpan);
953960
}
954961

0 commit comments

Comments
 (0)