Skip to content

Commit

Permalink
cache: Strip tags from java names
Browse files Browse the repository at this point in the history
  • Loading branch information
abextm committed May 14, 2018
1 parent 220add9 commit 7cc7260
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion cache/src/main/java/net/runelite/cache/util/Namer.java
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
Expand Down Expand Up @@ -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())
Expand All @@ -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();
}
}

0 comments on commit 7cc7260

Please sign in to comment.