diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-12 21:12:36 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-12 21:32:30 +0000 |
commit | f6f01416b71f239c0d9594f5c6201dfd208fe8c4 (patch) | |
tree | f8553504b0b9630ba8fef19ccfd9668b1f70c5e1 /src/libutil | |
parent | 2853ba4ab26c254d564aee9e75fe8f9f664b94fc (diff) |
Use `std::string_view` in a few more places
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/hash.cc | 4 | ||||
-rw-r--r-- | src/libutil/hash.hh | 2 | ||||
-rw-r--r-- | src/libutil/util.cc | 6 | ||||
-rw-r--r-- | src/libutil/util.hh | 6 |
4 files changed, 9 insertions, 9 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index c935f05eb..460d479a3 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -125,7 +125,7 @@ std::string Hash::to_string(Base base, bool includeType) const } -Hash::Hash(const std::string & s, HashType type) +Hash::Hash(std::string_view s, HashType type) : type(type) { size_t pos = 0; @@ -194,7 +194,7 @@ Hash::Hash(const std::string & s, HashType type) } else if (isSRI || size == base64Len()) { - auto d = base64Decode(std::string(s, pos)); + auto d = base64Decode(s.substr(pos)); if (d.size() != hashSize) throw BadHash("invalid %s hash '%s'", isSRI ? "SRI" : "base-64", s); assert(hashSize); diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 5080539b2..180fb7633 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -42,7 +42,7 @@ struct Hash Subresource Integrity hash expression). If the 'type' argument is htUnknown, then the hash type must be specified in the string. */ - Hash(const std::string & s, HashType type = htUnknown); + Hash(std::string_view s, HashType type = htUnknown); void init(); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index e0a99152b..b66447e08 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1314,7 +1314,7 @@ bool statusOk(int status) } -bool hasPrefix(const string & s, const string & prefix) +bool hasPrefix(std::string_view s, std::string_view prefix) { return s.compare(0, prefix.size(), prefix) == 0; } @@ -1408,7 +1408,7 @@ std::string filterANSIEscapes(const std::string & s, bool filterAll, unsigned in static char base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -string base64Encode(const string & s) +string base64Encode(std::string_view s) { string res; int data = 0, nbits = 0; @@ -1429,7 +1429,7 @@ string base64Encode(const string & s) } -string base64Decode(const string & s) +string base64Decode(std::string_view s) { bool init = false; char decode[256]; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 4b117f9bc..c95232317 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -416,7 +416,7 @@ template<class N> bool string2Float(const string & s, N & n) /* Return true iff `s' starts with `prefix'. */ -bool hasPrefix(const string & s, const string & prefix); +bool hasPrefix(std::string_view s, std::string_view prefix); /* Return true iff `s' ends in `suffix'. */ @@ -455,8 +455,8 @@ std::string filterANSIEscapes(const std::string & s, /* Base64 encoding/decoding. */ -string base64Encode(const string & s); -string base64Decode(const string & s); +string base64Encode(std::string_view s); +string base64Decode(std::string_view s); /* Get a value for the specified key from an associate container. */ |