getting rid of string.read_line; use string.read_until instead
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 29 May 2021 17:11:48 +0000 (12:11 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 29 May 2021 17:11:48 +0000 (12:11 -0500)
core/string.onyx
tests/aoc-2020/day3.onyx
tests/aoc-2020/day4.onyx
tests/aoc-2020/day5.onyx
tests/aoc-2020/day6.onyx

index a34f65ee3654e0da7ac0eab0af94e2124e75791f..9bd6e4d1d1f1b0f5ef163b434bb44fb8d86a39e5 100644 (file)
@@ -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 "";
 
index e845be757990d71a67265e358944daaf41bb899e..63a7553d10ce9465bcf01208532251f8f962692c 100644 (file)
@@ -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;
index 30e541e38beb1c8a44c1249ae89e49050f0d7bf8..94f6c3edaf65e3623187070da48c1229c6c03e89 100644 (file)
@@ -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 " ");
index d1898aa22d67b49c9438dd56ee0888d1d5ba5cdb..15be62981eb759a47af4cb7f6d730f0f217bd338 100644 (file)
@@ -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;
index d816149d060ddfe3db03527de61d98de95a9a57f..1d731702033c9b53d95ca54485af2ca41a44b609 100644 (file)
@@ -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;