Skip to content

Commit a7eecd7

Browse files
committed
fix byte->u8 warnings, improve code quality by replacing "\n".bytes()[0] with just \n etc
1 parent 7ba0800 commit a7eecd7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

highlight/highlight.v

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn highlight_text(st string, file_path string, commit bool) (string, int, in
6363
if in_comment {
6464
res << '<i>'.bytes()
6565
}
66-
if !in_comment && !in_line_comment && runes[pos + 1] != '\n'.bytes()[0] {
66+
if !in_comment && !in_line_comment && runes[pos + 1] != `\n` {
6767
sloc++
6868
}
6969
continue
@@ -74,7 +74,7 @@ pub fn highlight_text(st string, file_path string, commit bool) (string, int, in
7474
}
7575
if in_comment {
7676
res << write(c)
77-
if c == mlc_end.bytes()[0] && is_line_comment(runes, pos, mlc_end) {
77+
if c == mlc_end[0] && is_line_comment(runes, pos, mlc_end) {
7878
in_comment = false
7979
res << runes[pos + 1]
8080
pos++
@@ -88,7 +88,7 @@ pub fn highlight_text(st string, file_path string, commit bool) (string, int, in
8888
}
8989
if in_string {
9090
res << write(c)
91-
if runes[pos - 1] == `\\` && ss == '"'.bytes()[0] {
91+
if runes[pos - 1] == `\\` && ss == `"` {
9292
continue
9393
}
9494
if c == ss {
@@ -135,38 +135,38 @@ pub fn highlight_text(st string, file_path string, commit bool) (string, int, in
135135
return res.bytestr(), lines, sloc
136136
}
137137

138-
fn write(c byte) []u8 {
138+
fn write(c u8) []u8 {
139139
mut tmp := []u8{}
140-
if c == '<'.bytes()[0] {
140+
if c == `<` {
141141
tmp << '&lt;'.bytes()
142-
} else if c == '>'.bytes()[0] {
142+
} else if c == `>` {
143143
tmp << '&gt;'.bytes()
144144
} else {
145145
tmp << c
146146
}
147147
return tmp
148148
}
149149

150-
fn is_letter(c byte, lang Lang) bool {
150+
fn is_letter(c u8, lang Lang) bool {
151151
name := lang.name.to_lower()
152-
if (name == 'cpp' || name == 'c' || name == 'd' || name == 'swift') && c == '#'.bytes()[0] {
152+
if (name == 'cpp' || name == 'c' || name == 'd' || name == 'swift') && c == `#` {
153153
return true
154154
}
155155
return c.is_letter() || c == `_`
156156
}
157157

158-
fn is_string_token(c byte, lang Lang) bool {
158+
fn is_string_token(c u8, lang Lang) bool {
159159
for val in lang.string_start {
160-
if c == val.bytes()[0] {
160+
if c == val[0] {
161161
return true
162162
}
163163
}
164164
return false
165165
}
166166

167167
fn is_line_comment(s []u8, pos int, lc string) bool {
168-
for i in 0 .. lc.len {
169-
if s[pos + i] != lc.bytes()[i] {
168+
for i, b in lc {
169+
if s[pos + i] != b {
170170
return false
171171
}
172172
}
@@ -176,7 +176,7 @@ fn is_line_comment(s []u8, pos int, lc string) bool {
176176
fn is_single_line(s string) bool {
177177
mut cnt := 0
178178
for i in 0 .. s.len {
179-
if s.bytes()[i] == '\n'.bytes()[0] {
179+
if s[i] == `\n` {
180180
cnt++
181181
if cnt > 1 {
182182
return false

0 commit comments

Comments
 (0)