Write Unicode symbols instead of escaping them

This commit is contained in:
moandji.ezana 2015-07-14 22:29:54 +02:00
parent c90d4e1e71
commit 97e0133450
2 changed files with 8 additions and 3 deletions

View file

@ -113,6 +113,7 @@ class StringConverter implements ValueConverter, ValueWriter {
int codePoint = in.codePointAt(i);
if (codePoint < specialCharacterEscapes.length && specialCharacterEscapes[codePoint] != null) {
context.write(specialCharacterEscapes[codePoint]);
/*
} else if (codePoint > 0x1f && codePoint < 0x7f) {
context.write(Character.toChars(codePoint));
} else if (codePoint <= 0xFFFF) {
@ -122,6 +123,10 @@ class StringConverter implements ValueConverter, ValueWriter {
// Skip the low surrogate, which will be the next in the code point sequence.
i++;
}
*/
} else {
context.write(in.charAt(i));
}
}
}

View file

@ -289,12 +289,12 @@ public class TomlWriterTest {
}
Utf8Test utf8Test = new Utf8Test();
utf8Test.input = " é foo \b \t \n \f \r \" \\ ";
assertEquals("input = \" \\u00E9 foo \\u20AC \\b \\t \\n \\f \\r \\\" \\\\ \"\n", new TomlWriter().write(utf8Test));
utf8Test.input = " é foo \u20AC \b \t \n \f \r \" \\ ";
assertEquals("input = \" é foo € \\b \\t \\n \\f \\r \\\" \\\\ \"\n", new TomlWriter().write(utf8Test));
// Check unicode code points greater than 0XFFFF
utf8Test.input = " \uD801\uDC28 \uD840\uDC0B ";
assertEquals("input = \" \\U00010428 \\U0002000B \"\n", new TomlWriter().write(utf8Test));
assertEquals("input = \" 𐐨 𠀋 \"\n", new TomlWriter().write(utf8Test));
}
@Test