mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Make template removal work properly
This commit is contained in:
parent
f941989c19
commit
6dae336522
1 changed files with 17 additions and 4 deletions
|
|
@ -46,14 +46,27 @@ public class TemplateRemoveModifier extends PageModifier {
|
||||||
int braceCount = 1;
|
int braceCount = 1;
|
||||||
int startIndex = matcher.start();
|
int startIndex = matcher.start();
|
||||||
int curIndex = matcher.end();
|
int curIndex = matcher.end();
|
||||||
|
Matcher openMatch = PATTERN_TEMPLATE_OPEN.matcher(pageContents);
|
||||||
|
Matcher closeMatch = PATTERN_TEMPLATE_CLOSE.matcher(pageContents);
|
||||||
|
|
||||||
while(curIndex < pageContents.length()) {
|
while(curIndex < pageContents.length()) {
|
||||||
if(PATTERN_TEMPLATE_OPEN.matcher(pageContents).find(curIndex)) {
|
boolean openFound = openMatch.find(curIndex);
|
||||||
|
boolean closeFound = closeMatch.find(curIndex);
|
||||||
|
|
||||||
|
if(openFound && (!closeFound || openMatch.start() < closeMatch.start())) {
|
||||||
braceCount++;
|
braceCount++;
|
||||||
} else if(PATTERN_TEMPLATE_CLOSE.matcher(pageContents).find(curIndex)) {
|
curIndex = openMatch.end();
|
||||||
|
} else if (closeFound) {
|
||||||
braceCount--;
|
braceCount--;
|
||||||
|
curIndex = closeMatch.end();
|
||||||
|
} else if (braceCount > 0) {
|
||||||
|
// The template never closes, so...remove nothing
|
||||||
|
curIndex = startIndex;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
curIndex++;
|
|
||||||
if(braceCount == 0) {
|
if (braceCount == 0) {
|
||||||
|
// The braces have all been closed!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue