From d1753505b3761e1ee0e44a41e378e53251a05fda Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 14 Dec 2020 10:45:34 -0600 Subject: [PATCH] added 'reader.read_word' --- core/string/reader.onyx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/string/reader.onyx b/core/string/reader.onyx index b60a34b2..f1dcaa78 100644 --- a/core/string/reader.onyx +++ b/core/string/reader.onyx @@ -133,6 +133,26 @@ read_until :: proc (use reader: ^StringReader, skip: u32, uptos: ..u8) -> str { return out; } +// Reads a continuous string of alphabetic chars along with underscores '_' +read_word :: proc (use reader: ^StringReader) -> str { + if count == 0 do return str.{ null, 0 }; + + out := str.{ data, 0 }; + for ch: *(cast(^str) reader) { + if (ch >= #char "a" && ch <= #char "z") + || (ch >= #char "A" && ch <= #char "Z") + || ch == #char "_" { + out.count += 1; + } + else do break; + } + + data += out.count; + count -= out.count; + + return out; +} + advance_line :: proc (use reader: ^StringReader) { if count == 0 do return; -- 2.25.1