Consolidate lower and upper logic (#2594)

This commit is contained in:
Andrew Gaul 2024-11-06 00:07:12 +09:00 committed by GitHub
parent a101b88114
commit 45b32046cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 8 deletions

View File

@ -593,8 +593,7 @@ size_t S3fsCurl::HeaderCallback(void* data, size_t blockSize, size_t numBlocks,
if(getline(ss, key, ':')){ if(getline(ss, key, ':')){
// Force to lower, only "x-amz" // Force to lower, only "x-amz"
std::string lkey = key; std::string lkey = lower(key);
transform(lkey.cbegin(), lkey.cend(), lkey.begin(), static_cast<int (*)(int)>(std::tolower));
if(is_prefix(lkey.c_str(), "x-amz")){ if(is_prefix(lkey.c_str(), "x-amz")){
key = lkey; key = lkey;
} }
@ -746,9 +745,8 @@ acl_t S3fsCurl::GetDefaultAcl()
std::string S3fsCurl::SetStorageClass(const std::string& storage_class) std::string S3fsCurl::SetStorageClass(const std::string& storage_class)
{ {
std::string old = S3fsCurl::storage_class; std::string old = S3fsCurl::storage_class;
S3fsCurl::storage_class = storage_class;
// AWS requires uppercase storage class values // 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; return old;
} }

View File

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cerrno> #include <cerrno>
@ -98,10 +99,13 @@ off_t cvt_strtoofft(const char* str, int base)
std::string lower(std::string s) std::string lower(std::string s)
{ {
// change each character of the std::string to lower case std::transform(s.cbegin(), s.cend(), s.begin(), ::tolower);
for(size_t i = 0; i < s.length(); i++){ return s;
s[i] = static_cast<char>(tolower(s[i])); }
}
std::string upper(std::string s)
{
std::transform(s.cbegin(), s.cend(), s.begin(), ::toupper);
return s; return s;
} }

View File

@ -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_right(std::string s, const char *t = SPACES);
std::string trim(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 lower(std::string s);
std::string upper(std::string s);
std::string peeloff(std::string s); std::string peeloff(std::string s);
// //