Browse Source

add attribute parsing

pull/61/merge
Thodoris1999 6 years ago
parent
commit
546241e98f
  1. 12
      app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java
  2. 12
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java

12
app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java

@ -4,13 +4,19 @@ import androidx.annotation.NonNull;
public class BBTag {
private int start, end;
private String name;
private String name, attribute;
public BBTag(int start, String name) {
this.start = start;
this.name = name;
}
public BBTag(int start, String name, String attribute) {
this.start = start;
this.name = name;
this.attribute = attribute;
}
@NonNull
@Override
public String toString() {
@ -40,4 +46,8 @@ public class BBTag {
public void setName(String name) {
this.name = name;
}
public String getAttribute() {
return attribute;
}
}

12
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java

@ -74,7 +74,15 @@ public class BBParser {
LinkedList<BBTag> tags = new LinkedList<>();
Matcher bbMatcher = bbtagPattern.matcher(bb);
while (bbMatcher.find()) {
String name = bbMatcher.group(1);
String startTag = bbMatcher.group(1);
int separatorIndex = startTag.indexOf('=');
String name, attribute = null;
if (separatorIndex > 0) {
attribute = startTag.substring(separatorIndex);
name = startTag.substring(0, separatorIndex);
} else
name = startTag;
if (name.startsWith("/")) {
//closing tag
name = name.substring(1);
@ -87,7 +95,7 @@ public class BBParser {
continue;
}
if (isSupported(name))
tags.add(new BBTag(bbMatcher.start(), name));
tags.add(new BBTag(bbMatcher.start(), name, attribute));
}
// remove parsed tags with no end tag
for (BBTag bbTag : tags)

Loading…
Cancel
Save