diff options
author | Shachar Shemesh <lingnu@gmail.com> | 2010-12-20 17:38:33 +0200 |
---|---|---|
committer | Alex Ray <aray@google.com> | 2013-07-30 13:56:55 -0700 |
commit | b69f49bab9502ddb0850280f2aea12fb34475777 (patch) | |
tree | c19984ab47ac05f303bd35048d417cd77557e87e /libs | |
parent | 8659f0be9a7cac99d55f58601d68c0c6da55af7b (diff) | |
download | system_core-b69f49bab9502ddb0850280f2aea12fb34475777.zip system_core-b69f49bab9502ddb0850280f2aea12fb34475777.tar.gz system_core-b69f49bab9502ddb0850280f2aea12fb34475777.tar.bz2 |
Normalize output from aapt d
Make the output from aapt dump --values resources and aapt dump xmltree normalized, so that it is unambigously displayed
regardless of the content of the strings.
Change-Id: Ia3bff36c4ee1e9a44f474534e154830948beabdf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/utils/ResourceTypes.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp index bbf5093..cae91ac 100644 --- a/libs/utils/ResourceTypes.cpp +++ b/libs/utils/ResourceTypes.cpp @@ -4141,6 +4141,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) { @@ -4154,13 +4186,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"); } |