Re-doing some of the code. Need to learn how to check for already escaped characters without re-writing a whole class.

This commit is contained in:
Connor Tumbleson 2012-07-12 10:39:18 -05:00
parent 97451619b8
commit f0c96c6ea5
2 changed files with 23 additions and 10 deletions

View File

@ -52,7 +52,7 @@ public abstract class ResScalarValue extends ResValue
if (mRawValue != null) { if (mRawValue != null) {
return mRawValue; return mRawValue;
} }
return encodeAsResXmlValueExt(); return encodeAsResXml();
} }
public String encodeAsResXmlValueExt() throws AndrolibException { public String encodeAsResXmlValueExt() throws AndrolibException {

View File

@ -156,25 +156,38 @@ public final class ResXmlEncoders {
return out.toString(); return out.toString();
} }
private static List<Integer> findNonPositionalSubstitutions(String str, /**
* It searches for "%", but not "%%" nor "%(\d)+\$"
*/
private static List<Integer> findNonPositionalSubstitutions(String str,
int max) { int max) {
int pos = 0; int pos = 0;
int pos2 = 0;
int count = 0; int count = 0;
int length = str.length(); int length = str.length();
List<Integer> ret = new ArrayList<Integer>(); List<Integer> ret = new ArrayList<Integer>();
while((pos = str.indexOf('%', pos)) != -1) { while((pos2 = (pos = str.indexOf('%', pos2)) + 1) != 0) {
if (pos + 1 == length) { if (pos2 == length) {
break; break;
} }
char c = str.charAt(pos + 1); char c = str.charAt(pos2++);
if (c >= 'a' && c <= 'z') { if (c == '%') {
continue;
}
if (c >= '0' && c <= '9' && pos2 < length) {
do {
c = str.charAt(pos2++);
} while (c >= '0' && c <= '9' && pos2 < length);
if (c == '$') {
continue;
}
}
ret.add(pos); ret.add(pos);
if (max != -1 && ++count >= max) { if (max != -1 && ++count >= max) {
break; break;
} }
} }
pos += 2;
}
return ret; return ret;
} }