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


Golang RuneScanner.UnreadRune方法代码示例

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


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

示例1: parseNumber

// ParseNumber parses and returns a positive integer.
// Leading spaces are ignored.
// If EOF is reached before any digits are encountered, 1 is returned.
func parseNumber(rs io.RuneScanner) (int, error) {
	if err := skipSpace(rs); err != nil {
		return 0, err
	}
	var s string
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			break
		case err != nil:
			return 0, err
		case unicode.IsDigit(r):
			s += string(r)
			continue
		default:
			if err := rs.UnreadRune(); err != nil {
				return 0, err
			}
		}

		if len(s) == 0 {
			return 1, nil
		}
		return strconv.Atoi(s)
	}
}
开发者ID:chai2010,项目名称:T,代码行数:29,代码来源:edit.go

示例2: parseCompoundAddr

func parseCompoundAddr(rs io.RuneScanner) (Address, error) {
	var a1 Address
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			return a1, nil
		case err != nil:
			return nil, err
		case strings.ContainsRune(simpleFirst, r):
			if err := rs.UnreadRune(); err != nil {
				return nil, err
			}
			switch a2, err := parseSimpleAddr(rs); {
			case err != nil:
				return nil, err
			case a1 != nil:
				a1 = a1.Plus(a2)
			default:
				a1 = a2
			}
		case r == '+' || r == '-':
			if a1 == nil {
				a1 = Dot
			}
			a2, err := parseSimpleAddr(rs)
			if a2 == nil {
				a2 = Line(1)
			}
			switch {
			case err != nil:
				return nil, err
			case r == '+':
				a1 = a1.Plus(a2)
			default:
				a1 = a1.Minus(a2)
			}
		case r == ',' || r == ';':
			if a1 == nil {
				a1 = Line(0)
			}
			a2, err := parseCompoundAddr(rs)
			if a2 == nil {
				a2 = End
			}
			switch {
			case err != nil:
				return nil, err
			case r == ',':
				a1 = a1.To(a2)
			default:
				a1 = a1.Then(a2)
			}
		case unicode.IsSpace(r) && r != '\n':
			continue
		default:
			return a1, rs.UnreadRune()
		}
	}
}
开发者ID:chai2010,项目名称:T,代码行数:59,代码来源:addr.go

示例3: chompBOM

func chompBOM(r io.RuneScanner) (err error) {
	for {
		c, _, err := r.ReadRune()
		if err != nil {
			return err
		}
		if c != BOM {
			r.UnreadRune()
			return nil
		}
	}
}
开发者ID:CowPanda,项目名称:hugo,代码行数:12,代码来源:page.go

示例4: chompWhitespace

func chompWhitespace(r io.RuneScanner) (err error) {
	for {
		c, _, err := r.ReadRune()
		if err != nil {
			return err
		}
		if !unicode.IsSpace(c) {
			r.UnreadRune()
			return nil
		}
	}
}
开发者ID:CowPanda,项目名称:hugo,代码行数:12,代码来源:page.go

示例5: skipSingleNewline

func skipSingleNewline(rs io.RuneScanner) error {
	// Eat a single trailing newline.
	switch r, _, err := rs.ReadRune(); {
	case err == io.EOF:
		return nil
	case err != nil:
		return err
	case r == '\n':
		return nil
	default:
		return rs.UnreadRune()
	}
}
开发者ID:chai2010,项目名称:T,代码行数:13,代码来源:edit.go

示例6: readNumber

func readNumber(b int, r io.RuneScanner) string {
	s := string(b)
	rune, _, err := r.ReadRune()
	for err == nil && string(rune) != " " && string(rune) != "(" && string(rune) != ")" {
		s = s + string(rune)
		rune, _, err = r.ReadRune()
	}
	if err == nil {
		r.UnreadRune()
	}

	return s
}
开发者ID:xiaohong,项目名称:algorithm,代码行数:13,代码来源:client.go

示例7: skipSpace

// SkipSpace consumes and ignores non-newline whitespace.
// Terminates if a newline is encountered.
// The terminating newline remains consumed.
func skipSpace(rs io.RuneScanner) error {
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			return nil
		case err != nil:
			return err
		case r != '\n' && unicode.IsSpace(r):
			continue
		default:
			return rs.UnreadRune()
		}
	}
}
开发者ID:chai2010,项目名称:T,代码行数:17,代码来源:edit.go

示例8: readSdParamName

// readSdParam reads a PARAM-NAME as defined by RFC-5424
// SD-PARAM        = PARAM-NAME "=" %d34 PARAM-VALUE %d34
// PARAM-NAME      = SD-NAME
// SD-NAME         = 1*32PRINTUSASCII except '=', SP, ']', %d34 (")
func readSdParamName(r io.RuneScanner) (string, error) {
	rv := &bytes.Buffer{}
	for {
		ch, _, err := r.ReadRune()
		if err != nil {
			return "", err
		}
		if ch == '=' {
			r.UnreadRune()
			return string(rv.Bytes()), nil
		}
		rv.WriteRune(ch)
	}
}
开发者ID:leavengood,项目名称:rfc5424,代码行数:18,代码来源:unmarshal.go

示例9: parseNegation

func parseNegation(r io.RuneScanner, glob *globImpl) error {
	for {
		char, _, err := r.ReadRune()

		if err != nil {
			return err
		} else if char == '!' {
			glob.negated = !glob.negated
		} else {
			r.UnreadRune()
			return nil
		}
	}
}
开发者ID:hailocab,项目名称:ohmyglob,代码行数:14,代码来源:glob.go

示例10: readword

func readword(f *Xfile, isnum bool) string {
	var (
		barr [512]rune
		sp   int
		c    rune
		err  error
		sc   io.RuneScanner
	)
	if f.isgraphic() {
		sc = f.graph
	} else {
		sc = f.b
	}
	buf := barr[0:0]
	sp = 0
	for {
		c, _, err = sc.ReadRune()
		if err!=nil || !unicode.IsSpace(c) {
			break
		}
	}
	for {
		if err!=nil && sp==0 {
			panic("read: eof met")
		}
		buf = append(buf, c)
		sp++
		c, _, err = sc.ReadRune()
		if err!=nil || (isnum && !strings.ContainsRune("0123456789+-eE.", c)) {
			break
		}
		if err!=nil || unicode.IsSpace(c) {
			break
		}
	}
	if err != nil {
		if iseof(c, err) {
			f.eof = true
		}
	} else {
		f.eol = (c == rune(paminstr.EOL[0]))
		if !f.eol {
			sc.UnreadRune()
		}
	}
	if len(buf) == 0 {
		panic("read: eof met")
	}
	return string(buf)
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:50,代码来源:builtin.go

示例11: readNumber

func readNumber(b int, r io.RuneScanner) interface{} {
	s := string(b)

	for {
		rune := readRune(r)
		if rune == -1 || isWhiteSpace(rune) || rune == ')' {
			r.UnreadRune()
			return s
		}
		s = s + string(rune)
	}

	return matchNumer(s)
}
开发者ID:shxiao,项目名称:clogure,代码行数:14,代码来源:read.go

示例12: scanDigits

func scanDigits(rs io.RuneScanner) (string, error) {
	var s string
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			return s, nil
		case err != nil:
			return "", err
		case !unicode.IsDigit(r):
			return s, rs.UnreadRune()
		default:
			s += string(r)
		}
	}
}
开发者ID:chai2010,项目名称:T,代码行数:15,代码来源:addr.go

示例13: ScanDelimited

func ScanDelimited(r io.RuneScanner, start, end rune, escapes map[rune]rune, escapesPassThru bool) ([]byte, error) {

	// Scan start delimiter.
	if ch, _, err := r.ReadRune(); err != nil {
		return nil, err
	} else if ch != start {
		return nil, fmt.Errorf("expected %s; found %s", string(start), string(ch))
	}

	var buf bytes.Buffer
	for {
		ch0, _, err := r.ReadRune()
		if ch0 == end {
			return buf.Bytes(), nil
		} else if err != nil {
			return buf.Bytes(), err
		} else if ch0 == '\n' {
			return nil, errors.New("delimited text contains new line")
		} else if ch0 == '\\' {
			// If the next character is an escape then write the escaped char.
			// If it's not a valid escape then return an error.
			ch1, _, err := r.ReadRune()
			if err != nil {
				return nil, err
			}

			c, ok := escapes[ch1]
			if !ok {
				if escapesPassThru {
					// Unread ch1 (char after the \)
					_ = r.UnreadRune()
					// Write ch0 (\) to the output buffer.
					_, _ = buf.WriteRune(ch0)
					continue
				} else {
					buf.Reset()
					_, _ = buf.WriteRune(ch0)
					_, _ = buf.WriteRune(ch1)
					return buf.Bytes(), errBadEscape
				}
			}

			_, _ = buf.WriteRune(c)
		} else {
			_, _ = buf.WriteRune(ch0)
		}
	}
}
开发者ID:subsilent,项目名称:kappa,代码行数:48,代码来源:utils.go

示例14: seqReader

func seqReader(rune int, r io.RuneScanner) interface{} {
	seq := make([]interface{}, 0)
	for {
		nrune, _, err := r.ReadRune()
		for isWhiteSpace(nrune) {
			nrune, _, err = r.ReadRune()
		}
		if err != nil || string(nrune) == ")" {
			return seq
		}
		r.UnreadRune()
		fmt.Println(seq)
		seq = append(seq, read(r))
	}
	return seq
}
开发者ID:shxiao,项目名称:clogure,代码行数:16,代码来源:read.go

示例15: ScanBareIdent

// ScanBareIdent reads bare identifier from a rune reader.
func ScanBareIdent(r io.RuneScanner) string {
	// Read every ident character into the buffer.
	// Non-ident characters and EOF will cause the loop to exit.
	var buf bytes.Buffer
	for {
		ch, _, err := r.ReadRune()
		if err != nil {
			break
		} else if !isIdentChar(ch) {
			r.UnreadRune()
			break
		} else {
			_, _ = buf.WriteRune(ch)
		}
	}
	return buf.String()
}
开发者ID:go-chef,项目名称:metadata-parser,代码行数:18,代码来源:scanner.go


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