cache: Strip tags from java names

This commit is contained in:
Max Weber
2018-05-14 03:26:38 -06:00
parent 220add92fd
commit 7cc726097f

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Joshua Filby <joshua@filby.me>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,7 +54,8 @@ public class Namer
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 @@ public class Namer
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();
}
}