From cfba4e44f11df8299d416fdb439914af1ace5e2f Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 9 Dec 2020 08:59:46 -0600 Subject: [PATCH] added read_u64 and fold_slice --- core/array.onyx | 7 +++++++ core/string/reader.onyx | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/array.onyx b/core/array.onyx index 5407dcd3..b367d3a5 100644 --- a/core/array.onyx +++ b/core/array.onyx @@ -119,6 +119,13 @@ fold :: proc (arr: ^[..] $T, init: $R, f: proc (T, R) -> R) -> R { return val; } +// CLEANUP: :slice Move this elsewhere when more slice functionality is added +fold_slice :: proc (arr: [] $T, init: $R, f: proc (T, R) -> R) -> R { + val := init; + for it: arr do val = f(it, val); + return val; +} + map :: proc (arr: ^[..] $T, data: $R, f: proc (T, R) -> T) { for ^it: *arr do *it = f(*it, data); } diff --git a/core/string/reader.onyx b/core/string/reader.onyx index 83485706..5cf797a4 100644 --- a/core/string/reader.onyx +++ b/core/string/reader.onyx @@ -43,6 +43,22 @@ read_u32 :: proc (use reader: ^StringReader) -> u32 { return n; } +read_u64 :: proc (use reader: ^StringReader) -> u64 { + n: u64 = 0; + + skip_whitespace(reader); + + while count > 0 && data[0] >= #char "0" && data[0] <= #char "9" { + n *= 10; + n += cast(u64) (data[0] - #char "0"); + + data += 1; + count -= 1; + } + + return n; +} + read_byte :: proc (use reader: ^StringReader) -> u8 { if count == 0 do return #char "\0"; -- 2.25.1