diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-07-16 00:14:38 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-07-16 00:14:38 -0700 |
commit | 9e2d6e976b114f42142ba74a3c902b9c073c5629 (patch) | |
tree | 8f2ac5fea3363624a9b51871524b3e711263bdac | |
parent | 8849c6f648cf979b04a844a28ff3d0c7181e09b0 (diff) | |
parent | 0a128e3cbef25e17aa7280928e682801041fa55f (diff) | |
download | frameworks_native-9e2d6e976b114f42142ba74a3c902b9c073c5629.zip frameworks_native-9e2d6e976b114f42142ba74a3c902b9c073c5629.tar.gz frameworks_native-9e2d6e976b114f42142ba74a3c902b9c073c5629.tar.bz2 |
Merge "Fix bug with phantom input windows." into gingerbread
-rw-r--r-- | include/utils/String8.h | 2 | ||||
-rw-r--r-- | libs/utils/String8.cpp | 36 |
2 files changed, 31 insertions, 7 deletions
diff --git a/include/utils/String8.h b/include/utils/String8.h index c4b18a4..0b18fe3 100644 --- a/include/utils/String8.h +++ b/include/utils/String8.h @@ -171,6 +171,8 @@ public: status_t append(const char* other); status_t append(const char* other, size_t numChars); + status_t appendFormat(const char* fmt, ...); + // Note that this function takes O(N) time to calculate the value. // No cache value is stored. size_t getUtf32Length() const; diff --git a/libs/utils/String8.cpp b/libs/utils/String8.cpp index 82776f4..1c4f80c 100644 --- a/libs/utils/String8.cpp +++ b/libs/utils/String8.cpp @@ -372,6 +372,27 @@ status_t String8::append(const char* other, size_t otherLen) return real_append(other, otherLen); } +status_t String8::appendFormat(const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + int result = NO_ERROR; + int n = vsnprintf(NULL, 0, fmt, ap); + if (n != 0) { + size_t oldLength = length(); + char* buf = lockBuffer(oldLength + n); + if (buf) { + vsnprintf(buf + oldLength, n + 1, fmt, ap); + } else { + result = NO_MEMORY; + } + } + + va_end(ap); + return result; +} + status_t String8::real_append(const char* other, size_t otherLen) { const size_t myLen = bytes(); @@ -411,15 +432,16 @@ status_t String8::unlockBuffer(size_t size) if (size != this->size()) { SharedBuffer* buf = SharedBuffer::bufferFromData(mString) ->editResize(size+1); - if (buf) { - char* str = (char*)buf->data(); - str[size] = 0; - mString = str; - return NO_ERROR; + if (! buf) { + return NO_MEMORY; } + + char* str = (char*)buf->data(); + str[size] = 0; + mString = str; } - - return NO_MEMORY; + + return NO_ERROR; } ssize_t String8::find(const char* other, size_t start) const |