From 8c3f31f022f7e094fd227ef0c2987e0846cb3e43 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Wed, 7 Sep 2016 13:45:13 -0700 Subject: AAPT2: Fix issue with styled string indices Styled strings use spans to denote which part is styled (, , etc). Spans are simply a range of indices into the original string. In Java, we use String and its internal representation, meaning we must encode the indices using UTF16 lengths. When the internal AAPT2 representation of strings switched to UTF8, the indices also began to index into the UTF8 string. This change reverts the indices to use UTF16 lengths. Bug:31170115 Change-Id: I07b8b5b67d2542c7e0a855b601cdbd3ac4ebffb0 --- tools/aapt2/ResourceParser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/aapt2/ResourceParser.cpp') diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index 32e5cfd573bc..c430c4637899 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -152,7 +152,7 @@ bool ResourceParser::flattenXmlSubtree(xml::XmlPullParser* parser, std::string* break; } - spanStack.back().lastChar = builder.str().size() - 1; + spanStack.back().lastChar = builder.utf16Len() - 1; outStyleString->spans.push_back(spanStack.back()); spanStack.pop_back(); @@ -185,12 +185,12 @@ bool ResourceParser::flattenXmlSubtree(xml::XmlPullParser* parser, std::string* spanName += attrIter->value; } - if (builder.str().size() > std::numeric_limits::max()) { + if (builder.utf16Len() > std::numeric_limits::max()) { mDiag->error(DiagMessage(mSource.withLine(parser->getLineNumber())) << "style string '" << builder.str() << "' is too long"); error = true; } else { - spanStack.push_back(Span{ spanName, static_cast(builder.str().size()) }); + spanStack.push_back(Span{ spanName, static_cast(builder.utf16Len()) }); } } else if (event == xml::XmlPullParser::Event::kComment) { -- cgit v1.2.3-59-g8ed1b