@@ -17,6 +17,8 @@ const (
17
17
double_quote = `"`
18
18
// char used as number separator
19
19
num_sep = `_`
20
+ b_lf = 10
21
+ b_cr = 13
20
22
)
21
23
22
24
pub struct Scanner {
@@ -492,18 +494,22 @@ fn (mut s Scanner) ident_number() string {
492
494
}
493
495
}
494
496
495
- [inline ]
497
+ [direct_array_access; inline]
496
498
fn (mut s Scanner) skip_whitespace () {
497
- // if s.is_vh { println('vh') return }
498
- for s.pos < s.text.len && s.text [s.pos]. is_space () {
499
- if util. is_nl (s.text[s.pos]) && s.is_vh {
499
+ for s.pos < s.text.len {
500
+ c := s.text[s.pos]
501
+ if ! c. is_space () {
500
502
return
501
503
}
502
- if s.pos + 1 < s.text.len && s.text[s.pos] == `\r ` && s.text[s.pos + 1 ] == `\n ` {
504
+ c_is_nl := c == scanner.b_cr || c == scanner.b_lf
505
+ if c_is_nl && s.is_vh {
506
+ return
507
+ }
508
+ if s.pos + 1 < s.text.len && c == scanner.b_cr && s.text[s.pos + 1 ] == scanner.b_lf {
503
509
s.is_crlf = true
504
510
}
505
511
// Count \r\n as one line
506
- if util. is_nl (s.text[s. pos]) && ! s. expect ( ' \r\n ' , s.pos - 1 ) {
512
+ if c_is_nl && ! (s.pos > 0 && s.text[ s.pos - 1 ] == scanner.b_cr && c == scanner.b_lf ) {
507
513
s.inc_line_number ()
508
514
}
509
515
s.pos++
@@ -975,7 +981,7 @@ fn (mut s Scanner) text_scan() token.Token {
975
981
start := s.pos + 1
976
982
s.ignore_line ()
977
983
mut comment_line_end := s.pos
978
- if s.text[s.pos - 1 ] == ` \r ` {
984
+ if s.text[s.pos - 1 ] == scanner.b_cr {
979
985
comment_line_end--
980
986
} else {
981
987
// fix line_nr, \n was read; the comment is marked on the next line
@@ -987,7 +993,7 @@ fn (mut s Scanner) text_scan() token.Token {
987
993
mut comment := s.line_comment
988
994
// Find out if this comment is on its own line (for vfmt)
989
995
mut is_separate_line_comment := true
990
- for j := start - 2 ; j > = 0 && s.text[j] != ` \n ` ; j-- {
996
+ for j := start - 2 ; j > = 0 && s.text[j] != scanner.b_lf ; j-- {
991
997
if s.text[j] ! in [`\t ` , ` ` ] {
992
998
is_separate_line_comment = false
993
999
}
@@ -1015,7 +1021,7 @@ fn (mut s Scanner) text_scan() token.Token {
1015
1021
s.line_nr--
1016
1022
s.error ('comment not terminated' )
1017
1023
}
1018
- if s.text[s.pos] == ` \n ` {
1024
+ if s.text[s.pos] == scanner.b_lf {
1019
1025
s.inc_line_number ()
1020
1026
continue
1021
1027
}
@@ -1098,7 +1104,7 @@ fn (mut s Scanner) ident_string() string {
1098
1104
if start_char == s.quote
1099
1105
|| (start_char == s.inter_quote && (s.is_inter_start || s.is_enclosed_inter)) {
1100
1106
start++
1101
- } else if start_char == ` \n ` {
1107
+ } else if start_char == scanner.b_lf {
1102
1108
s.inc_line_number ()
1103
1109
}
1104
1110
s.is_inside_string = false
@@ -1120,10 +1126,10 @@ fn (mut s Scanner) ident_string() string {
1120
1126
if c == s.inter_quote && (s.is_inter_start || s.is_enclosed_inter) {
1121
1127
break
1122
1128
}
1123
- if c == ` \r ` {
1129
+ if c == scanner.b_cr {
1124
1130
n_cr_chars++
1125
1131
}
1126
- if c == ` \n ` {
1132
+ if c == scanner.b_lf {
1127
1133
s.inc_line_number ()
1128
1134
}
1129
1135
// Don't allow \0
@@ -1288,9 +1294,9 @@ fn (mut s Scanner) ignore_line() {
1288
1294
s.inc_line_number ()
1289
1295
}
1290
1296
1291
- [inline ]
1297
+ [direct_array_access; inline]
1292
1298
fn (mut s Scanner) eat_to_end_of_line () {
1293
- for s.pos < s.text.len && s.text[s.pos] != ` \n ` {
1299
+ for s.pos < s.text.len && s.text[s.pos] != scanner.b_lf {
1294
1300
s.pos++
1295
1301
}
1296
1302
}
0 commit comments