diff options
author | Dianne Hackborn <hackbod@android.com> | 2011-01-29 23:01:20 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-01-29 23:01:20 -0800 |
commit | a30063d80c08434ac3c7316f338c6d54110449ab (patch) | |
tree | 6c59e04e7d9b961b49fccdfb139fe87baaa35855 | |
parent | 2107757dde0b3159119edcc9084fcb9a87985e88 (diff) | |
parent | 25eb04642cb5a72f59a274bbfc92f4f65c6c343e (diff) | |
download | frameworks_base-a30063d80c08434ac3c7316f338c6d54110449ab.zip frameworks_base-a30063d80c08434ac3c7316f338c6d54110449ab.tar.gz frameworks_base-a30063d80c08434ac3c7316f338c6d54110449ab.tar.bz2 |
am 25eb0464: Merge "Normalize output from aapt d"
* commit '25eb04642cb5a72f59a274bbfc92f4f65c6c343e':
Normalize output from aapt d
-rw-r--r-- | include/utils/ResourceTypes.h | 1 | ||||
-rw-r--r-- | libs/utils/ResourceTypes.cpp | 36 | ||||
-rw-r--r-- | tools/aapt/XMLNode.cpp | 6 |
3 files changed, 39 insertions, 4 deletions
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h index da86da4..ab7b973 100644 --- a/include/utils/ResourceTypes.h +++ b/include/utils/ResourceTypes.h @@ -1983,6 +1983,7 @@ public: #ifndef HAVE_ANDROID_OS void print(bool inclValues) const; + static String8 normalizeForOutput(const char* input); #endif private: diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp index 8345cc3..7fb7ae3 100644 --- a/libs/utils/ResourceTypes.cpp +++ b/libs/utils/ResourceTypes.cpp @@ -4038,6 +4038,38 @@ void print_complex(uint32_t complex, bool isFraction) } } +// Normalize a string for output +String8 ResTable::normalizeForOutput( const char *input ) +{ + String8 ret; + char buff[2]; + buff[1] = '\0'; + + while (*input != '\0') { + switch (*input) { + // All interesting characters are in the ASCII zone, so we are making our own lives + // easier by scanning the string one byte at a time. + case '\\': + ret += "\\\\"; + break; + case '\n': + ret += "\\n"; + break; + case '"': + ret += "\\\""; + break; + default: + buff[0] = *input; + ret += buff; + break; + } + + input++; + } + + return ret; +} + void ResTable::print_value(const Package* pkg, const Res_value& value) const { if (value.dataType == Res_value::TYPE_NULL) { @@ -4051,13 +4083,13 @@ void ResTable::print_value(const Package* pkg, const Res_value& value) const const char* str8 = pkg->header->values.string8At( value.data, &len); if (str8 != NULL) { - printf("(string8) \"%s\"\n", str8); + printf("(string8) \"%s\"\n", normalizeForOutput(str8).string()); } else { const char16_t* str16 = pkg->header->values.stringAt( value.data, &len); if (str16 != NULL) { printf("(string16) \"%s\"\n", - String8(str16, len).string()); + normalizeForOutput(String8(str16, len).string()).string()); } else { printf("(string) null\n"); } diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp index 8551b0f..c0d7427 100644 --- a/tools/aapt/XMLNode.cpp +++ b/tools/aapt/XMLNode.cpp @@ -451,13 +451,15 @@ void printXMLBlock(ResXMLTree* block) printf("=?0x%x", (int)value.data); } else if (value.dataType == Res_value::TYPE_STRING) { printf("=\"%s\"", - String8(block->getAttributeStringValue(i, &len)).string()); + ResTable::normalizeForOutput(String8(block->getAttributeStringValue(i, + &len)).string()).string()); } else { printf("=(type 0x%x)0x%x", (int)value.dataType, (int)value.data); } const char16_t* val = block->getAttributeStringValue(i, &len); if (val != NULL) { - printf(" (Raw: \"%s\")", String8(val).string()); + printf(" (Raw: \"%s\")", ResTable::normalizeForOutput(String8(val).string()). + string()); } printf("\n"); } |