1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 17:31:47 +02:00

Make RewritingSink accept a map of rewrites

Giving it the same semantics as `rewriteStrings`.
Also add some tests for it
This commit is contained in:
Théophane Hufschmitt 2023-03-17 15:51:08 +01:00
parent 6e4570234d
commit 3ebe1341ab
7 changed files with 169 additions and 88 deletions

56
src/libutil/references.hh Normal file
View file

@ -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;
};
}