Search in sources :

Example 41 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest_scanSymbol method test_1.

public void test_1() throws Exception {
    JSONScanner lexer = new JSONScanner("\"value\":\"aa\"},");
    long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
    Assert.assertEquals(fnv_hash("aa"), hashCode);
    Assert.assertEquals(JSONScanner.END, lexer.matchStat());
    Assert.assertEquals(JSONToken.COMMA, lexer.token());
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 42 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest_singQuoteString method test_string2.

public void test_string2() throws Exception {
    StringBuilder buf = new StringBuilder();
    buf.append('\'');
    for (int i = 0; i < 200; ++i) {
        buf.append("\\\\\\/\\b\\f\\n\\r\\t\\u" + Integer.toHexString('中'));
    }
    buf.append('\'');
    String text = buf.toString();
    JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
    lexer.config(Feature.AllowSingleQuotes, true);
    lexer.nextToken();
    Assert.assertEquals(0, lexer.pos());
    String stringVal = lexer.stringVal();
    // Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
    // JSON.toJSONString(stringVal));
    JSON.toJSONString(stringVal);
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 43 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest_singQuoteString method test_error_1.

public void test_error_1() throws Exception {
    Exception error = null;
    try {
        JSONScanner lexer = new JSONScanner("'k\\k'");
        lexer.config(Feature.AllowSingleQuotes, true);
        lexer.nextToken();
        Assert.assertEquals(JSONToken.ERROR, lexer.token());
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) JSONException(com.alibaba.fastjson.JSONException) JSONException(com.alibaba.fastjson.JSONException)

Example 44 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner in project fastjson by alibaba.

the class JSONScannerTest_singQuoteString method test_string3.

public void test_string3() throws Exception {
    StringBuilder buf = new StringBuilder();
    buf.append('\'');
    for (int i = 0; i < 200; ++i) {
        buf.append("abcdefghijklmn012345689ABCDEFG");
    }
    buf.append('\'');
    String text = buf.toString();
    JSONScanner lexer = new JSONScanner(text.toCharArray(), text.length());
    lexer.config(Feature.AllowSingleQuotes, true);
    lexer.nextToken();
    Assert.assertEquals(0, lexer.pos());
    String stringVal = lexer.stringVal();
    // Assert.assertEquals("\"\\\\\\/\\b\\f\\n\\r\\t中\"",
    // JSON.toJSONString(stringVal));
    JSON.toJSONString(stringVal);
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner)

Example 45 with JSONScanner

use of com.alibaba.fastjson.parser.JSONScanner 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)

Aggregations

JSONScanner (com.alibaba.fastjson.parser.JSONScanner)179 JSONException (com.alibaba.fastjson.JSONException)37 SymbolTable (com.alibaba.fastjson.parser.SymbolTable)15 JSONReader (com.alibaba.fastjson.JSONReader)11 ParseException (java.text.ParseException)5 BigInteger (java.math.BigInteger)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 BigDecimal (java.math.BigDecimal)1 AccessControlException (java.security.AccessControlException)1 Calendar (java.util.Calendar)1