mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 11:10:29 +00:00
Do not limit labels to the ASCII range.
This should accept all printable characters that ComputerCraft can handle.
This commit is contained in:
parent
b1efbdad95
commit
c190ec5147
@ -1,20 +1,20 @@
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class StringUtil
|
||||
{
|
||||
private static final Pattern INVALID_PATTERN = Pattern.compile( "[^ -~]" );
|
||||
|
||||
public static String normaliseLabel( String label )
|
||||
{
|
||||
label = INVALID_PATTERN.matcher( label ).replaceAll( "" );
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if( label.length() > 32 )
|
||||
for (int i = 0; i < label.length() && builder.length() < 32; i++)
|
||||
{
|
||||
label = label.substring( 0, 32 );
|
||||
char c = label.charAt( i );
|
||||
if( (c >= ' ' && c <= '~') || (c >= 161 && c <= 172) || (c >= 174 && c <= 255) )
|
||||
{
|
||||
builder.append( c );
|
||||
}
|
||||
}
|
||||
|
||||
return label;
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user