AAPT2: Fix processing of quotes in XML

When processing attributes in XML, quotes can't be used to mark a
section as whitespace preserving, so the assumption should be that the
entire string is whitespace preserving, which makes quote characters
literals.

Bug: 62840718
Bug: 62840406
Test: make aapt2_tests
Change-Id: I4afff02148b5b8e78833abf1f323c2f5325d6155
diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp
index 9fde1b4..51a75d7 100644
--- a/tools/aapt2/util/Util.cpp
+++ b/tools/aapt2/util/Util.cpp
@@ -327,6 +327,9 @@
   return isspace(static_cast<char>(codepoint));
 }
 
+StringBuilder::StringBuilder(bool preserve_spaces) : preserve_spaces_(preserve_spaces) {
+}
+
 StringBuilder& StringBuilder::Append(const StringPiece& str) {
   if (!error_.empty()) {
     return *this;
@@ -372,14 +375,12 @@
       }
       last_char_was_escape_ = false;
 
-    } else if (codepoint == U'"') {
+    } else if (!preserve_spaces_ && codepoint == U'"') {
       if (!quote_ && trailing_space_) {
-        // We found an opening quote, and we have
-        // trailing space, so we should append that
+        // We found an opening quote, and we have trailing space, so we should append that
         // space now.
         if (trailing_space_) {
-          // We had trailing whitespace, so
-          // replace with a single space.
+          // We had trailing whitespace, so replace with a single space.
           if (!str_.empty()) {
             str_ += ' ';
           }
@@ -388,7 +389,7 @@
       }
       quote_ = !quote_;
 
-    } else if (codepoint == U'\'' && !quote_) {
+    } else if (!preserve_spaces_ && codepoint == U'\'' && !quote_) {
       // This should be escaped.
       error_ = "unescaped apostrophe";
       return *this;
@@ -405,7 +406,7 @@
       }
       last_char_was_escape_ = true;
     } else {
-      if (quote_) {
+      if (preserve_spaces_ || quote_) {
         // Quotes mean everything is taken, including whitespace.
         AppendCodepointToUtf8String(codepoint, &str_);
       } else {