text: actually fix remove levels properly

This commit is contained in:
ThatGamerBlue
2021-02-25 22:54:29 +00:00
parent a499d7f305
commit 7c00707fc0
2 changed files with 4 additions and 2 deletions

View File

@@ -88,16 +88,17 @@ public class Text
*/ */
public static String removeTags(String str, boolean removeLevels) public static String removeTags(String str, boolean removeLevels)
{ {
int strLen = str.length();
if (removeLevels) if (removeLevels)
{ {
int levelIdx = StringUtils.lastIndexOf(str, " (level"); int levelIdx = StringUtils.lastIndexOf(str, " (level");
if (levelIdx >= 0) if (levelIdx >= 0)
{ {
strLen = levelIdx + 1; str = str.substring(0, levelIdx);
} }
} }
int strLen = str.length();
int open, close; int open, close;
if ((open = StringUtils.indexOf(str, '<')) == -1 if ((open = StringUtils.indexOf(str, '<')) == -1
|| (close = StringUtils.indexOf(str, '>', open)) == -1) || (close = StringUtils.indexOf(str, '>', open)) == -1)

View File

@@ -41,6 +41,7 @@ public class TextTest
assertEquals("a < b", Text.removeTags("a < b")); assertEquals("a < b", Text.removeTags("a < b"));
assertEquals("Remove no tags", Text.removeTags("Remove no tags")); assertEquals("Remove no tags", Text.removeTags("Remove no tags"));
assertEquals("Zezima", Text.removeTags("<col=ffffff><img=2>Zezima<col=00ffff> (level-126)", true)); assertEquals("Zezima", Text.removeTags("<col=ffffff><img=2>Zezima<col=00ffff> (level-126)", true));
assertEquals("Zezima", Text.removeTags("Zezima (level-126)", true));
assertEquals("", Text.removeTags("<col=ffffff><img=2><col=00ffff> (level-126)", true)); assertEquals("", Text.removeTags("<col=ffffff><img=2><col=00ffff> (level-126)", true));
} }