Now one non positional substitution and one positional is detected as "multiple non positional".

This commit is contained in:
Ryszard Wiśniewski 2013-05-11 20:03:03 +02:00
parent 14f26474e6
commit d9cac893f9
2 changed files with 8 additions and 5 deletions

View File

@ -137,14 +137,16 @@ public final class ResXmlEncoders {
}
public static boolean hasMultipleNonPositionalSubstitutions(String str) {
return findSubstitutions(str, 2).m1.size() > 1;
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 2);
return ! tuple.m1.isEmpty() && tuple.m1.size() + tuple.m2.size() > 1;
}
public static String enumerateNonPositionalSubstitutionsIfRequired(String str) {
List<Integer> subs = findSubstitutions(str, -1).m1;
if (subs.size() < 2) {
return str;
}
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 2);
if (tuple.m1.isEmpty() || tuple.m1.size() + tuple.m2.size() < 2) {
return str;
}
List<Integer> subs = tuple.m1;
StringBuilder out = new StringBuilder();
int pos = 0;

View File

@ -24,4 +24,5 @@ bar"</string>
<string name="test_string22" formatted="false">%02d foo %01d</string>
<string name="test_string23" formatted="false">%d foo %1</string>
<string name="test_string24" formatted="false">%1% foo %2%</string>
<string name="test_string25" formatted="false">foo %s bar %2$s baz</string>
</resources>