13# include <absl/container/node_hash_map.h>
15# include <unordered_map>
24 size_t operator()(
const std::filesystem::path& path)
const noexcept {
return std::filesystem::hash_value(path); }
32using PathMap = absl::node_hash_map<std::filesystem::path, V, PathHash>;
35using PathMap = std::unordered_map<std::filesystem::path, V, PathHash>;
46 const std::filesystem::path&
path()
const {
return path_; }
47 std::string_view
buf()
const {
return buf_; }
52 Pos end()
const {
return Pos((uint32_t)buf_.size()); }
61 std::pair<uint32_t, uint32_t>
rowcol(
Pos pos)
const;
68 std::string_view
line(uint32_t
row)
const;
78 uint32_t phantom_()
const {
return rows_.size() > 1 && rows_.back() == buf_.size() ? 1 : 0; }
80 std::string_view sub(uint32_t
begin, uint32_t
end)
const {
84 std::filesystem::path path_;
86 std::vector<uint32_t> rows_;
99 std::pair<const Src*, bool>
add(std::filesystem::path path, std::string buf);
103 std::pair<const Src*, bool>
add(std::filesystem::path path);
106 static std::string
slurp(std::istream& is);
114 const Src*
lookup(
const std::filesystem::path& path)
const;
121 static std::filesystem::path
key(
const std::filesystem::path& path);
Interns the text - and the std::filesystem::path - of every file a Loc may point into.
std::pair< const Src *, bool > add(std::filesystem::path path)
As above, but reads the content from path.
static std::filesystem::path key(const std::filesystem::path &path)
The key path is interned under - absolute, symlink-free, and normalized.
const Src * lookup(const std::filesystem::path &path) const
std::pair< const Src *, bool > add(std::filesystem::path path, std::string buf)
static std::string slurp(std::istream &is)
Reads all of is into a std::string.
The content of one source file together with the offsets its rows start at.
std::string_view buf() const
std::string_view line(uint32_t row) const
Text of the 1-based row without its line terminator - or a leading utf8::Bom; empty if row is out of ...
uint32_t num_rows() const
The number of rows the file actually has.
bool contains(Pos pos) const
uint32_t col(Pos pos) const
Src(std::filesystem::path path, std::string buf)
const std::filesystem::path & path() const
Pos prev(Pos pos) const
Start of the last code point before pos - the character a half-open Loc::end points past.
uint32_t row(Pos pos) const
std::pair< uint32_t, uint32_t > rowcol(Pos pos) const
std::unordered_map< std::filesystem::path, V, PathHash > PathMap
Maps a std::filesystem::path to V.
Hashes a std::filesystem::path - consistent with its operator==, which compares lexically.
size_t operator()(const std::filesystem::path &path) const noexcept
Byte offset into a Src; pass around as value.
constexpr Pos() noexcept=default
Creates an invalid Position.