aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSundong Ahn <sundongahn@google.com>2022-03-24 07:45:06 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-03-24 07:45:06 +0000
commite1c10f6e5b1f54bbb362b8e114d34e7b495a7286 (patch)
tree781fa47dfe3aade2f418cef5c034d03f032e4112
parentae8e8a1a6294255ec4e4d2f81d0f93b180ffd698 (diff)
parent974af37e1db6ce4a543c34137db3009822c5777b (diff)
downloadxsdc-e1c10f6e5b1f54bbb362b8e114d34e7b495a7286.tar.gz
Support multiple whitespace characters am: bf3bd35ef8 am: 974af37e1d
Original change: https://android-review.googlesource.com/c/platform/system/tools/xsdc/+/2038983 Change-Id: Ie45394abc6f98a17d28117eaf2a17a8406bdb444
-rw-r--r--src/com/android/xsdc/cpp/CppCodeGenerator.java1
-rw-r--r--src/com/android/xsdc/cpp/CppSimpleType.java13
-rw-r--r--tests/resources/attr_group_simple.xml3
3 files changed, 8 insertions, 9 deletions
diff --git a/src/com/android/xsdc/cpp/CppCodeGenerator.java b/src/com/android/xsdc/cpp/CppCodeGenerator.java
index 272a296..e470216 100644
--- a/src/com/android/xsdc/cpp/CppCodeGenerator.java
+++ b/src/com/android/xsdc/cpp/CppCodeGenerator.java
@@ -154,6 +154,7 @@ public class CppCodeGenerator {
parserHeaderFile.printf("#include <optional>\n");
parserHeaderFile.printf("#include <string>\n");
parserHeaderFile.printf("#include <vector>\n");
+ parserHeaderFile.printf("#include <sstream>\n");
if (writer) {
parserHeaderFile.printf("#include <iostream>\n");
}
diff --git a/src/com/android/xsdc/cpp/CppSimpleType.java b/src/com/android/xsdc/cpp/CppSimpleType.java
index 282855f..d063ebe 100644
--- a/src/com/android/xsdc/cpp/CppSimpleType.java
+++ b/src/com/android/xsdc/cpp/CppSimpleType.java
@@ -63,15 +63,12 @@ class CppSimpleType implements CppType {
if (list) {
expression.append(
String.format("%s value;\n", getName()));
- expression.append(String.format("{\nint base = 0;\n"
- + "int found;\n"
- + "while(true) {\n"
- + "found = raw.find_first_of(\" \", base);\n"
- + "value.push_back(%s);\n"
- + "if (found == raw.npos) break;\n"
- + "base = found + 1;\n"
+ expression.append(String.format("{\n"
+ + "std::istringstream stream(raw);\n"
+ + "for(std::string str; stream >> str; ) {\n"
+ + " value.push_back(%s);\n"
+ "}\n",
- String.format(rawParsingExpression, "raw.substr(base, found - base)")));
+ String.format(rawParsingExpression, "str")));
expression.append("}\n");
} else {
expression.append(
diff --git a/tests/resources/attr_group_simple.xml b/tests/resources/attr_group_simple.xml
index 0a14222..fa400f9 100644
--- a/tests/resources/attr_group_simple.xml
+++ b/tests/resources/attr_group_simple.xml
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Student State="CA" city="Mountain View" road="Street 101" list="1 2 3">
+<Student State="CA" city="Mountain View" road="Street 101" list="1 2
+ 3">
<Name>Jun</Name>
</Student>