cache: Strip tags from java names
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user