File tree Expand file tree Collapse file tree 2 files changed +22
-28
lines changed
opengrok-indexer/src/main/resources/util Expand file tree Collapse file tree 2 files changed +22
-28
lines changed Original file line number Diff line number Diff line change @@ -35,35 +35,29 @@ import java.util.List;
35
35
return false ;
36
36
%eofval}
37
37
%eof{
38
- length = yychar;
39
-
40
38
/*
41
39
* Following JFlexXref's custom, an empty file or a file ending with EOL
42
40
* produces an additional line of length zero. We also ensure there are two
43
41
* entries to describe the boundaries.
44
42
*/
45
- if (lastHadEOL || offsets. size() <= 1 ) {
46
- offsets. add(yychar);
47
- }
43
+ offsets. add(yychar);
44
+ length = yychar;
48
45
%eof}
49
46
%{
50
47
private int length;
51
48
52
- private boolean lastHadEOL;
53
-
54
49
private List<Integer > offsets;
55
50
56
51
public int getLength() {
57
52
return length;
58
53
}
59
54
60
55
/**
61
- * Sets the required target to write.
56
+ * Sets the required target to write, and adds a first offset of 0 .
62
57
* @param offsets a required instance
63
58
*/
64
59
public void setTarget(List<Integer > offsets) {
65
60
this . length = 0 ;
66
- this . lastHadEOL = false ;
67
61
this . offsets = offsets;
68
62
offsets. add(0 );
69
63
}
@@ -84,12 +78,9 @@ import java.util.List;
84
78
%include Common.lexh
85
79
%%
86
80
87
- [^\n\r] * {EOL} {
81
+ {EOL} {
88
82
offsets. add(yychar + yylength());
89
- lastHadEOL = true ;
90
83
}
91
84
92
- [^\n\r] + {
93
- offsets. add(yychar + yylength());
94
- lastHadEOL = false ;
85
+ [^\n\r] {
95
86
}
Original file line number Diff line number Diff line change @@ -35,20 +35,19 @@ import java.util.List;
35
35
return false ;
36
36
%eofval}
37
37
%eof{
38
- length = yychar;
39
-
40
38
/*
41
39
* Following JFlexXref's custom, an empty file or a file ending with EOL
42
40
* produces an additional line of length zero.
43
41
*/
44
- if (lastHadEOL || lines. size() < 1 ) {
45
- lines. add(" " );
46
- }
42
+ lines. add(builder. toString());
43
+ builder. setLength(0 );
44
+
45
+ length = yychar;
47
46
%eof}
48
47
%{
49
- private int length ;
48
+ private final StringBuilder builder = new StringBuilder () ;
50
49
51
- private boolean lastHadEOL ;
50
+ private int length ;
52
51
53
52
private List<String > lines;
54
53
@@ -61,8 +60,8 @@ import java.util.List;
61
60
* @param lines a required instance
62
61
*/
63
62
public void setTarget(List<String > lines) {
63
+ this . builder. setLength(0 );
64
64
this . length = 0 ;
65
- this . lastHadEOL = false ;
66
65
this . lines = lines;
67
66
}
68
67
@@ -82,12 +81,16 @@ import java.util.List;
82
81
%include Common.lexh
83
82
%%
84
83
85
- [^\n\r] * {EOL} {
86
- lines. add(yytext());
87
- lastHadEOL = true ;
84
+ {EOL} {
85
+ for (int i = 0 ; i < yylength(); ++ i) {
86
+ builder. append(yycharat(i)); // faster than yytext()
87
+ }
88
+ lines. add(builder. toString());
89
+ builder. setLength(0 );
88
90
}
89
91
90
- [^\n\r] + {
91
- lines. add(yytext());
92
- lastHadEOL = false ;
92
+ [^\n\r] {
93
+ for (int i = 0 ; i < yylength(); ++ i) {
94
+ builder. append(yycharat(i)); // faster than yytext()
95
+ }
93
96
}
You can’t perform that action at this time.
0 commit comments