Skip to content

Commit f675211

Browse files
committed
Set up some more helper extension methods for ITextReader.
1 parent 9591ae2 commit f675211

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

Schema/src/text/reader/TextReaderExtensions.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,36 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
using schema.util.symbols;
6-
75
namespace schema.text.reader;
86

97
public static partial class TextReaderExtensions {
8+
public static void SkipWhitespace(this ITextReader tr)
9+
=> tr.SkipManyIfPresent(TextReaderConstants.WHITESPACE_CHARS);
10+
11+
public static string ReadWord(this ITextReader tr) {
12+
tr.SkipWhitespace();
13+
return tr.ReadUpToStartOfTerminator([
14+
" ", "\t", "\n", "\r\n", ",", "{", "[", "}", "]", ":"
15+
]);
16+
}
17+
18+
public static bool TryToSkipComment(
19+
this ITextReader tr,
20+
string lineCommentPrefix = "//") {
21+
tr.SkipWhitespace();
22+
if (tr.Matches(lineCommentPrefix)) {
23+
tr.ReadLine();
24+
return true;
25+
}
26+
27+
if (tr.Matches("/*")) {
28+
tr.ReadUpToAndPastTerminator("*/");
29+
return true;
30+
}
31+
32+
return false;
33+
}
34+
1035
public static string[] ReadArguments(
1136
this ITextReader tr,
1237
ReadOnlySpan<char> separators,

0 commit comments

Comments
 (0)