use of com.alibaba.fastjson.parser.SymbolTable in project fastjson by alibaba.
the class SymbolTableTest method test_symbol.
public void test_symbol() throws Exception {
char[][] symbols_char = new char[symbols.length][];
for (int i = 0; i < symbols.length; ++i) {
symbols_char[i] = symbols[i].toCharArray();
}
{
CharsToNameCanonicalizer table = CharsToNameCanonicalizer.createRoot();
for (int i = 0; i < symbols.length; ++i) {
String symbol = symbols[i];
table.findSymbol(symbol.toCharArray(), 0, symbol.length(), symbol.hashCode());
}
}
SymbolTable table = new SymbolTable(512);
for (int i = 0; i < symbols.length; ++i) {
String symbol = symbols[i];
char[] charArray = symbol.toCharArray();
table.addSymbol(charArray, 0, charArray.length);
//System.out.println((table.hash(symbol) & table.getIndexMask()) + "\t\t:" + symbol + "\t\t" + table.hash(symbol));
}
String symbol = "name";
table.addSymbol(symbol.toCharArray(), 0, symbol.length());
table.addSymbol(symbol.toCharArray(), 0, symbol.length());
Assert.assertTrue(symbol == table.addSymbol("name".toCharArray(), 0, 4));
Assert.assertTrue(symbol == table.addSymbol(" name".toCharArray(), 1, 4));
Assert.assertTrue(symbol == table.addSymbol(" name ".toCharArray(), 1, 4));
Assert.assertTrue(symbol != table.addSymbol(" namf ".toCharArray(), 1, 4));
}
use of com.alibaba.fastjson.parser.SymbolTable in project fastjson by alibaba.
the class JSONScannerTest_symbol method test_12.
public void test_12() throws Exception {
SymbolTable symbolTable = new SymbolTable(512);
JSONScanner lexer = new JSONScanner("\"\\tabcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890\"");
String symbol = lexer.scanSymbol(symbolTable, '"');
Assert.assertTrue("\tabcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890" == symbol);
lexer.close();
}
use of com.alibaba.fastjson.parser.SymbolTable in project fastjson by alibaba.
the class JSONScannerTest_symbol method test_7.
public void test_7() throws Exception {
SymbolTable symbolTable = new SymbolTable(512);
JSONScanner lexer = new JSONScanner("\"nick \\F name\"");
String symbol = lexer.scanSymbol(symbolTable, '"');
Assert.assertTrue("nick \f name" == symbol);
lexer.close();
}
use of com.alibaba.fastjson.parser.SymbolTable in project fastjson by alibaba.
the class JSONScannerTest_symbol method test_3.
public void test_3() throws Exception {
SymbolTable symbolTable = new SymbolTable(512);
JSONScanner lexer = new JSONScanner("\"nick \\\\name\"");
String symbol = lexer.scanSymbol(symbolTable, '"');
Assert.assertTrue("nick \\name" == symbol);
lexer.close();
}
use of com.alibaba.fastjson.parser.SymbolTable in project fastjson by alibaba.
the class JSONScannerTest_symbol method test_9.
public void test_9() throws Exception {
SymbolTable symbolTable = new SymbolTable(512);
JSONScanner lexer = new JSONScanner("\"nick \\r name\"");
String symbol = lexer.scanSymbol(symbolTable, '"');
Assert.assertTrue("nick \r name" == symbol);
lexer.close();
}
Aggregations