summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceUtils.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2019-03-06 15:06:49 -0800
committerRyan Mitchell <rtmitchell@google.com>2019-03-06 15:06:49 -0800
commit1d358ff5bb59f56ab19aa31d6afcf82c46b7c7bc (patch)
tree5d06705d5d234da3899fc21c71a024e6f2592b5b /tools/aapt2/ResourceUtils.cpp
parentf163c2111a72694f676f632762521376a6e80919 (diff)
Fix aapt2 whitespace diffs from aapt(1)
CDATA blocks were being processed differently in aapt2 so this change fixes aapt2 to not treat cdata blocks differently and still trime whitespace. Also, aapt did not process escapes when compiling xml files. This change removes over-processing of xml text nodes. All test strings are what aapt(1) would output. Test: aapt2_tests Bug: 124470332 Change-Id: I90ee0c1e5e9208f8a5c60cee93e3ba02712c9b2c
Diffstat (limited to 'tools/aapt2/ResourceUtils.cpp')
-rw-r--r--tools/aapt2/ResourceUtils.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index ffc1a92a88b0..f0e4d9e7ce8c 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -845,20 +845,16 @@ StringBuilder::StringBuilder(bool preserve_spaces)
: preserve_spaces_(preserve_spaces), quote_(preserve_spaces) {
}
-StringBuilder& StringBuilder::AppendText(const std::string& text, bool preserve_spaces) {
+StringBuilder& StringBuilder::AppendText(const std::string& text) {
if (!error_.empty()) {
return *this;
}
- // Enable preserving spaces if it is enabled for this append or the StringBuilder was constructed
- // to preserve spaces
- preserve_spaces = (preserve_spaces) ? preserve_spaces : preserve_spaces_;
-
const size_t previous_len = xml_string_.text.size();
Utf8Iterator iter(text);
while (iter.HasNext()) {
char32_t codepoint = iter.Next();
- if (!preserve_spaces && !quote_ && codepoint != kNonBreakingSpace && iswspace(codepoint)) {
+ if (!preserve_spaces_ && !quote_ && codepoint != kNonBreakingSpace && iswspace(codepoint)) {
if (!last_codepoint_was_space_) {
// Emit a space if it's the first.
xml_string_.text += ' ';
@@ -906,11 +902,11 @@ StringBuilder& StringBuilder::AppendText(const std::string& text, bool preserve_
break;
}
}
- } else if (!preserve_spaces && codepoint == U'"') {
+ } else if (!preserve_spaces_ && codepoint == U'"') {
// Only toggle the quote state when we are not preserving spaces.
quote_ = !quote_;
- } else if (!preserve_spaces && !quote_ && codepoint == U'\'') {
+ } else if (!preserve_spaces_ && !quote_ && codepoint == U'\'') {
// This should be escaped when we are not preserving spaces
error_ = StringPrintf("unescaped apostrophe in string\n\"%s\"", text.c_str());
return *this;