forked from runelite/runelite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request runelite#4357 from Nightfirecat/fix-remove-tags
text: Fix removeTags for isolated < and > chars
- Loading branch information
Showing
2 changed files
with
7 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2018, Joshua Filby <[email protected]> | ||
* Copyright (c) 2018, Jordan Atwood <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -24,11 +25,14 @@ | |
*/ | ||
package net.runelite.client.util; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* A set of utilities to use when dealing with text. | ||
*/ | ||
public class Text | ||
{ | ||
private static final Pattern TAG_REGEXP = Pattern.compile("<[^>]*>"); | ||
|
||
/** | ||
* Removes all tags from the given `str`. | ||
|
@@ -38,28 +42,7 @@ public class Text | |
*/ | ||
public static String removeTags(String str) | ||
{ | ||
StringBuilder builder = new StringBuilder(str.length()); | ||
boolean inTag = false; | ||
|
||
for (int i = 0; i < str.length(); i++) | ||
{ | ||
char currentChar = str.charAt(i); | ||
|
||
if (currentChar == '<') | ||
{ | ||
inTag = true; | ||
} | ||
else if (currentChar == '>') | ||
{ | ||
inTag = false; | ||
} | ||
else if (!inTag) | ||
{ | ||
builder.append(currentChar); | ||
} | ||
} | ||
|
||
return builder.toString(); | ||
return TAG_REGEXP.matcher(str).replaceAll(""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters