summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Brown2014-06-06 21:30:15 -0500
committerJeff Brown2014-06-09 16:02:52 -0500
commit5ee915afe17b7190f992addc48cb53ed6371a68d (patch)
treeb9d17977eac672201411fbb01c17bc4f16464aa5 /libutils/String8.cpp
parent45e2756409bee6b766fd965bd945f9d42789fb33 (diff)
downloadplatform-system-core-5ee915afe17b7190f992addc48cb53ed6371a68d.tar.gz
platform-system-core-5ee915afe17b7190f992addc48cb53ed6371a68d.tar.xz
platform-system-core-5ee915afe17b7190f992addc48cb53ed6371a68d.zip
Add a couple of useful string functions.
Change-Id: I158f69917bab5f15482dd8f2b66b36a4cc0f11ad
Diffstat (limited to 'libutils/String8.cpp')
-rw-r--r--libutils/String8.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index 49340bbb7..9092cbc99 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -408,6 +408,30 @@ ssize_t String8::find(const char* other, size_t start) const
408 return p ? p-mString : -1; 408 return p ? p-mString : -1;
409} 409}
410 410
411bool String8::removeAll(const char* other) {
412 ssize_t index = find(other);
413 if (index < 0) return false;
414
415 char* buf = lockBuffer(size());
416 if (!buf) return false; // out of memory
417
418 size_t skip = strlen(other);
419 size_t len = size();
420 size_t tail = index;
421 while (size_t(index) < len) {
422 ssize_t next = find(other, index + skip);
423 if (next < 0) {
424 next = len;
425 }
426
427 memcpy(buf + tail, buf + index + skip, next - index - skip);
428 tail += next - index - skip;
429 index = next;
430 }
431 unlockBuffer(tail);
432 return true;
433}
434
411void String8::toLower() 435void String8::toLower()
412{ 436{
413 toLower(0, size()); 437 toLower(0, size());