aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/common.h b/src/common.h
index 93da70b..35f9b0e 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,18 +1,36 @@
#pragma once
+#include <iostream>
#include <stdlib.h>
#include <utility>
struct line_view {
const char* line;
size_t length;
+
+ friend std::ostream& operator<<(std::ostream& o, const line_view& lv) {
+ for (size_t i = 0; i < lv.length; i++) {
+ o << lv.line[i];
+ }
+ return o;
+ }
+
+ bool operator==(const char* l) const noexcept {
+ size_t i = 0;
+ while (i < this->length) {
+ if (l[i] != this->line[i]) {
+ return false;
+ }
+ i++;
+ }
+ return l[i] == '\0';
+ }
};
line_view load_file(const char*);
line_view next_line(line_view, size_t*);
-template <typename F, typename... Args>
-void per_line(line_view file, F&& f, Args&&... args) {
+template <typename F, typename... Args> void per_line(line_view file, F&& f, Args&&... args) {
size_t offset = 0;
line_view lv;
do {