Fix pseudolocalizer at end of string

The accent pseudolocalizer would incorrectly process
the byte after the end of the string, which would end
up inserting null characters into the resulting
output.

Change-Id: I5cdabd6b0272d94073f06e180b8cbe7abafa3888
diff --git a/tools/aapt2/compile/Pseudolocalizer.cpp b/tools/aapt2/compile/Pseudolocalizer.cpp
index eae52d7..767d746 100644
--- a/tools/aapt2/compile/Pseudolocalizer.cpp
+++ b/tools/aapt2/compile/Pseudolocalizer.cpp
@@ -280,13 +280,13 @@
             std::u16string chunk;
             bool end = false;
             chunk.append(&c, 1);
-            while (!end && i < I) {
+            while (!end && i + 1 < I) {
                 ++i;
                 c = s[i];
                 chunk.append(&c, 1);
                 if (isPossibleNormalPlaceholderEnd(c)) {
                     end = true;
-                } else if (c == 't') {
+                } else if (i + 1 < I && c == 't') {
                     ++i;
                     c = s[i];
                     chunk.append(&c, 1);
diff --git a/tools/aapt2/compile/Pseudolocalizer_test.cpp b/tools/aapt2/compile/Pseudolocalizer_test.cpp
index b0bc2c1..36c8896 100644
--- a/tools/aapt2/compile/Pseudolocalizer_test.cpp
+++ b/tools/aapt2/compile/Pseudolocalizer_test.cpp
@@ -69,7 +69,7 @@
 
     EXPECT_TRUE(simpleHelper("Battery %1d%%",
                              "[βåţţéŕý »%1d«%% one two]", Pseudolocalizer::Method::kAccent));
-
+    EXPECT_TRUE(simpleHelper("^1 %", "[^1 % one]", Pseudolocalizer::Method::kAccent));
     EXPECT_TRUE(compoundHelper("", "", "", "[]", Pseudolocalizer::Method::kAccent));
     EXPECT_TRUE(compoundHelper("Hello,", " world", "",
                                "[Ĥéļļö, ŵöŕļð one two]", Pseudolocalizer::Method::kAccent));