aboutsummaryrefslogtreecommitdiff
path: root/src/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/common.h b/src/common.h
index e320b66..93da70b 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,6 +1,7 @@
#pragma once
#include <stdlib.h>
+#include <utility>
struct line_view {
const char* line;
@@ -8,4 +9,16 @@ struct line_view {
};
line_view load_file(const char*);
-line_view next_line(line_view);
+line_view next_line(line_view, size_t*);
+
+template <typename F, typename... Args>
+void per_line(line_view file, F&& f, Args&&... args) {
+ size_t offset = 0;
+ line_view lv;
+ do {
+ lv = next_line(file, &offset);
+ if (!f(lv, std::forward<Args>(args)...)) {
+ break;
+ }
+ } while (offset < file.length);
+}