当前位置: 首页>>代码示例>>Golang>>正文


Golang ByteScanner.UnreadByte方法代码示例

本文整理汇总了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)
}
开发者ID:ebb,项目名称:lumgua,代码行数:28,代码来源:syntax.go

示例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
}
开发者ID:evmar,项目名称:smash,代码行数:31,代码来源:terminal.go

示例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)
}
开发者ID:ebb,项目名称:lumgua,代码行数:25,代码来源:syntax.go

示例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()
}
开发者ID:mrd0ll4r,项目名称:chihaya,代码行数:9,代码来源:decoder.go

示例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)
}
开发者ID:ebb,项目名称:lumgua,代码行数:14,代码来源:syntax.go

示例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
}
开发者ID:gmwu,项目名称:go,代码行数:15,代码来源:intconv.go

示例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")
}
开发者ID:evmar,项目名称:smash,代码行数:16,代码来源:terminal.go

示例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
	}
}
开发者ID:ebb,项目名称:lumgua,代码行数:17,代码来源:syntax.go

示例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)
	}
}
开发者ID:jaeyeom,项目名称:orgmode-wiki,代码行数:18,代码来源:parser.go

示例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...)
}
开发者ID:ebb,项目名称:lumgua,代码行数:17,代码来源:syntax.go

示例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
}
开发者ID:jShi-git,项目名称:goquery_sample,代码行数:19,代码来源:parse.go

示例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
}
开发者ID:hlubek,项目名称:parser-experiments,代码行数:20,代码来源:tokenizer.go

示例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()
		}
	}
}
开发者ID:jaeyeom,项目名称:orgmode-wiki,代码行数:52,代码来源:parser.go

示例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
}
开发者ID:jShi-git,项目名称:goquery_sample,代码行数:26,代码来源:parse.go

示例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")
}
开发者ID:jShi-git,项目名称:goquery_sample,代码行数:38,代码来源:parse.go


注:本文中的io.ByteScanner.UnreadByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。