mirror of
https://github.com/revanced/Apktool.git
synced 2024-11-11 15:09:24 +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.startTag(null, "item");
|
||||||
serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
|
serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
|
||||||
if (ResXmlEncoders.hasMultipleNonPositionalSubstitutions(rawValue
|
serializer.text(ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(item.encodeAsResXmlValue()));
|
||||||
.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.endTag(null, "item");
|
serializer.endTag(null, "item");
|
||||||
}
|
}
|
||||||
serializer.endTag(null, "plurals");
|
serializer.endTag(null, "plurals");
|
||||||
|
@ -54,44 +54,13 @@ public abstract class ResScalarValue extends ResValue implements
|
|||||||
if (mRawValue != null) {
|
if (mRawValue != null) {
|
||||||
return mRawValue;
|
return mRawValue;
|
||||||
}
|
}
|
||||||
return encodeAsResXmlValueExt().replace("@android:", "@*android:");
|
return encodeAsResXml().replace("@android:", "@*android:");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String encodeAsResXmlNonEscapedItemValue() throws AndrolibException {
|
public String encodeAsResXmlNonEscapedItemValue() throws AndrolibException {
|
||||||
return encodeAsResXmlValue().replace("@android:", "@*android:").replace("&", "&").replace("<","<");
|
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
|
@Override
|
||||||
public void serializeToResValuesXml(XmlSerializer serializer,
|
public void serializeToResValuesXml(XmlSerializer serializer,
|
||||||
ResResource res) throws IOException, AndrolibException {
|
ResResource res) throws IOException, AndrolibException {
|
||||||
|
@ -43,7 +43,7 @@ public class ResStringValue extends ResScalarValue {
|
|||||||
@Override
|
@Override
|
||||||
public String encodeAsResXmlItemValue() {
|
public String encodeAsResXmlItemValue() {
|
||||||
return ResXmlEncoders
|
return ResXmlEncoders
|
||||||
.enumerateNonPositionalSubstitutions(ResXmlEncoders
|
.enumerateNonPositionalSubstitutionsIfRequired(ResXmlEncoders
|
||||||
.encodeAsXmlValue(mRawValue));
|
.encodeAsXmlValue(mRawValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ public final class ResXmlEncoders {
|
|||||||
return findSubstitutions(str, 2).m1.size() > 1;
|
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;
|
List<Integer> subs = findSubstitutions(str, -1).m1;
|
||||||
if (subs.size() < 2) {
|
if (subs.size() < 2) {
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user