Revert code
This commit is contained in:
parent
fd42cc208a
commit
2da032b556
23
cmd/main.go
Normal file
23
cmd/main.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
b := []byte("你好")
|
||||||
|
|
||||||
|
sz := 0
|
||||||
|
var r rune
|
||||||
|
|
||||||
|
for i := 0; i < len(b); {
|
||||||
|
r, sz = utf8.DecodeRune(b[i:])
|
||||||
|
i += sz
|
||||||
|
|
||||||
|
fmt.Println(r, sz, i, string(r))
|
||||||
|
}
|
||||||
|
|
||||||
|
// fmt.Println(len(b))
|
||||||
|
|
||||||
|
}
|
@ -69,36 +69,35 @@ type Match struct {
|
|||||||
Bytes []byte // the actual bytes matched during scanning.
|
Bytes []byte // the actual bytes matched during scanning.
|
||||||
}
|
}
|
||||||
|
|
||||||
func computeLineCol(s []byte, prevTC, tc, line, col int) (int, int) {
|
func computeLineCol(text []byte, prevTC, tc, line, col int) (int, int) {
|
||||||
// s := []rune(string(text))
|
|
||||||
if tc < 0 {
|
if tc < 0 {
|
||||||
return line, col
|
return line, col
|
||||||
}
|
}
|
||||||
if tc < prevTC {
|
if tc < prevTC {
|
||||||
for i := prevTC; i > tc && i > 0; i-- {
|
for i := prevTC; i > tc && i > 0; i-- {
|
||||||
if s[i] == '\n' {
|
if text[i] == '\n' {
|
||||||
line--
|
line--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
col = 0
|
col = 0
|
||||||
for i := tc; i >= 0; i-- {
|
for i := tc; i >= 0; i-- {
|
||||||
if s[i] == '\n' {
|
if text[i] == '\n' {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
col++
|
col++
|
||||||
}
|
}
|
||||||
return line, col
|
return line, col
|
||||||
}
|
}
|
||||||
for i := prevTC + 1; i <= tc && i < len(s); i++ {
|
for i := prevTC + 1; i <= tc && i < len(text); i++ {
|
||||||
if s[i] == '\n' {
|
if text[i] == '\n' {
|
||||||
col = 0
|
col = 0
|
||||||
line++
|
line++
|
||||||
} else {
|
} else {
|
||||||
col++
|
col++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if prevTC == tc && tc == 0 && tc < len(s) {
|
if prevTC == tc && tc == 0 && tc < len(text) {
|
||||||
if s[tc] == '\n' {
|
if text[tc] == '\n' {
|
||||||
line++
|
line++
|
||||||
col--
|
col--
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user