aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/references.hh
diff options
context:
space:
mode:
authorThéophane Hufschmitt <theophane.hufschmitt@tweag.io>2023-03-17 15:51:08 +0100
committerThéophane Hufschmitt <theophane.hufschmitt@tweag.io>2023-05-24 14:11:50 +0200
commit3ebe1341abe1b0ad59bd4925517af18d9200f818 (patch)
tree66e6ef77c7c60ac559c7aac06f1054427a0afcb1 /src/libutil/references.hh
parent6e4570234d5ac63a9483fb7f7aabaa1d17561a3a (diff)
Make `RewritingSink` accept a map of rewrites
Giving it the same semantics as `rewriteStrings`. Also add some tests for it
Diffstat (limited to 'src/libutil/references.hh')
-rw-r--r--src/libutil/references.hh56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/libutil/references.hh b/src/libutil/references.hh
new file mode 100644
index 000000000..ffd730e7b
--- /dev/null
+++ b/src/libutil/references.hh
@@ -0,0 +1,56 @@
+#pragma once
+///@file
+
+#include "hash.hh"
+
+namespace nix {
+
+class RefScanSink : public Sink
+{
+ StringSet hashes;
+ StringSet seen;
+
+ std::string tail;
+
+public:
+
+ RefScanSink(StringSet && hashes) : hashes(hashes)
+ { }
+
+ StringSet & getResult()
+ { return seen; }
+
+ void operator () (std::string_view data) override;
+};
+
+struct RewritingSink : Sink
+{
+ const StringMap rewrites;
+ long unsigned int maxRewriteSize;
+ std::string prev;
+ Sink & nextSink;
+ uint64_t pos = 0;
+
+ std::vector<uint64_t> matches;
+
+ RewritingSink(const std::string & from, const std::string & to, Sink & nextSink);
+ RewritingSink(const StringMap & rewrites, Sink & nextSink);
+
+ void operator () (std::string_view data) override;
+
+ void flush();
+};
+
+struct HashModuloSink : AbstractHashSink
+{
+ HashSink hashSink;
+ RewritingSink rewritingSink;
+
+ HashModuloSink(HashType ht, const std::string & modulus);
+
+ void operator () (std::string_view data) override;
+
+ HashResult finish() override;
+};
+
+}