當前位置: 首頁>>代碼示例>>Golang>>正文


Golang io.ByteScanner類代碼示例

本文整理匯總了Golang中io.ByteScanner的典型用法代碼示例。如果您正苦於以下問題:Golang ByteScanner類的具體用法?Golang ByteScanner怎麽用?Golang ByteScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ByteScanner類的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: 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

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

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

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

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

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

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


注:本文中的io.ByteScanner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。