From 6ff1391fc28e001bae06a90f651efcd767d04ba4 Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Wed, 30 Oct 2019 10:09:14 +0100 Subject: [PATCH] Add hash functions for string and string_view --- src/hash.cpp | 14 +++++++++++++- src/hash.hpp | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/hash.cpp b/src/hash.cpp index 83dc47031..f839287d2 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -144,7 +144,19 @@ hash_string(struct hash* hash, const char* s) } void -hash_string_buffer(struct hash* hash, const char* s, int length) +hash_string(struct hash* hash, const std::string& s) +{ + hash_string_buffer(hash, s.data(), s.length()); +} + +void +hash_string_view(struct hash* hash, nonstd::string_view sv) +{ + hash_string_buffer(hash, sv.data(), sv.length()); +} + +void +hash_string_buffer(struct hash* hash, const char* s, size_t length) { hash_buffer(hash, s, length); do_debug_text(hash, "\n", 1); diff --git a/src/hash.hpp b/src/hash.hpp index 43b3a29a2..cfc092a09 100644 --- a/src/hash.hpp +++ b/src/hash.hpp @@ -20,6 +20,8 @@ #include "system.hpp" +#include "third_party/nonstd/string_view.hpp" + #define DIGEST_SIZE 20 #define DIGEST_STRING_BUFFER_SIZE (2 * DIGEST_SIZE + 1) @@ -78,7 +80,7 @@ void hash_delimiter(struct hash* hash, const char* type); // input file. void hash_buffer(struct hash* hash, const void* s, size_t len); -// Hash a string. +// Hash a NUL terminated string. // // If hash debugging is enabled, the string is written to the text input file // followed by a newline. @@ -88,7 +90,9 @@ void hash_string(struct hash* hash, const char* s); // // If hash debugging is enabled, the string is written to the text input file // followed by a newline. -void hash_string_buffer(struct hash* hash, const char* s, int length); +void hash_string_buffer(struct hash* hash, const char* s, size_t length); +void hash_string(struct hash* hash, const std::string& s); +void hash_string_view(struct hash* hash, nonstd::string_view sv); // Hash an integer. // -- 2.47.3