本文整理汇总了Golang中io.ByteScanner.UnreadByte方法的典型用法代码示例。如果您正苦于以下问题:Golang ByteScanner.UnreadByte方法的具体用法?Golang ByteScanner.UnreadByte怎么用?Golang ByteScanner.UnreadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.ByteScanner
的用法示例。
在下文中一共展示了ByteScanner.UnreadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: read
func read(buf io.ByteScanner) Literal {
skipws(buf)
b, err := buf.ReadByte()
if err == io.EOF {
panic("read: premature end of file")
}
if err != nil {
panic("read: input error: " + err.Error())
}
switch b {
case ')':
panic("read: unmatched close-parenthesis")
case '"':
return readString(buf)
case '\'':
return readQuote(buf)
case '`':
return readQuasi(buf)
case ',':
return readComma(buf)
case '&':
return readAmpersand(buf)
case '(':
return readList(buf)
}
buf.UnreadByte()
return readAtom(buf)
}
示例2: Read
func (t *Terminal) Read(r io.ByteScanner) error {
c, err := r.ReadByte()
if err != nil {
return err
}
switch {
case c == 0x7: // bell
// ignore
case c == 0x8: // backspace
if t.Col > 0 {
t.Col--
}
case c == 0x1b:
return t.readEscape(r)
case c == '\r':
t.Col = 0
case c == '\n':
t.Col = 0
t.Row++
t.fixPosition()
case c == '\t':
t.Col += 8 - (t.Col % 8)
t.fixPosition()
case c >= ' ' && c <= '~':
t.writeRune(rune(c), t.Attr)
default:
r.UnreadByte()
return t.readUTF8(r)
}
return nil
}
示例3: readAtom
func readAtom(buf io.ByteScanner) Literal {
atomBuf := []byte{}
loop:
for {
b, err := buf.ReadByte()
if err != nil {
break
}
switch b {
case '(', ')', '\'', '"', ' ', '\t', '\n':
buf.UnreadByte()
break loop
}
atomBuf = append(atomBuf, b)
}
if len(atomBuf) == 0 {
panic("read: empty atom")
}
atom := string(atomBuf)
n, err := strconv.ParseFloat(atom, 64)
if err == nil {
return Number(n)
}
return Intern(atom)
}
示例4: readTerminator
func readTerminator(r io.ByteScanner, term byte) (bool, error) {
tok, err := r.ReadByte()
if err != nil {
return false, err
} else if tok == term {
return true, nil
}
return false, r.UnreadByte()
}
示例5: readComma
func readComma(buf io.ByteScanner) Literal {
b, err := buf.ReadByte()
if err != nil {
panic("read: incomplete comma")
}
tag := Intern("unquote")
if b == '@' {
tag = Intern("unquotesplicing")
} else {
buf.UnreadByte()
}
x := read(buf)
return newListLiteral(tag, x)
}
示例6: scanSign
func scanSign(r io.ByteScanner) (neg bool, err error) {
var ch byte
if ch, err = r.ReadByte(); err != nil {
return false, err
}
switch ch {
case '-':
neg = true
case '+':
// nothing to do
default:
r.UnreadByte()
}
return
}
示例7: readInt
func (t *Terminal) readInt(r io.ByteScanner) (int, error) {
n := 0
for i := 0; i < 20; i++ {
c, err := r.ReadByte()
if err != nil {
return -1, err
}
if c >= '0' && c <= '9' {
n = n*10 + int(c) - '0'
} else {
r.UnreadByte()
return n, err
}
}
return -1, fmt.Errorf("term: readInt overlong")
}
示例8: skipws
func skipws(buf io.ByteScanner) {
for {
b, err := buf.ReadByte()
if err != nil {
break
}
switch b {
case ' ', '\t', '\n':
continue
case ';':
nextLine(buf)
continue
}
buf.UnreadByte()
break
}
}
示例9: parseDocument
// parseDocument parses a document.
func (p *Parser) parseDocument(r io.ByteScanner) {
_, err := r.ReadByte()
if err != nil {
return
}
r.UnreadByte()
p.root = addElement(nil, "Document")
p.current = p.root
for {
_, err := r.ReadByte()
if err != nil {
break
}
r.UnreadByte()
p.parseLine(r)
}
}
示例10: readList
func readList(buf io.ByteScanner) Literal {
skipws(buf)
items := []Literal{}
for {
b, err := buf.ReadByte()
if err != nil {
panic("read: premature end of file")
}
if b == ')' {
break
}
buf.UnreadByte()
items = append(items, read(buf))
skipws(buf)
}
return newListLiteral(items...)
}
示例11: consumeValue
func consumeValue(rdr io.ByteScanner) ([]byte, error) {
bs := []byte{}
for c, err := rdr.ReadByte(); err != io.EOF; c, err = rdr.ReadByte() {
if err != nil {
return nil, err
}
switch c {
case '{':
rdr.UnreadByte()
return bs, EOS
case '>', '+', '~', ' ', '\t', '\n', '\f', ',', '.', '#', '[', ':':
rdr.UnreadByte()
return bs, nil
default:
bs = append(bs, c)
}
}
return bs, nil
}
示例12: readWhile
// Read from reader while f holds true, unread bytes if reset == true
func readWhile(reader io.ByteScanner, f func(b byte) bool, reset bool) string {
s := ""
for {
b, err := reader.ReadByte()
if err != nil {
return s
}
if !f(b) {
reader.UnreadByte()
return s
}
if reset {
defer reader.UnreadByte()
}
s += string(b)
}
return s
}
示例13: parseLine
// parseLine parses an unknown line.
func (p *Parser) parseLine(r io.ByteScanner) {
level := 0
for {
c, err := r.ReadByte()
if err != nil {
return
}
if c == '*' && level == 0 {
p.closeElement("Paragraph")
r.UnreadByte()
p.parseHeader(r)
} else if c == ':' {
c, err := r.ReadByte()
if err != nil {
r.UnreadByte()
return
}
if c != ' ' {
p.openElement("Paragraph")
r.UnreadByte()
p.startElement("Text")
p.current.Text = ":"
p.current.Attr["level"] = fmt.Sprint(level)
p.parseTextLine(r)
p.endElement()
continue
}
p.closeElement("Paragraph")
p.parseExampleLine(r)
p.nextLine()
break
} else if c == ' ' {
level += 1
p.nextColumn()
} else if c == '\n' {
p.closeElement("Paragraph")
p.nextLine()
break
} else if c == '\r' {
// Ignore CR character.
p.nextColumn()
} else {
p.openElement("Paragraph")
r.UnreadByte()
p.startElement("Text")
p.current.Attr["level"] = fmt.Sprint(level)
p.parseTextLine(r)
p.endElement()
}
}
}
示例14: parseCombinator
func parseCombinator(rdr io.ByteScanner, p *Link) error {
rdr.UnreadByte()
for c, err := rdr.ReadByte(); err != io.EOF; c, err = rdr.ReadByte() {
if err != nil {
return err
}
switch c {
case '{':
rdr.UnreadByte()
return EOS
case ',':
return fmt.Errorf("Encountered ',' after combinator")
case ' ', '\t', '\n', '\r', '\f':
case '>', '+', '~':
if p.Combinator == Descendant {
p.Combinator = combinatorMap[c]
} else {
return fmt.Errorf("Can't combine multiple combinators")
}
default:
rdr.UnreadByte()
return nil
}
}
return nil
}
示例15: parseSimpleAttr
func parseSimpleAttr(rdr io.ByteScanner, sel *SimpleSelector) error {
var name []byte
var value []byte
var c1 byte = 0
for c2, err := rdr.ReadByte(); err != io.EOF; c2, err = rdr.ReadByte() {
if err != nil {
return err
}
switch c2 {
case ']':
sel.AttrName = string(name)
sel.Value = string(value)
return nil
case '=':
if c1 == '~' {
sel.AttrMatch = Contains
} else if c1 == '|' {
sel.AttrMatch = DashPrefix
} else {
sel.AttrMatch = Exactly
}
case '{':
rdr.UnreadByte()
return EOS
case '~':
case '|':
// TODO(jwall): Substring matchers
default:
if sel.AttrMatch == Presence {
name = append(name, c2)
} else {
value = append(value, c2)
}
}
c1 = c2
}
return fmt.Errorf("Didn't close Attribute Matcher")
}