diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java index f1583f98..868bd4c1 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java @@ -143,12 +143,12 @@ public final class ResXmlEncoders { } public static boolean hasMultipleNonPositionalSubstitutions(String str) { - Duo, List> tuple = findSubstitutions(str, 2); + Duo, List> tuple = findSubstitutions(str, 3); return ! tuple.m1.isEmpty() && tuple.m1.size() + tuple.m2.size() > 1; } public static String enumerateNonPositionalSubstitutionsIfRequired(String str) { - Duo, List> tuple = findSubstitutions(str, 2); + Duo, List> tuple = findSubstitutions(str, 3); if (tuple.m1.isEmpty() || tuple.m1.size() + tuple.m2.size() < 2) { return str; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java new file mode 100644 index 00000000..e16ef0a7 --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java @@ -0,0 +1,59 @@ +/** + * Copyright 2014 Ryszard Wiśniewski + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package brut.androlib; + +import brut.androlib.res.xml.ResXmlEncoders; +import org.junit.Test; +import java.util.logging.Logger; + +import static org.junit.Assert.assertEquals; + +/** + * @author Connor Tumbleson + */ +public class PositionalEnumerationTest { + + @Test + public void noArgumentsTest() { + assertEquals("test", enumerateArguments("test")); + } + + @Test + public void twoArgumentsTest() { + assertEquals("%1$s, %2$s, and 1 other.", enumerateArguments("%s, %s, and 1 other.")); + } + + @Test + public void twoPositionalArgumentsTest() { + assertEquals("%1$s, %2$s and 1 other", enumerateArguments("%1$s, %2$s and 1 other")); + } + + @Test + public void threeArgumentsTest() { + assertEquals("%1$s, %2$s, and %3$d other.", enumerateArguments("%s, %s, and %d other.")); + } + + @Test + public void threePositionalArgumentsTest() { + assertEquals(" %1$s, %2$s and %3$d other", enumerateArguments(" %1$s, %2$s and %3$d other")); + } + + private String enumerateArguments(String value) { + return ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(value); + } + + private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName()); +} \ No newline at end of file