KKSU
2024-11-21 80fd9e3da4b45285c29cdb380ce743202b0c2af4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.best.javaSdk.converter.util.jsonReader;
 
public class BufferErrorListener implements JSONErrorListener {
 
    protected StringBuffer buffer;
    private String input;
    
    public BufferErrorListener(StringBuffer buffer) {
        this.buffer = buffer;
    }
    
    public BufferErrorListener() {
        this(new StringBuffer());
    }
    
    public void start(String input) {
        this.input = input;
        buffer.setLength(0);
    }
 
    public void error(String type, int col) {
        buffer.append("expected ");
        buffer.append(type);
        buffer.append(" at column ");
        buffer.append(col);
        buffer.append("\n");
        buffer.append(input);
        buffer.append("\n");
        indent(col-1, buffer);
        buffer.append("^");
    }
 
    private void indent(int n, StringBuffer ret) {
        for (int i = 0; i< n; ++i) {
            ret.append(' ');
        }
    }
 
    public void end() {
    }
}