1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-14 04:07:09 +00:00

Use '?' for unprintable characters

This commit is contained in:
SquidDev
2017-05-02 13:24:42 +01:00
parent c190ec5147
commit 2fef772f3d

View File

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