Prefer std::string::empty over length == 0 (#1679)

This is more concise.
This commit is contained in:
Andrew Gaul 2021-06-13 20:03:10 +09:00 committed by GitHub
parent 4d39ea887e
commit a100be9dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 18 deletions

View File

@ -205,7 +205,7 @@ bool AdditionalHeader::AddHeader(headers_t& meta, const char* path) const
}else{ }else{
// directly comparing // directly comparing
if(paddhead->basestring.length() < pathlength){ if(paddhead->basestring.length() < pathlength){
if(0 == paddhead->basestring.length() || 0 == strcmp(&path[pathlength - paddhead->basestring.length()], paddhead->basestring.c_str())){ if(paddhead->basestring.empty() || 0 == strcmp(&path[pathlength - paddhead->basestring.length()], paddhead->basestring.c_str())){
// match -> adding header // match -> adding header
meta[paddhead->headkey] = paddhead->headvalue; meta[paddhead->headkey] = paddhead->headvalue;
} }

View File

@ -953,7 +953,7 @@ bool S3fsCurl::LoadEnvSseKmsid()
bool S3fsCurl::GetSseKey(std::string& md5, std::string& ssekey) bool S3fsCurl::GetSseKey(std::string& md5, std::string& ssekey)
{ {
for(sseckeylist_t::const_iterator iter = S3fsCurl::sseckeys.begin(); iter != S3fsCurl::sseckeys.end(); ++iter){ for(sseckeylist_t::const_iterator iter = S3fsCurl::sseckeys.begin(); iter != S3fsCurl::sseckeys.end(); ++iter){
if(0 == md5.length() || md5 == (*iter).begin()->first){ if(md5.empty() || md5 == (*iter).begin()->first){
md5 = iter->begin()->first; md5 = iter->begin()->first;
ssekey = iter->begin()->second; ssekey = iter->begin()->second;
return true; return true;
@ -2658,7 +2658,7 @@ void S3fsCurl::insertV4Headers()
break; break;
} }
if(b_infile != NULL && 0 == payload_hash.length()){ if(b_infile != NULL && payload_hash.empty()){
S3FS_PRN_ERR("Failed to make SHA256."); S3FS_PRN_ERR("Failed to make SHA256.");
// TODO: propagate error // TODO: propagate error
} }

View File

@ -329,11 +329,11 @@ class S3fsCurl
static bool SetAccessKeyWithSessionToken(const char* AccessKeyId, const char* SecretAccessKey, const char * SessionToken); static bool SetAccessKeyWithSessionToken(const char* AccessKeyId, const char* SecretAccessKey, const char * SessionToken);
static bool IsSetAccessKeyID() static bool IsSetAccessKeyID()
{ {
return (0 < S3fsCurl::AWSAccessKeyId.size()); return !S3fsCurl::AWSAccessKeyId.empty();
} }
static bool IsSetAccessKeys() static bool IsSetAccessKeys()
{ {
return (0 < S3fsCurl::IAM_role.size() || ((0 < S3fsCurl::AWSAccessKeyId.size() || S3fsCurl::is_ibm_iam_auth) && 0 < S3fsCurl::AWSSecretAccessKey.size())); return !S3fsCurl::IAM_role.empty() || ((!S3fsCurl::AWSAccessKeyId.empty() || S3fsCurl::is_ibm_iam_auth) && !S3fsCurl::AWSSecretAccessKey.empty());
} }
static long SetSslVerifyHostname(long value); static long SetSslVerifyHostname(long value);
static long GetSslVerifyHostname() { return S3fsCurl::ssl_verify_hostname; } static long GetSslVerifyHostname() { return S3fsCurl::ssl_verify_hostname; }

View File

@ -145,7 +145,7 @@ std::string get_sorted_header_keys(const struct curl_slist* list)
} }
strkey.erase(pos); strkey.erase(pos);
} }
if(0 < sorted_headers.length()){ if(!sorted_headers.empty()){
sorted_headers += ";"; sorted_headers += ";";
} }
sorted_headers += lower(strkey); sorted_headers += lower(strkey);
@ -317,7 +317,7 @@ bool make_md5_from_binary(const char* pstr, size_t length, std::string& md5)
} }
// base64 md5 // base64 md5
md5 = s3fs_get_content_md5(fd); md5 = s3fs_get_content_md5(fd);
if(0 == md5.length()){ if(md5.empty()){
S3FS_PRN_ERR("Failed to make MD5."); S3FS_PRN_ERR("Failed to make MD5.");
fclose(fp); fclose(fp);
return false; return false;

View File

@ -277,7 +277,7 @@ static int chk_dir_object_type(const char* path, std::string& newpath, std::stri
nowpath = ""; nowpath = "";
}else{ }else{
nowpath = newpath; nowpath = newpath;
if(0 < nowpath.length() && '/' == *nowpath.rbegin()){ if(!nowpath.empty() && '/' == *nowpath.rbegin()){
// "dir/" type // "dir/" type
(*pType) = DIRTYPE_NEW; (*pType) = DIRTYPE_NEW;
}else{ }else{
@ -2694,7 +2694,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
query_prefix += "&prefix="; query_prefix += "&prefix=";
s3_realpath = get_realpath(path); s3_realpath = get_realpath(path);
if(0 == s3_realpath.length() || '/' != *s3_realpath.rbegin()){ if(s3_realpath.empty() || '/' != *s3_realpath.rbegin()){
// last word must be "/" // last word must be "/"
query_prefix += urlEncode(s3_realpath.substr(1) + "/"); query_prefix += urlEncode(s3_realpath.substr(1) + "/");
}else{ }else{
@ -2764,7 +2764,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
truncated = false; truncated = false;
}else{ }else{
next_marker = s3_realpath.substr(1); next_marker = s3_realpath.substr(1);
if(0 == s3_realpath.length() || '/' != *s3_realpath.rbegin()){ if(s3_realpath.empty() || '/' != *s3_realpath.rbegin()){
next_marker += "/"; next_marker += "/";
} }
next_marker += lastname; next_marker += lastname;
@ -2858,7 +2858,7 @@ static size_t parse_xattrs(const std::string& strxattrs, xattrs_t& xattrs)
} }
// parse each key:val // parse each key:val
for(size_t pair_nextpos = restxattrs.find_first_of(','); 0 < restxattrs.length(); restxattrs = (pair_nextpos != std::string::npos ? restxattrs.substr(pair_nextpos + 1) : std::string("")), pair_nextpos = restxattrs.find_first_of(',')){ for(size_t pair_nextpos = restxattrs.find_first_of(','); !restxattrs.empty(); restxattrs = (pair_nextpos != std::string::npos ? restxattrs.substr(pair_nextpos + 1) : std::string("")), pair_nextpos = restxattrs.find_first_of(',')){
std::string pair = pair_nextpos != std::string::npos ? restxattrs.substr(0, pair_nextpos) : restxattrs; std::string pair = pair_nextpos != std::string::npos ? restxattrs.substr(0, pair_nextpos) : restxattrs;
std::string key; std::string key;
PXATTRVAL pval = NULL; PXATTRVAL pval = NULL;
@ -3190,7 +3190,7 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
// calculate total name length // calculate total name length
size_t total = 0; size_t total = 0;
for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){ for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){
if(0 < xiter->first.length()){ if(!xiter->first.empty()){
total += xiter->first.length() + 1; total += xiter->first.length() + 1;
} }
} }
@ -3213,7 +3213,7 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
// copy to list // copy to list
char* setpos = list; char* setpos = list;
for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){ for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){
if(0 < xiter->first.length()){ if(!xiter->first.empty()){
strcpy(setpos, xiter->first.c_str()); strcpy(setpos, xiter->first.c_str());
setpos = &setpos[strlen(setpos) + 1]; setpos = &setpos[strlen(setpos) + 1];
} }

View File

@ -175,7 +175,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
if(strlen(dirpath) > strlen(basepath)){ if(strlen(dirpath) > strlen(basepath)){
withdirname = &dirpath[strlen(basepath)]; withdirname = &dirpath[strlen(basepath)];
} }
if(0 < withdirname.length() && '/' != *withdirname.rbegin()){ if(!withdirname.empty() && '/' != *withdirname.rbegin()){
withdirname += "/"; withdirname += "/";
} }
withdirname += mybname; withdirname += mybname;
@ -378,7 +378,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
xmlXPathFreeObject(ETag); xmlXPathFreeObject(ETag);
} }
} }
if(!head.insert(name, (0 < stretag.length() ? stretag.c_str() : NULL), is_dir)){ if(!head.insert(name, (!stretag.empty() ? stretag.c_str() : NULL), is_dir)){
S3FS_PRN_ERR("insert_object returns with error."); S3FS_PRN_ERR("insert_object returns with error.");
xmlXPathFreeObject(key); xmlXPathFreeObject(key);
xmlXPathFreeObject(contents_xp); xmlXPathFreeObject(contents_xp);

View File

@ -165,7 +165,7 @@ std::string S3ObjList::GetNormalizedName(const char* name) const
if(NULL == (ps3obj = GetS3Obj(name))){ if(NULL == (ps3obj = GetS3Obj(name))){
return std::string(""); return std::string("");
} }
if(0 == (ps3obj->normalname).length()){ if(ps3obj->normalname.empty()){
return std::string(name); return std::string(name);
} }
return ps3obj->normalname; return ps3obj->normalname;
@ -219,7 +219,7 @@ bool S3ObjList::GetNameList(s3obj_list_t& list, bool OnlyNormalized, bool CutSla
s3obj_t::const_iterator iter; s3obj_t::const_iterator iter;
for(iter = objects.begin(); objects.end() != iter; ++iter){ for(iter = objects.begin(); objects.end() != iter; ++iter){
if(OnlyNormalized && 0 != (*iter).second.normalname.length()){ if(OnlyNormalized && !iter->second.normalname.empty()){
continue; continue;
} }
std::string name = (*iter).first; std::string name = (*iter).first;
@ -250,7 +250,7 @@ bool S3ObjList::MakeHierarchizedList(s3obj_list_t& list, bool haveSlash)
// check hierarchized directory // check hierarchized directory
for(std::string::size_type pos = strtmp.find_last_of('/'); std::string::npos != pos; pos = strtmp.find_last_of('/')){ for(std::string::size_type pos = strtmp.find_last_of('/'); std::string::npos != pos; pos = strtmp.find_last_of('/')){
strtmp.erase(pos); strtmp.erase(pos);
if(0 == strtmp.length() || "/" == strtmp){ if(strtmp.empty() || "/" == strtmp){
break; break;
} }
if(h_map.end() == h_map.find(strtmp)){ if(h_map.end() == h_map.find(strtmp)){