From 9e35f9d9357d23d0b247937cc542e46b6cd68b2f Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 2 Dec 2021 07:58:26 -0600 Subject: [PATCH] random little fixes --- core/io/reader.onyx | 18 +++--------------- core/string.onyx | 2 +- tests/aoc-2021/day02 | 1 + 3 files changed, 5 insertions(+), 16 deletions(-) create mode 100644 tests/aoc-2021/day02 diff --git a/core/io/reader.onyx b/core/io/reader.onyx index 800313d5..6f5d005e 100644 --- a/core/io/reader.onyx +++ b/core/io/reader.onyx @@ -234,11 +234,7 @@ read_line :: (use reader: ^Reader, consume_newline := true, allocator := context if inplace do return buffer[start .. count]; - out := str.{ - data = raw_alloc(allocator, count * sizeof(u8)), - count = count - start, - }; - + out := memory.make_slice(u8, count - start); memory.copy(out.data, buffer.data + start, count - start); return out; } @@ -264,11 +260,7 @@ read_word :: (use reader: ^Reader, numeric_allowed := false, allocator := contex if inplace do return buffer[start .. count]; - out := str.{ - data = raw_alloc(allocator, count * sizeof(u8)), - count = count - start, - }; - + out := memory.make_slice(u8, count - start); memory.copy(out.data, buffer.data + start, count - start); return out; } @@ -292,11 +284,7 @@ read_until :: (use reader: ^Reader, until: u8, skip: u32 = 0, allocator := conte if inplace do return buffer[start .. count]; - out := str.{ - data = raw_alloc(allocator, count * sizeof(u8)), - count = count - start, - }; - + out := memory.make_slice(u8, count - start); memory.copy(out.data, buffer.data + start, count - start); return out; } diff --git a/core/string.onyx b/core/string.onyx index 6159eb2b..e7d907e3 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -173,7 +173,7 @@ ends_with :: (s: str, suffix: str) -> bool { strip_whitespace :: #match { (s: ^str) { strip_leading_whitespace(s); strip_trailing_whitespace(s); }, - (s: str) { strip_leading_whitespace(s); strip_trailing_whitespace(s); }, + (s: str) => s |> strip_leading_whitespace() |> strip_trailing_whitespace() } strip_leading_whitespace :: #match { diff --git a/tests/aoc-2021/day02 b/tests/aoc-2021/day02 new file mode 100644 index 00000000..f486dcac --- /dev/null +++ b/tests/aoc-2021/day02 @@ -0,0 +1 @@ +Part 2: 1965970888 -- 2.25.1