diff options
| author | gingerBill <bill@gingerbill.org> | 2020-12-07 10:55:27 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-12-07 10:55:27 +0000 |
| commit | 96d8971d87fbe4156fd1653a205a84cf66469bc7 (patch) | |
| tree | 2a1afa3c4f70260aa9c9a5b8e825b48b8a338614 /core | |
| parent | 98c8fde0989c455ae88cedf2622029510d2519fc (diff) | |
Add `peek_n` to `package text/scanner`
Diffstat (limited to 'core')
| -rw-r--r-- | core/text/scanner/scanner.odin | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/text/scanner/scanner.odin b/core/text/scanner/scanner.odin index 30fa961a8..a3c44e909 100644 --- a/core/text/scanner/scanner.odin +++ b/core/text/scanner/scanner.odin @@ -160,6 +160,21 @@ peek :: proc(s: ^Scanner) -> rune { return s.ch; } +peek_n :: proc(s: ^Scanner, n: int) -> rune { + assert(n >= 0); + if n == 0 { + return peek(s); + } + + prev_s := s^; + for in 0..<n { + next(s); + } + ch := peek(s); + s^ = prev_s; + return ch; +} + error :: proc(s: ^Scanner, msg: string) { s.error_count += 1; |