From c190ec51475f534feb4a021f77b7da2f38e6cee3 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 2 May 2017 00:12:58 +0100 Subject: [PATCH] Do not limit labels to the ASCII range. This should accept all printable characters that ComputerCraft can handle. --- .../computercraft/shared/util/StringUtil.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/util/StringUtil.java b/src/main/java/dan200/computercraft/shared/util/StringUtil.java index 7372e4575..a9366c111 100644 --- a/src/main/java/dan200/computercraft/shared/util/StringUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/StringUtil.java @@ -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(); } }