From 546241e98f790fcd9b9d8b58f72acb360bd3aa84 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Mon, 22 Oct 2018 17:42:45 +0300 Subject: [PATCH] add attribute parsing --- app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java | 12 +++++++++++- .../java/gr/thmmy/mthmmy/utils/parsing/BBParser.java | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java b/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java index af8db970..77504761 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java +++ b/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; + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java index 89e177c5..e596d85f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java @@ -74,7 +74,15 @@ public class BBParser { LinkedList 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)