本文整理汇总了Golang中strings.Reader.UnreadRune方法的典型用法代码示例。如果您正苦于以下问题:Golang Reader.UnreadRune方法的具体用法?Golang Reader.UnreadRune怎么用?Golang Reader.UnreadRune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings.Reader
的用法示例。
在下文中一共展示了Reader.UnreadRune方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: insertHistory
func insertHistory(buffer *bytes.Buffer, reader *strings.Reader, historyNo int) {
history1 := conio.DefaultEditor.Histories[historyNo]
ch, siz, _ := reader.ReadRune()
if siz > 0 && ch == '^' {
if len(history1.Word) >= 2 {
buffer.WriteString(history1.At(1))
}
} else if siz > 0 && ch == '$' {
if len(history1.Word) >= 2 {
buffer.WriteString(history1.At(-1))
}
} else if siz > 0 && ch == '*' {
if len(history1.Word) >= 2 {
buffer.WriteString(strings.Join(history1.Word[1:], " "))
}
} else if siz > 0 && ch == ':' {
n, count := atoi_(reader)
if count <= 0 {
buffer.WriteRune(':')
} else if n < len(history1.Word) {
buffer.WriteString(history1.Word[n])
}
} else {
if siz > 0 {
reader.UnreadRune()
}
buffer.WriteString(history1.Line)
}
}
示例2: quotedWordCutter
func quotedWordCutter(reader *strings.Reader) (string, bool) {
var buffer bytes.Buffer
for {
if reader.Len() <= 0 {
return "", false
}
ch, _, _ := reader.ReadRune()
if ch != ' ' {
reader.UnreadRune()
break
}
}
quote := NULQUOTE
yenCount := 0
for reader.Len() > 0 {
ch, _, _ := reader.ReadRune()
if yenCount%2 == 0 {
if quote == NULQUOTE && (ch == '"' || ch == '\'') {
quote = ch
} else if quote != NULQUOTE && ch == quote {
quote = NULQUOTE
}
}
if ch == ' ' && quote == NULQUOTE {
break
}
if ch == '\\' {
yenCount++
} else {
yenCount = 0
}
buffer.WriteRune(ch)
}
return buffer.String(), true
}
示例3: atoi_
func atoi_(reader *strings.Reader) (int, int) {
n := 0
count := 0
for reader.Len() > 0 {
ch, _, _ := reader.ReadRune()
index := strings.IndexRune("0123456789", ch)
if index >= 0 {
n = n*10 + index
count++
} else {
reader.UnreadRune()
break
}
}
return n, count
}
示例4: scanToken
func scanToken(rd *strings.Reader) (token string, err error) {
r, _, err := rd.ReadRune()
if err != nil {
return "", err
}
if isSplitRune(r) {
return string(r), nil
}
var tok []rune
for {
tok = append(tok, r)
r, _, err = rd.ReadRune()
if err != nil {
return "", err
}
if isSplitRune(r) {
rd.UnreadRune()
return string(tok), nil
}
}
}