--- src/org/linuxsampler/lscp/Parser.java (revision 3905) +++ src/org/linuxsampler/lscp/Parser.java (working copy) @@ -570,9 +570,11 @@ */ public static String toExtendedEscapeSequence(String escapedString) { + byte[] byteString = escapedString.getBytes(java.nio.charset.StandardCharsets.UTF_8); + StringBuffer sb = new StringBuffer(); - for(int i = 0; i < escapedString.length(); i++) { - char c = escapedString.charAt(i); + for(int i = 0; i < byteString.length; i++) { + char c = (char)(byteString[i] & 0xFF); if(c == '`') sb.append("\\x60"); else if(c < ' ' || c > '~') sb.append(toEscapeString(c)); @@ -617,7 +619,8 @@ public static String toNonEscapedString(Object obj) { String s = obj.toString(); - StringBuffer sb = new StringBuffer(); + byte[] sb = new byte[s.length() + 1]; + int j = 0; for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(c == '\\') { @@ -626,34 +629,34 @@ break; } char c2 = s.charAt(++i); - if(c2 == '\'') sb.append('\''); - else if(c2 == '"') sb.append('"'); - else if(c2 == '\\') sb.append('\\'); - else if(c2 == 'r') sb.append('\r'); - else if(c2 == 'n') sb.append('\n'); - else if(c2 == 'f') sb.append('\f'); - else if(c2 == 't') sb.append('\t'); - else if(c2 == 'v') sb.append((char)0x0B); + if (c2 == '\'') sb[j++] = '\''; + else if(c2 == '"') sb[j++] = '"'; + else if(c2 == '\\') sb[j++] = '\\'; + else if(c2 == 'r') sb[j++] = '\r'; + else if(c2 == 'n') sb[j++] = '\n'; + else if(c2 == 'f') sb[j++] = '\f'; + else if(c2 == 't') sb[j++] = '\t'; + else if(c2 == 'v') sb[j++] = (char)0x0B; else if(c2 == 'x') { - Character ch = getHexEscapeSequence(s, i + 1); - if(ch != null) sb.append(ch.charValue()); + byte ch = getHexEscapeSequence(s, i + 1); + if(ch != 0) sb[j++] = ch; i += 2; } else if(c2 >= '0' && c2 <= '9') { - Character ch = getOctEscapeSequence(s, i); - if(ch != null) sb.append(ch.charValue()); + byte ch = getOctEscapeSequence(s, i); + if(ch != 0) sb[j++] = ch; i += 2; } else Client.getLogger().info("Unknown escape sequence \\" + c2); } else { - sb.append(c); + sb[j++] = (byte)c; } } - - return sb.toString(); + sb[j] = 0; + return new String(sb, java.nio.charset.StandardCharsets.UTF_8); } - private static Character + private static byte getHexEscapeSequence(String s, int index) { - Character c = null; + byte c = 0; if(index + 1 >= s.length()) { Client.getLogger().info("Broken escape sequence"); @@ -660,15 +663,15 @@ return c; } - try { c = (char)Integer.parseInt(s.substring(index, index + 2), 16); } + try { c = (byte)Integer.parseInt(s.substring(index, index + 2), 16); } catch(Exception x) { Client.getLogger().info("Broken escape sequence!"); } return c; } - private static Character + private static byte getOctEscapeSequence(String s, int index) { - Character c = null; + byte c = 0; if(index + 2 >= s.length()) { Client.getLogger().info("Broken escape sequence"); @@ -675,7 +678,7 @@ return c; } - try { c = (char)Integer.parseInt(s.substring(index, index + 3), 8); } + try { c = (byte)Integer.parseInt(s.substring(index, index + 3), 8); } catch(Exception x) { Client.getLogger().info("Broken escape sequence!"); } return c;