mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +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 startIndex = matcher.start();
|
||||
int curIndex = matcher.end();
|
||||
Matcher openMatch = PATTERN_TEMPLATE_OPEN.matcher(pageContents);
|
||||
Matcher closeMatch = PATTERN_TEMPLATE_CLOSE.matcher(pageContents);
|
||||
|
||||
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++;
|
||||
} else if(PATTERN_TEMPLATE_CLOSE.matcher(pageContents).find(curIndex)) {
|
||||
curIndex = openMatch.end();
|
||||
} else if (closeFound) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue