aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/iohash.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-10-03 12:35:44 +0200
committerGitHub Enterprise <[email protected]>2024-10-03 12:35:44 +0200
commitdb531191789f48a141c42fef229bca7a7922443d (patch)
treecc1570bf8dedccb975d594bd91284ac5d0bd0bae /src/zencore/iohash.cpp
parentsimplified CleanDirectory implementation (#182) (diff)
downloadzen-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.cpp18
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
{