Merge "Remove the weird range variants of String8::toLower() and String8::toUpper()." am: 561209ee66 am: 7e7ff3635d
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1670567 Change-Id: I397edfff4cd96c30aba03c5960be5473bb19333b
This commit is contained in:
commit
685c0c9a7f
2 changed files with 10 additions and 34 deletions
|
|
@ -415,50 +415,28 @@ bool String8::removeAll(const char* other) {
|
||||||
|
|
||||||
void String8::toLower()
|
void String8::toLower()
|
||||||
{
|
{
|
||||||
toLower(0, size());
|
const size_t length = size();
|
||||||
}
|
if (length == 0) return;
|
||||||
|
|
||||||
void String8::toLower(size_t start, size_t length)
|
char* buf = lockBuffer(length);
|
||||||
{
|
for (size_t i = length; i > 0; --i) {
|
||||||
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) {
|
|
||||||
*buf = static_cast<char>(tolower(*buf));
|
*buf = static_cast<char>(tolower(*buf));
|
||||||
buf++;
|
buf++;
|
||||||
length--;
|
|
||||||
}
|
}
|
||||||
unlockBuffer(len);
|
unlockBuffer(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String8::toUpper()
|
void String8::toUpper()
|
||||||
{
|
{
|
||||||
toUpper(0, size());
|
const size_t length = size();
|
||||||
}
|
if (length == 0) return;
|
||||||
|
|
||||||
void String8::toUpper(size_t start, size_t length)
|
char* buf = lockBuffer(length);
|
||||||
{
|
for (size_t i = length; i > 0; --i) {
|
||||||
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) {
|
|
||||||
*buf = static_cast<char>(toupper(*buf));
|
*buf = static_cast<char>(toupper(*buf));
|
||||||
buf++;
|
buf++;
|
||||||
length--;
|
|
||||||
}
|
}
|
||||||
unlockBuffer(len);
|
unlockBuffer(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,7 @@ public:
|
||||||
bool removeAll(const char* other);
|
bool removeAll(const char* other);
|
||||||
|
|
||||||
void toLower();
|
void toLower();
|
||||||
void toLower(size_t start, size_t numChars);
|
|
||||||
void toUpper();
|
void toUpper();
|
||||||
void toUpper(size_t start, size_t numChars);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue