From: Brendan Hansen Date: Mon, 14 Dec 2020 16:45:34 +0000 (-0600) Subject: added 'reader.read_word' X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d1753505b3761e1ee0e44a41e378e53251a05fda;p=onyx.git added 'reader.read_word' --- 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;