Add support for 4 non-positional attributes

- adds tests
 - fixes #1611
This commit is contained in:
Connor Tumbleson 2017-09-19 17:02:42 -04:00
parent f0f87c844e
commit bc00cce9bd
2 changed files with 12 additions and 2 deletions

View File

@ -143,12 +143,12 @@ public final class ResXmlEncoders {
}
public static boolean hasMultipleNonPositionalSubstitutions(String str) {
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 3);
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 4);
return ! tuple.m1.isEmpty() && tuple.m1.size() + tuple.m2.size() > 1;
}
public static String enumerateNonPositionalSubstitutionsIfRequired(String str) {
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 3);
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 4);
if (tuple.m1.isEmpty() || tuple.m1.size() + tuple.m2.size() < 2) {
return str;
}

View File

@ -51,6 +51,16 @@ public class PositionalEnumerationTest {
assertEquals(" %1$s, %2$s and %3$d other", enumerateArguments(" %1$s, %2$s and %3$d other"));
}
@Test
public void fourArgumentsTest() {
assertEquals("%1$s, %2$s, and %3$d other and %4$d.", enumerateArguments("%s, %s, and %d other and %d."));
}
@Test
public void fourPositionalArgumentsTest() {
assertEquals(" %1$s, %2$s and %3$d other and %4$d.", enumerateArguments(" %1$s, %2$s and %3$d other and %4$d."));
}
private String enumerateArguments(String value) {
return ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(value);
}