Commit b5b298b7 authored by Christian Willms's avatar Christian Willms
Browse files

implemented proper unicode handling

parent 197fe737
......@@ -5,6 +5,8 @@ import java.lang.reflect.Array;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.dfki.lt.hfc.types.*;
import gnu.trove.list.array.TIntArrayList;
......@@ -1636,7 +1638,15 @@ public final class TupleStore {
sb.append("^^").append(XsdString.LONG_NAME);
}
token = sb.toString();
tuple.add(token);
Pattern p = Pattern.compile("\\\\u(\\p{XDigit}{4})");
Matcher m = p.matcher(token);
StringBuffer buf = new StringBuffer(token.length());
while(m.find()){
String ch = String.valueOf((char) Integer.parseInt(m.group(1), 16));
m.appendReplacement(buf, Matcher.quoteReplacement(ch));
}
m.appendTail(buf);
tuple.add(buf.toString());
return token;
}
......
# Hello foo
<test:a1> <test:value> "\u0048\u0065\u006C\u006C\u006F foo"^^<xsd:string> .
# Hello foo!
<test:a1> <test:value> "\u0048\u0065\u006C\u006C\u006F foo\u0021"^^<xsd:string> .
# ü foo
<test:a2> <test:value> "\u00FC foo"^^<xsd:string> .
......@@ -215,10 +215,10 @@ public class TupleStoreTest {
TupleStore objectToTest = new TupleStore(1,1);
objectToTest.readTuples(getTestResource("ReadTest", "testUnicodes.nt"));
assertEquals("expected 10 tuples but was " + objectToTest.getAllTuples().size(),
1, objectToTest.getAllTuples().size());
String[][] expected = {
{"\"Hello foo\"^^<xsd:string>"}
{"\"Hello foo\"^^<xsd:string>"},
{"\"Hello foo!\"^^<xsd:string>"},
{"\"ü foo\"^^<xsd:string>"}
};
Query q = new Query(objectToTest);
BindingTable bt = q.query("SELECT ?o WHERE ?s <test:value> ?o");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment