diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/ImStyleParser.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/ImStyleParser.java b/src/main/java/de/pixart/messenger/utils/ImStyleParser.java index 9f008d76c..118f3179f 100644 --- a/src/main/java/de/pixart/messenger/utils/ImStyleParser.java +++ b/src/main/java/de/pixart/messenger/utils/ImStyleParser.java @@ -34,10 +34,12 @@ import java.util.Arrays; import java.util.List; public class ImStyleParser { + private final static List<Character> KEYWORDS = Arrays.asList('*', '_', '~', '`'); private final static List<Character> NO_SUB_PARSING_KEYWORDS = Arrays.asList('`'); private final static List<Character> BLOCK_KEYWORDS = Arrays.asList('`'); private final static boolean ALLOW_EMPTY = false; + private final static boolean PARSE_HIGHER_ORDER_END = true; public static List<Style> parse(CharSequence text) { return parse(text, 0, text.length() - 1); @@ -86,6 +88,28 @@ public class ImStyleParser { for (int i = start; i <= end; ++i) { char c = text.charAt(i); if (c == needle && !Character.isWhitespace(text.charAt(i - 1))) { + if (!PARSE_HIGHER_ORDER_END || followedByWhitespace(text, i, end)) { + return i; + } else { + int higherOrder = seekHigherOrderEndWithoutNewBeginning(text, needle, i + 1, end); + if (higherOrder != -1) { + return higherOrder; + } + return i; + } + } else if (c == '\n') { + return -1; + } + } + return -1; + } + + private static int seekHigherOrderEndWithoutNewBeginning(CharSequence text, char needle, int start, int end) { + for (int i = start; i <= end; ++i) { + char c = text.charAt(i); + if (c == needle && precededByWhiteSpace(text, i, start) && !followedByWhitespace(text, i, end)) { + return -1; // new beginning + } else if (c == needle && !Character.isWhitespace(text.charAt(i - 1)) && followedByWhitespace(text, i, end)) { return i; } else if (c == '\n') { return -1; |