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


Golang ByteScanner.ReadByte方法代码示例

本文整理汇总了Golang中io.ByteScanner.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:Golang ByteScanner.ReadByte方法的具体用法?Golang ByteScanner.ReadByte怎么用?Golang ByteScanner.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.ByteScanner的用法示例。


在下文中一共展示了ByteScanner.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例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: 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

示例5: readString

func readString(buf io.ByteScanner) Literal {
	strbuf := []byte{}
loop:
	for {
		b, err := buf.ReadByte()
		if err != nil {
			break
		}
		switch b {
		case '"':
			return String(string(strbuf))
		case '\\':
			b, err := buf.ReadByte()
			if err != nil {
				break loop
			}
			switch b {
			case 't':
				strbuf = append(strbuf, '\t')
			case 'n':
				strbuf = append(strbuf, '\n')
			case '\\':
				strbuf = append(strbuf, '\\')
			case '"':
				strbuf = append(strbuf, '"')
			default:
				panic("read: unknown escape")
			}
		default:
			strbuf = append(strbuf, b)
		}
	}
	panic("read: unterminated string")
	return String("")
}
开发者ID:ebb,项目名称:lumgua,代码行数:35,代码来源:syntax.go

示例6: nextLine

func nextLine(buf io.ByteScanner) {
	for {
		b, err := buf.ReadByte()
		if err != nil || b == '\n' {
			break
		}
	}
}
开发者ID:ebb,项目名称:lumgua,代码行数:8,代码来源:syntax.go

示例7: TestMockByteScanner

func TestMockByteScanner(t *testing.T) {
	var s io.ByteScanner
	m := &ByteScannerMock{}
	s = m
	m.On("ReadByte").Return(byte('_'), nil)
	b, err := s.ReadByte()
	assert.Equal(t, byte('_'), b)
	assert.Equal(t, nil, err)
}
开发者ID:ernesto-jimenez,项目名称:gogen,代码行数:9,代码来源:generator_test.go

示例8: 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

示例9: expect

func (t *Terminal) expect(r io.ByteScanner, exp byte) (bool, error) {
	c, err := r.ReadByte()
	if err != nil {
		return false, err
	}
	ok := c == exp
	if !ok {
		log.Printf("expect %s failed, got %s", showChar(exp), showChar(c))
	}
	return ok, nil
}
开发者ID:evmar,项目名称:smash,代码行数:11,代码来源:terminal.go

示例10: readAmpersand

func readAmpersand(buf io.ByteScanner) Literal {
	skipws(buf)
	b, err := buf.ReadByte()
	if err != nil {
		panic("read: incomplete input")
	}
	if b != '(' {
		panic("read: ill-formed ampersand")
	}
	x := readList(buf)
	return newListLiteral(Intern("ampersand"), x)
}
开发者ID:ebb,项目名称:lumgua,代码行数:12,代码来源:syntax.go

示例11: 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

示例12: parseSequence

func parseSequence(rdr io.ByteScanner) (Sequence, error) {
	seq := []SimpleSelector{}
	rdr.UnreadByte()
	for c, err := rdr.ReadByte(); err != io.EOF; c, err = rdr.ReadByte() {
		if err != nil {
			return nil, err
		}
		switch c {
		case '*':
			seq = append(seq, SimpleSelector{Type: Universal})
		case '#':
			sel := SimpleSelector{Type: Id, AttrName: "id"}
			if err := parseSimpleSelector(rdr, &sel); err != nil {
				return nil, err
			}
			seq = append(seq, sel)
		case '.':
			sel := SimpleSelector{Type: Class, AttrName: "class"}
			if err := parseSimpleSelector(rdr, &sel); err != nil {
				return nil, err
			}
			seq = append(seq, sel)
		case ':':
			sel := SimpleSelector{Type: PseudoClass}
			if err := parseSimpleSelector(rdr, &sel); err != nil {
				return nil, err
			}
			seq = append(seq, sel)
		case '[':
			sel := SimpleSelector{Type: Attr}
			if err := parseSimpleAttr(rdr, &sel); err != nil {
				return nil, err
			}
			seq = append(seq, sel)
		case '{':
			rdr.UnreadByte()
			return seq, EOS
		case ' ', '\t', '\n', '\r', '\f', '>', '+', '~':
			rdr.UnreadByte()
			return seq, nil
		default:
			sel := SimpleSelector{Type: Tag, Tag: string(c)}
			if err := parseSimpleTag(rdr, &sel); err != nil {
				return nil, err
			}
			seq = append(seq, sel)
		}
	}
	return seq, nil
}
开发者ID:jShi-git,项目名称:goquery_sample,代码行数:50,代码来源:parse.go

示例13: readTo

func (t *Terminal) readTo(r io.ByteScanner, end byte) ([]byte, error) {
	var buf []byte
	for i := 0; i < 1000; i++ {
		c, err := r.ReadByte()
		if err != nil {
			return nil, err
		}
		if c == end {
			return buf, nil
		}
		buf = append(buf, c)
	}
	return nil, fmt.Errorf("term: readTo(%s) overlong", showChar(end))
}
开发者ID:evmar,项目名称:smash,代码行数:14,代码来源:terminal.go

示例14: 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

示例15: 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


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