mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-05 17:45:52 +01:00
ResXmlEncoders: replaced findNonPositionedSubstitutions() by more flexible findSubstitutions().
Also rewritten some bits.
This commit is contained in:
parent
997df5cfc5
commit
68f97980eb
@ -16,6 +16,8 @@
|
||||
|
||||
package brut.androlib.res.xml;
|
||||
|
||||
import brut.util.Duo;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -135,11 +137,11 @@ public final class ResXmlEncoders {
|
||||
}
|
||||
|
||||
public static boolean hasMultipleNonPositionalSubstitutions(String str) {
|
||||
return findNonPositionalSubstitutions(str, 2).size() > 1;
|
||||
return findSubstitutions(str, 2).m1.size() > 1;
|
||||
}
|
||||
|
||||
public static String enumerateNonPositionalSubstitutions(String str) {
|
||||
List<Integer> subs = findNonPositionalSubstitutions(str, -1);
|
||||
List<Integer> subs = findSubstitutions(str, -1).m1;
|
||||
if (subs.size() < 2) {
|
||||
return str;
|
||||
}
|
||||
@ -157,16 +159,21 @@ public final class ResXmlEncoders {
|
||||
}
|
||||
|
||||
/**
|
||||
* It searches for "%", but not "%%" nor "%(\d)+\$"
|
||||
* It returns a tuple of:
|
||||
* - a list of offsets of non positional substitutions. non-pos is defined as any "%" which isn't "%%" nor "%\d+\$"
|
||||
* - a list of offsets of positional substitutions
|
||||
*/
|
||||
private static List<Integer> findNonPositionalSubstitutions(String str,
|
||||
int max) {
|
||||
int pos = 0;
|
||||
private static Duo<List<Integer>, List<Integer>> findSubstitutions(String str, int nonPosMax) {
|
||||
if (nonPosMax == -1) {
|
||||
nonPosMax = Integer.MAX_VALUE;
|
||||
}
|
||||
int pos;
|
||||
int pos2 = 0;
|
||||
int count = 0;
|
||||
int length = str.length();
|
||||
List<Integer> ret = new ArrayList<Integer>();
|
||||
while ((pos2 = (pos = str.indexOf('%', pos2)) + 1) != 0) {
|
||||
List<Integer> nonPositional = new ArrayList<>();
|
||||
List<Integer> positional = new ArrayList<>();
|
||||
while ((pos = str.indexOf('%', pos2)) != -1) {
|
||||
pos2 = pos + 1;
|
||||
if (pos2 == length) {
|
||||
break;
|
||||
}
|
||||
@ -175,21 +182,20 @@ public final class ResXmlEncoders {
|
||||
continue;
|
||||
}
|
||||
if (c >= '0' && c <= '9' && pos2 < length) {
|
||||
do {
|
||||
c = str.charAt(pos2++);
|
||||
} while (c >= '0' && c <= '9' && pos2 < length);
|
||||
if (c == '$') {
|
||||
continue;
|
||||
}
|
||||
while ((c = str.charAt(pos2++)) >= '0' && c <= '9' && pos2 < length);
|
||||
if (c == '$') {
|
||||
positional.add(pos);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret.add(pos);
|
||||
if (max != -1 && ++count >= max) {
|
||||
nonPositional.add(pos);
|
||||
if (nonPositional.size() >= nonPosMax) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return new Duo<>(nonPositional, positional);
|
||||
}
|
||||
|
||||
private static boolean isPrintableChar(char c) {
|
||||
|
Loading…
Reference in New Issue
Block a user