diff options
| author | 2010-02-24 07:52:27 -0800 | |
|---|---|---|
| committer | 2010-02-24 07:52:27 -0800 | |
| commit | f70c4cebccfda4b4b0d92a0773f6dfa10f3b9574 (patch) | |
| tree | 94292c242662550649e9dddeff8e61ec269b0108 | |
| parent | 30c205b6eab0d3700e936dddb8ec475a497809d4 (diff) | |
| parent | 9e333ab42c5ca09632f56cd5d8e5349e06a632b7 (diff) | |
Merge "Use UTF-8 strings to avoid duplicate caching, part 1"
| -rw-r--r-- | include/utils/ResourceTypes.h | 2 | ||||
| -rw-r--r-- | libs/utils/ResourceTypes.cpp | 45 |
2 files changed, 41 insertions, 6 deletions
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h index 13ea27e4db..cd657e8311 100644 --- a/include/utils/ResourceTypes.h +++ b/include/utils/ResourceTypes.h @@ -447,6 +447,8 @@ public: } const char16_t* stringAt(size_t idx, size_t* outLen) const; + const char* string8At(size_t idx, size_t* outLen) const; + const ResStringPool_span* styleAt(const ResStringPool_ref& ref) const; const ResStringPool_span* styleAt(size_t idx) const; diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp index e8bd5cf011..38600b9aee 100644 --- a/libs/utils/ResourceTypes.cpp +++ b/libs/utils/ResourceTypes.cpp @@ -497,6 +497,34 @@ const uint16_t* ResStringPool::stringAt(size_t idx, size_t* outLen) const return NULL; } +const char* ResStringPool::string8At(size_t idx, size_t* outLen) const +{ + if (mError == NO_ERROR && idx < mHeader->stringCount) { + const bool isUTF8 = (mHeader->flags&ResStringPool_header::UTF8_FLAG) != 0; + const uint32_t off = mEntries[idx]/(isUTF8?sizeof(char):sizeof(char16_t)); + if (off < (mStringPoolSize-1)) { + if (isUTF8) { + const uint8_t* strings = (uint8_t*)mStrings; + const uint8_t* str = strings+off; + DECODE_LENGTH(str, sizeof(uint8_t), *outLen) + size_t encLen; + DECODE_LENGTH(str, sizeof(uint8_t), encLen) + if ((uint32_t)(str+encLen-strings) < mStringPoolSize) { + return (const char*)str; + } else { + LOGW("Bad string block: string #%d extends to %d, past end at %d\n", + (int)idx, (int)(str+encLen-strings), (int)mStringPoolSize); + } + } + } else { + LOGW("Bad string block: string #%d entry is at %d, past end at %d\n", + (int)idx, (int)(off*sizeof(uint16_t)), + (int)(mStringPoolSize*sizeof(uint16_t))); + } + } + return NULL; +} + const ResStringPool_span* ResStringPool::styleAt(const ResStringPool_ref& ref) const { return styleAt(ref.index); @@ -4018,14 +4046,19 @@ void ResTable::print_value(const Package* pkg, const Res_value& value) const printf("(attribute) 0x%08x\n", value.data); } else if (value.dataType == Res_value::TYPE_STRING) { size_t len; - const char16_t* str = pkg->header->values.stringAt( + const char* str8 = pkg->header->values.string8At( value.data, &len); - if (str == NULL) { - printf("(string) null\n"); + if (str8 != NULL) { + printf("(string8) \"%s\"\n", str8); } else { - printf("(string%d) \"%s\"\n", - pkg->header->values.isUTF8()?8:16, - String8(str, len).string()); + const char16_t* str16 = pkg->header->values.stringAt( + value.data, &len); + if (str16 != NULL) { + printf("(string16) \"%s\"\n", + String8(str16, len).string()); + } else { + printf("(string) null\n"); + } } } else if (value.dataType == Res_value::TYPE_FLOAT) { printf("(float) %g\n", *(const float*)&value.data); |