summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/hash.cpp
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2021-01-01 12:16:05 -0500
committer AJR <ajrhacker@users.noreply.github.com>2021-01-01 12:16:05 -0500
commit21fd9835451a5a7d7655964bfb7adb1ba9b8540f (patch)
tree514f8d654945329127fa93120d277adcafd4c2e9 /src/lib/util/hash.cpp
parentc296bd97293658a42a58c932161679ed51f97e1a (diff)
hash.cpp, hashing.cpp: Change string processing to use std::string_view parameters; add sum16 type
Diffstat (limited to 'src/lib/util/hash.cpp')
-rw-r--r--src/lib/util/hash.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/lib/util/hash.cpp b/src/lib/util/hash.cpp
index fd9f2c1d7cd..78f10bbff7f 100644
--- a/src/lib/util/hash.cpp
+++ b/src/lib/util/hash.cpp
@@ -148,15 +148,15 @@ void hash_collection::reset()
// from a string
//-------------------------------------------------
-bool hash_collection::add_from_string(char type, const char *buffer, int length)
+bool hash_collection::add_from_string(char type, std::string_view string)
{
// handle CRCs
if (type == HASH_CRC)
- return m_has_crc32 = m_crc32.from_string(buffer, length);
+ return m_has_crc32 = m_crc32.from_string(string);
// handle SHA1s
else if (type == HASH_SHA1)
- return m_has_sha1 = m_sha1.from_string(buffer, length);
+ return m_has_sha1 = m_sha1.from_string(string);
return false;
}
@@ -273,24 +273,19 @@ std::string hash_collection::attribute_string() const
// compact string to set of hashes and flags
//-------------------------------------------------
-bool hash_collection::from_internal_string(const char *string)
+bool hash_collection::from_internal_string(std::string_view string)
{
- assert(string != nullptr);
-
// start fresh
reset();
- // determine the end of the string
- const char *stringend = string + strlen(string);
- const char *ptr = string;
-
- // loop until we hit it
+ // loop until we hit the end of the string
bool errors = false;
int skip_digits = 0;
- while (ptr < stringend)
+ while (!string.empty())
{
- char c = *ptr++;
+ char c = string[0];
char uc = toupper(c);
+ string.remove_prefix(1);
// non-hex alpha values specify a hash type
if (uc >= 'G' && uc <= 'Z')
@@ -299,13 +294,13 @@ bool hash_collection::from_internal_string(const char *string)
if (uc == HASH_CRC)
{
m_has_crc32 = true;
- errors = !m_crc32.from_string(ptr, stringend - ptr);
+ errors = !m_crc32.from_string(string);
skip_digits = 2 * sizeof(crc32_t);
}
else if (uc == HASH_SHA1)
{
m_has_sha1 = true;
- errors = !m_sha1.from_string(ptr, stringend - ptr);
+ errors = !m_sha1.from_string(string);
skip_digits = 2 * sizeof(sha1_t);
}
else