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.
|
||||
}
|
||||
|
||||
func computeLineCol(s []byte, prevTC, tc, line, col int) (int, int) {
|
||||
// s := []rune(string(text))
|
||||
func computeLineCol(text []byte, prevTC, tc, line, col int) (int, int) {
|
||||
if tc < 0 {
|
||||
return line, col
|
||||
}
|
||||
if tc < prevTC {
|
||||
for i := prevTC; i > tc && i > 0; i-- {
|
||||
if s[i] == '\n' {
|
||||
if text[i] == '\n' {
|
||||
line--
|
||||
}
|
||||
}
|
||||
col = 0
|
||||
for i := tc; i >= 0; i-- {
|
||||
if s[i] == '\n' {
|
||||
if text[i] == '\n' {
|
||||
break
|
||||
}
|
||||
col++
|
||||
}
|
||||
return line, col
|
||||
}
|
||||
for i := prevTC + 1; i <= tc && i < len(s); i++ {
|
||||
if s[i] == '\n' {
|
||||
for i := prevTC + 1; i <= tc && i < len(text); i++ {
|
||||
if text[i] == '\n' {
|
||||
col = 0
|
||||
line++
|
||||
} else {
|
||||
col++
|
||||
}
|
||||
}
|
||||
if prevTC == tc && tc == 0 && tc < len(s) {
|
||||
if s[tc] == '\n' {
|
||||
if prevTC == tc && tc == 0 && tc < len(text) {
|
||||
if text[tc] == '\n' {
|
||||
line++
|
||||
col--
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user