aboutsummaryrefslogtreecommitdiff
path: root/src/common.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-03-14 18:37:57 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-03-14 18:37:57 +0800
commit88509ee467b955f9cd23b7d02c16f2f35583cb0d (patch)
tree2b15d5f0ec2878ae67fce4c36a1151808d657ef5 /src/common.cpp
parent5eb187ae03d845e83b78a727533d311643adfd39 (diff)
downloadadvent-of-code-88509ee467b955f9cd23b7d02c16f2f35583cb0d.tar.gz
advent-of-code-88509ee467b955f9cd23b7d02c16f2f35583cb0d.zip
per line
Diffstat (limited to 'src/common.cpp')
-rw-r--r--src/common.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/common.cpp b/src/common.cpp
index be45494..d608a22 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -19,6 +19,13 @@ line_view load_file(const char* path) {
return lv;
}
-line_view next_line(line_view file) {
- return {nullptr, 0};
+line_view next_line(line_view file, size_t* offset) {
+ const char* p1 = file.line + *offset;
+ const char* p2 = p1;
+ const char* end = file.line + file.length;
+ while (p2 < end && *p2 != '\n') {
+ p2++;
+ }
+ *offset = p2 - file.line + 1;
+ return {p1, static_cast<size_t>(p2 - p1 + 1)};
}