chore(android/engine): Tweak regex again

This commit is contained in:
Darcy Wong 2022-11-17 09:20:17 +07:00
parent dedc76f975
commit ab8562dc9d
2 changed files with 4 additions and 1 deletions

View file

@ -72,7 +72,8 @@ public class PackageProcessor {
public String getPackageID(File path) {
// Sometimes, downloading a kmp multiple times results in a filename with a suffix:
// " (#).kmp" or "-#.kmp" in the filename, so strip out the number
String filename = path.getName().toLowerCase().replaceAll("(\\s+\\(|-)\\d+\\)?.kmp$", ".kmp");
String filename = path.getName().toLowerCase().replaceAll(
"\\s*((\\(\\d+\\))|(-\\d+))\\.kmp$", ".kmp");
if(resourceRoot == null) {
throw new IllegalStateException("The PackageProcessor has not been initialized!");

View file

@ -245,10 +245,12 @@ public class PackageProcessorTest {
Assert.assertEquals(TEST_EN_CUSTOM_MODEL_NAME, PP.getPackageID(TEST_EN_CUSTOM_MODEL_KMP_FILE));
// Test trimming " (#)" from kmp name
Assert.assertEquals("khmer_angkor", PP.getPackageID(new File("khmer_angkor(10).kmp")));
Assert.assertEquals("khmer_angkor", PP.getPackageID(new File("khmer_angkor (10).kmp")));
// Test trimming "-#" from kmp name
Assert.assertEquals("khmer_angkor", PP.getPackageID(new File("khmer_angkor-10.kmp")));
Assert.assertEquals("khmer_angkor", PP.getPackageID(new File("khmer_angkor -10.kmp")));
}
@Test