aboutsummaryrefslogtreecommitdiff
path: root/src/functions.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/functions.hpp')
-rw-r--r--src/functions.hpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/functions.hpp b/src/functions.hpp
index 123f4ab..89e3b01 100644
--- a/src/functions.hpp
+++ b/src/functions.hpp
@@ -6,6 +6,7 @@
#define T_FUNCTIONS_HPP
#include "sha256/picosha2.h"
+#include <string>
std::string &ltrim(std::string &str, const std::string &chars = "\t\n\v\f\r ") {
str.erase(0, str.find_first_not_of(chars));
@@ -28,4 +29,16 @@ std::string sha256_hash(std::string text) {
std::string hex_str = picosha2::bytes_to_hex_string(hash.begin(), hash.end());
return hex_str;
}
+
+std::string prefix(std::string hash,
+ std::unordered_map<std::string, std::string> tasks) {
+ std::string prefix;
+ for (size_t i = 1; i <= hash.length(); i++) {
+ prefix = hash.substr(0, i);
+ if (tasks.find(prefix) == tasks.end())
+ return prefix;
+ }
+ return hash;
+}
+
#endif // T_FUNCTIONS_HPP