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.
- Loading branch information
Showing
1 changed file
with
29 additions
and
1 deletion.
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) 2017, Adam <[email protected]> | ||
* Copyright (c) 2018, Joshua Filby <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -53,7 +54,8 @@ public String name(String name, int id) | |
|
||
private static String sanitize(String in) | ||
{ | ||
String s = in.toUpperCase() | ||
String s = removeTags(in) | ||
.toUpperCase() | ||
.replace(' ', '_') | ||
.replaceAll("[^a-zA-Z0-9_]", ""); | ||
if (s.isEmpty()) | ||
|
@@ -69,4 +71,30 @@ private static String sanitize(String in) | |
return s; | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
} |