-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineColumnTracker.java
87 lines (73 loc) · 1.67 KB
/
LineColumnTracker.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.lupcode.JSON.utils;
/** Class is used for tracking line and column numbers while parsing
* @author LupCode.com (Luca Vogels)
* @since 2020-12-23
*/
public class LineColumnTracker {
private long line=1, offset=0;
private int column=0;
public LineColumnTracker(){
}
public LineColumnTracker(long offset){
this.offset = offset;
}
public LineColumnTracker(long line, int column, long offset){
this.line = line;
this.column = column;
this.offset = offset;
}
/**
* Returns the current line beginning from one
* @return Line number
*/
public long getLine(){
return line;
}
/**
* Increments the line counter and resets column counter back to zero
* @return Total offset
*/
public long increaseLine(){
this.line++; this.column=0; this.offset++; return this.offset;
}
/**
* Returns the current column beginning from zero
* @return Column number
*/
public int getColumn(){
return column;
}
/**
* Increases the column counter
* @return Total offset
*/
public long increaseColumn(){
this.column++;
this.offset++;
return this.offset;
}
/**
* Increases the column counter
* @param value How much the counter should be increased
* @return Total offset
*/
public long increaseColumn(int value){
this.column += value;
this.offset += value;
return this.offset;
}
/**
* Returns the total character offset from the beginning
* @return Total offset
*/
public long getOffset(){
return offset;
}
@Override
public LineColumnTracker clone() {
return new LineColumnTracker(line, column, offset);
}
public String toString(){
return "line "+line+" column "+column+" (totalOffset="+offset+")";
}
}