Use '?' for unprintable characters

This commit is contained in:
SquidDev 2017-05-02 13:24:42 +01:00
parent c190ec5147
commit 2fef772f3d
1 changed files with 7 additions and 3 deletions

View File

@ -4,15 +4,19 @@ public class StringUtil
{
public static String normaliseLabel( String label )
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < label.length() && builder.length() < 32; i++)
int length = Math.min( 32, label.length() );
StringBuilder builder = new StringBuilder( length );
for (int i = 0; i < length; i++)
{
char c = label.charAt( i );
if( (c >= ' ' && c <= '~') || (c >= 161 && c <= 172) || (c >= 174 && c <= 255) )
{
builder.append( c );
}
else
{
builder.append( '?' );
}
}
return builder.toString();