import (
"bufio"
"fmt"
"io"
"strings"
"unicode/utf8"
)
func main() {
inputText := "车牌号:苏A02WC7\n邮政编码:211700\n宗教信仰:伊斯兰教"
rd := bufio.NewReaderSize(strings.NewReader(inputText), 1024)
for {
line, err := rd.ReadBytes('\n')
fmt.Printf("%c \n", line)
sz := len(line)
for i := 0; i < sz; {
ch, width := utf8.DecodeRune(line[i:])
fmt.Printf("line[i:] %c \n", line[i:])
fmt.Printf("i %v \n", i)
fmt.Printf("width %v \n", width)
fmt.Printf("ch %c \n", ch)
if width == 0 {
break
}
if i+1 < sz && isEqualChar(ch) {
left := ""
right := ""
kPos := []int{-1, -1}
isFound := false
if i+2 < sz {
nx, nxWidth := utf8.DecodeRune(line[i+width:])
fmt.Printf("%s \n", nxWidth)
if nx == '=' {
left, kPos = lastToken(line, i)
isFound = true
}
}
if !isFound {
left, kPos = lastToken(line, i)
isFound = true
}
_ = kPos
if len(left) != 0 && len(right) != 0 {
}
}
i += width
}
if err != nil {
if err != io.EOF {
}
break
}
}
}
func isEqualChar(r rune) bool {
return r == ':' || r == '=' || r == ':'
}
func firstToken(line []byte, offset int) (string, []int) {
sz := len(line)
if offset >= 0 && offset < sz {
st := offset
ed := sz
for i := offset; i < sz; i++ {
if strings.IndexByte(" /\r\n\\[](){}:=\"'," , line[i]) == -1 {
st = i
break
}
}
for i := st + 1; i < sz; i++ {
if strings.IndexByte(" /\r\n\\[](){}:=\"'," , line[i]) != -1 {
ed = i
break
}
}
return string(line[st:ed]), []int{st, ed}
} else {
return "", nil
}
}
func lastToken(line []byte, offset int) (string, []int) {
sz := len(line)
if offset >= 0 && offset < sz {
st := 0
ed := offset
for i := offset - 1; i >= 0; i-- {
if strings.IndexByte(" /\r\n\\[](){}:=\"'," , line[i]) == -1 {
ed = i + 1
break
}
}
for i := ed - 1; i >= 0; i-- {
if strings.IndexByte(" /\r\n\\[](){}:=\"'," , line[i]) != -1 {
st = i + 1
break
}
}
return string(line[st:ed]), []int{st, ed}
} else {
return "", nil
}
}