From 45b32046cd06c7025c5109cdfd844fb705c864c5 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 6 Nov 2024 00:07:12 +0900 Subject: [PATCH] Consolidate lower and upper logic (#2594) --- src/curl.cpp | 6 ++---- src/string_util.cpp | 12 ++++++++---- src/string_util.h | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index ac02857..df11168 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -593,8 +593,7 @@ size_t S3fsCurl::HeaderCallback(void* data, size_t blockSize, size_t numBlocks, if(getline(ss, key, ':')){ // Force to lower, only "x-amz" - std::string lkey = key; - transform(lkey.cbegin(), lkey.cend(), lkey.begin(), static_cast(std::tolower)); + std::string lkey = lower(key); if(is_prefix(lkey.c_str(), "x-amz")){ key = lkey; } @@ -746,9 +745,8 @@ acl_t S3fsCurl::GetDefaultAcl() std::string S3fsCurl::SetStorageClass(const std::string& storage_class) { std::string old = S3fsCurl::storage_class; - S3fsCurl::storage_class = storage_class; // AWS requires uppercase storage class values - transform(S3fsCurl::storage_class.cbegin(), S3fsCurl::storage_class.cend(), S3fsCurl::storage_class.begin(), ::toupper); + S3fsCurl::storage_class = upper(storage_class); return old; } diff --git a/src/string_util.cpp b/src/string_util.cpp index 6f3b628..42113a8 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include @@ -98,10 +99,13 @@ off_t cvt_strtoofft(const char* str, int base) std::string lower(std::string s) { - // change each character of the std::string to lower case - for(size_t i = 0; i < s.length(); i++){ - s[i] = static_cast(tolower(s[i])); - } + std::transform(s.cbegin(), s.cend(), s.begin(), ::tolower); + return s; +} + +std::string upper(std::string s) +{ + std::transform(s.cbegin(), s.cend(), s.begin(), ::toupper); return s; } diff --git a/src/string_util.h b/src/string_util.h index dc3a41c..c1716ec 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -89,6 +89,7 @@ std::string trim_left(std::string s, const char *t = SPACES); std::string trim_right(std::string s, const char *t = SPACES); std::string trim(std::string s, const char *t = SPACES); std::string lower(std::string s); +std::string upper(std::string s); std::string peeloff(std::string s); //