diff options
author | Martin Fischer <martin@push-f.com> | 2023-09-09 22:15:54 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-09-28 10:36:08 +0200 |
commit | 394c52260e861e911e2d8706d4904136a920da87 (patch) | |
tree | b7511677c6f6a0ca03526991a770ef0b6752e963 /src/tokenizer/machine | |
parent | 5aa3b82fbe62882da8007b0a4548b979c845aa97 (diff) |
refactor: proxy emit_string calls through utils
This is done separately so that the next commit has a cleaner diff.
Diffstat (limited to 'src/tokenizer/machine')
-rw-r--r-- | src/tokenizer/machine/utils.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/tokenizer/machine/utils.rs b/src/tokenizer/machine/utils.rs index 6e45f4d..d96e50b 100644 --- a/src/tokenizer/machine/utils.rs +++ b/src/tokenizer/machine/utils.rs @@ -13,6 +13,24 @@ where O: Offset, E: Emitter<O>, { + /// Emits the given character as a character token. + #[inline] + pub(super) fn emit_char(&mut self, c: char) { + self.emitter.emit_string(ctostr!(c)); + } + + /// Emits every byte of the given byte slice as a character token. + /// + /// (We're operating on bytes to enable compiler optimization, + /// since [`str::chars`] isn't `const`.) + #[inline] + pub(super) fn emit_chars(&mut self, s: &[u8]) { + self.emitter.emit_string( + // this unsafe block is only temporary and will be removed in the next commit + unsafe { std::str::from_utf8_unchecked(s) }, + ); + } + #[inline] pub(crate) fn emit_error(&mut self, error: Error) { let span = match error { |