mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-05 17:45:52 +01:00
Cleaned up the code related to multiple substitutions in xml strings.
This commit is contained in:
parent
e7ee8cb178
commit
14f26474e6
@ -55,21 +55,7 @@ public class ResPluralsValue extends ResBagValue implements
|
||||
|
||||
serializer.startTag(null, "item");
|
||||
serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
|
||||
if (ResXmlEncoders.hasMultipleNonPositionalSubstitutions(rawValue
|
||||
.encodeAsResXmlValue())) {
|
||||
serializer.text(item.encodeAsResXmlValueExt());
|
||||
} else {
|
||||
String recode = item.encodeAsResXmlValue();
|
||||
// Dirty, but working fix @miuirussia
|
||||
for (int j = 0; j < 10; j++) {
|
||||
recode = StringUtils.replace(
|
||||
recode,
|
||||
"%" + Integer.toString(j) + "$"
|
||||
+ Integer.toString(j) + "$",
|
||||
"%" + Integer.toString(j) + "$");
|
||||
}
|
||||
serializer.text(recode);
|
||||
}
|
||||
serializer.text(ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(item.encodeAsResXmlValue()));
|
||||
serializer.endTag(null, "item");
|
||||
}
|
||||
serializer.endTag(null, "plurals");
|
||||
|
@ -54,44 +54,13 @@ public abstract class ResScalarValue extends ResValue implements
|
||||
if (mRawValue != null) {
|
||||
return mRawValue;
|
||||
}
|
||||
return encodeAsResXmlValueExt().replace("@android:", "@*android:");
|
||||
return encodeAsResXml().replace("@android:", "@*android:");
|
||||
}
|
||||
|
||||
public String encodeAsResXmlNonEscapedItemValue() throws AndrolibException {
|
||||
return encodeAsResXmlValue().replace("@android:", "@*android:").replace("&", "&").replace("<","<");
|
||||
}
|
||||
|
||||
public String encodeAsResXmlValueExt() throws AndrolibException {
|
||||
String rawValue = mRawValue;
|
||||
if (rawValue != null) {
|
||||
if (ResXmlEncoders.hasMultipleNonPositionalSubstitutions(rawValue)) {
|
||||
int count = 1;
|
||||
StringBuilder result = new StringBuilder();
|
||||
String tmp1[] = rawValue.split("%%", -1);
|
||||
int tmp1_sz = tmp1.length;
|
||||
for (int i = 0; i < tmp1_sz; i++) {
|
||||
String cur1 = tmp1[i];
|
||||
String tmp2[] = cur1.split("%", -1);
|
||||
int tmp2_sz = tmp2.length;
|
||||
for (int j = 0; j < tmp2_sz; j++) {
|
||||
String cur2 = tmp2[j];
|
||||
result.append(cur2);
|
||||
if (j != (tmp2_sz - 1)) {
|
||||
result.append('%').append(count).append('$');
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (i != (tmp1_sz - 1)) {
|
||||
result.append("%%");
|
||||
}
|
||||
}
|
||||
rawValue = result.toString();
|
||||
}
|
||||
return rawValue;
|
||||
}
|
||||
return encodeAsResXml();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeToResValuesXml(XmlSerializer serializer,
|
||||
ResResource res) throws IOException, AndrolibException {
|
||||
|
@ -43,7 +43,7 @@ public class ResStringValue extends ResScalarValue {
|
||||
@Override
|
||||
public String encodeAsResXmlItemValue() {
|
||||
return ResXmlEncoders
|
||||
.enumerateNonPositionalSubstitutions(ResXmlEncoders
|
||||
.enumerateNonPositionalSubstitutionsIfRequired(ResXmlEncoders
|
||||
.encodeAsXmlValue(mRawValue));
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ public final class ResXmlEncoders {
|
||||
return findSubstitutions(str, 2).m1.size() > 1;
|
||||
}
|
||||
|
||||
public static String enumerateNonPositionalSubstitutions(String str) {
|
||||
public static String enumerateNonPositionalSubstitutionsIfRequired(String str) {
|
||||
List<Integer> subs = findSubstitutions(str, -1).m1;
|
||||
if (subs.size() < 2) {
|
||||
return str;
|
||||
|
Loading…
Reference in New Issue
Block a user