From fd50939d0d895b48da0b6e96aa49e0dd966653cc Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 29 May 2021 12:11:48 -0500 Subject: [PATCH] getting rid of string.read_line; use string.read_until instead --- core/string.onyx | 24 ------------------------ tests/aoc-2020/day3.onyx | 4 ++-- tests/aoc-2020/day4.onyx | 4 ++-- tests/aoc-2020/day5.onyx | 4 ++-- tests/aoc-2020/day6.onyx | 9 +++++---- 5 files changed, 11 insertions(+), 34 deletions(-) diff --git a/core/string.onyx b/core/string.onyx index a34f65ee..9bd6e4d1 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -255,30 +255,6 @@ advance :: proc { } } - - -// DEPRECATED -// Everything below this point is deprecated - -// Goes up to but not including the closest newline or EOF -read_line :: (s: ^str, out: ^str) { - out.data = s.data; - out.count = 0; - - for ch: *s { - if ch == #char "\n" do break; - out.count += 1; - } - - s.data += out.count; - s.count -= out.count; - - if s.count > 0 { - s.data += 1; - s.count -= 1; - } -} - read_until :: (s: ^str, upto: u8, skip := 0) -> str { if s.count == 0 do return ""; diff --git a/tests/aoc-2020/day3.onyx b/tests/aoc-2020/day3.onyx index e845be75..63a7553d 100644 --- a/tests/aoc-2020/day3.onyx +++ b/tests/aoc-2020/day3.onyx @@ -24,8 +24,8 @@ main :: (args: [] cstr) { width := 0; height := 0; while true { - line := ""; - string.read_line(^contents, ^line); + line := string.read_until(^contents, #char "\n"); + string.advance(^contents, 1); if line.count == 0 do break; width = line.count; diff --git a/tests/aoc-2020/day4.onyx b/tests/aoc-2020/day4.onyx index 30e541e3..94f6c3ed 100644 --- a/tests/aoc-2020/day4.onyx +++ b/tests/aoc-2020/day4.onyx @@ -7,8 +7,8 @@ process_passport :: (contents: ^str) -> u32 { field_count := 0; while true { - line: str; - string.read_line(contents, ^line); + line := string.read_until(contents, #char "\n"); + string.advance(contents, 1); if line.count == 0 do break; fields := string.split(line, #char " "); diff --git a/tests/aoc-2020/day5.onyx b/tests/aoc-2020/day5.onyx index d1898aa2..15be6298 100644 --- a/tests/aoc-2020/day5.onyx +++ b/tests/aoc-2020/day5.onyx @@ -11,8 +11,8 @@ main :: (args: [] cstr) { max_val := 0; while true { - line: str; - string.read_line(^contents, ^line); + line := string.read_until(^contents, #char "\n"); + string.advance(^contents); if line.count == 0 do break; val := 0; diff --git a/tests/aoc-2020/day6.onyx b/tests/aoc-2020/day6.onyx index d816149d..1d731702 100644 --- a/tests/aoc-2020/day6.onyx +++ b/tests/aoc-2020/day6.onyx @@ -7,8 +7,8 @@ part_1 :: (contents: ^str) -> u32 { for ^ch: chars do *ch = false; while true { - line: str; - string.read_line(contents, ^line); + line := string.read_until(contents, #char "\n"); + string.advance(contents, 1); if line.count == 0 do break; for ch: line do chars[~~ch - cast(u32) #char "a"] = true; @@ -26,9 +26,10 @@ part_2 :: (contents: ^str) -> u32 { person_count := 0; while true { - line: str; - string.read_line(contents, ^line); + line := string.read_until(contents, #char "\n"); + string.advance(contents, 1); if line.count == 0 do break; + person_count += 1; for ch: line do chars[~~ch - cast(u32) #char "a"] += 1; -- 2.25.1