Search in sources :

Example 1 with SymbolTable

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));
}
Also used : SymbolTable(com.alibaba.fastjson.parser.SymbolTable) CharsToNameCanonicalizer(com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer)

Example 2 with SymbolTable

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();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) SymbolTable(com.alibaba.fastjson.parser.SymbolTable)

Example 3 with SymbolTable

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();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) SymbolTable(com.alibaba.fastjson.parser.SymbolTable)

Example 4 with SymbolTable

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();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) SymbolTable(com.alibaba.fastjson.parser.SymbolTable)

Example 5 with SymbolTable

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();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) SymbolTable(com.alibaba.fastjson.parser.SymbolTable)

Aggregations

SymbolTable (com.alibaba.fastjson.parser.SymbolTable)16 JSONScanner (com.alibaba.fastjson.parser.JSONScanner)15 JSONException (com.alibaba.fastjson.JSONException)2 CharsToNameCanonicalizer (com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer)1