diff options
author | Elliott Hughes <enh@google.com> | 2021-04-12 18:51:22 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-04-12 18:51:22 +0000 |
commit | 561209ee664eeecd3e7c291d0e88b9730bec84be (patch) | |
tree | ba471504819b27d01f9b95ddbe63ee40736c3416 /libutils/String8.cpp | |
parent | 2a8b028c04bb970ca2172541ba77d8a6623b28b1 (diff) | |
parent | a858395f91d09ddedfaab4f3094000ac32f3d124 (diff) |
Merge "Remove the weird range variants of String8::toLower() and String8::toUpper()."
Diffstat (limited to 'libutils/String8.cpp')
-rw-r--r-- | libutils/String8.cpp | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/libutils/String8.cpp b/libutils/String8.cpp index 3dc2026d9..fad130b1b 100644 --- a/libutils/String8.cpp +++ b/libutils/String8.cpp @@ -415,50 +415,28 @@ bool String8::removeAll(const char* other) { void String8::toLower() { - toLower(0, size()); -} + const size_t length = size(); + if (length == 0) return; -void String8::toLower(size_t start, size_t length) -{ - const size_t len = size(); - if (start >= len) { - return; - } - if (start+length > len) { - length = len-start; - } - char* buf = lockBuffer(len); - buf += start; - while (length > 0) { + char* buf = lockBuffer(length); + for (size_t i = length; i > 0; --i) { *buf = static_cast<char>(tolower(*buf)); buf++; - length--; } - unlockBuffer(len); + unlockBuffer(length); } void String8::toUpper() { - toUpper(0, size()); -} + const size_t length = size(); + if (length == 0) return; -void String8::toUpper(size_t start, size_t length) -{ - const size_t len = size(); - if (start >= len) { - return; - } - if (start+length > len) { - length = len-start; - } - char* buf = lockBuffer(len); - buf += start; - while (length > 0) { + char* buf = lockBuffer(length); + for (size_t i = length; i > 0; --i) { *buf = static_cast<char>(toupper(*buf)); buf++; - length--; } - unlockBuffer(len); + unlockBuffer(length); } // --------------------------------------------------------------------------- |