diff options
| author | Dan Engelbrecht <[email protected]> | 2024-10-03 12:35:44 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-10-03 12:35:44 +0200 |
| commit | db531191789f48a141c42fef229bca7a7922443d (patch) | |
| tree | cc1570bf8dedccb975d594bd91284ac5d0bd0bae /src/zencore/iohash.cpp | |
| parent | simplified CleanDirectory implementation (#182) (diff) | |
| download | zen-db531191789f48a141c42fef229bca7a7922443d.tar.xz zen-db531191789f48a141c42fef229bca7a7922443d.zip | |
cache get command (#183)
* move TryParseObjectId and TryParseIoHash to Oid::TryParse and IoHash::TryParse respectively
* zen cache-get command
Diffstat (limited to 'src/zencore/iohash.cpp')
| -rw-r--r-- | src/zencore/iohash.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/zencore/iohash.cpp b/src/zencore/iohash.cpp index 8f3f8da26..7200e6e3f 100644 --- a/src/zencore/iohash.cpp +++ b/src/zencore/iohash.cpp @@ -99,6 +99,24 @@ IoHash::FromHexString(std::string_view string) return io; } +bool +IoHash::TryParse(std::string_view Str, IoHash& Hash) +{ + using namespace std::literals; + + if (Str.size() == IoHash::StringLength) + { + return ParseHexBytes(Str.data(), Str.size(), Hash.Hash); + } + + if (Str.starts_with("0x"sv)) + { + return TryParse(Str.substr(2), Hash); + } + + return false; +} + const char* IoHash::ToHexString(char* outString /* 40 characters + NUL terminator */) const { |