random little fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 2 Dec 2021 13:58:26 +0000 (07:58 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 2 Dec 2021 13:58:26 +0000 (07:58 -0600)
core/io/reader.onyx
core/string.onyx
tests/aoc-2021/day02 [new file with mode: 0644]

index 800313d5ba6c5a2b5a9c08073e4ddf251face549..6f5d005ebf062231b4f0018e873aaee5cd7d19b5 100644 (file)
@@ -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;
 }
index 6159eb2bb475eef09bd7e8e680ef661bd210fb3b..e7d907e38032a534d6b7b4310ab347cda4e5f6cf 100644 (file)
@@ -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 (file)
index 0000000..f486dca
--- /dev/null
@@ -0,0 +1 @@
+Part 2: 1965970888