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


Golang RuneScanner.ReadRune方法代码示例

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


在下文中一共展示了RuneScanner.ReadRune方法的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: parseDelimited

// ParseDelimited returns the string
// up to the first unescaped delimiter,
// raw newline (rune 0xA),
// or the end of input.
// A delimiter preceeded by \ is escaped and is non-terminating.
// The letter n preceeded by \ is a newline literal.
func parseDelimited(delim rune, rs io.RuneScanner) (string, error) {
	var s string
	var esc bool
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			return s, nil
		case err != nil:
			return "", err
		case esc && r == delim:
			s += string(delim)
			esc = false
		case r == delim || r == '\n':
			return s, nil
		case !esc && r == '\\':
			esc = true
		case esc && r == 'n':
			s += "\n"
			esc = false
		default:
			if esc {
				s += "\\"
			}
			s += string(r)
			esc = false
		}
	}
}
开发者ID:chai2010,项目名称:T,代码行数:34,代码来源:edit.go

示例3: readStructuredData

// readStructuredData reads a STRUCTURED-DATA (as defined in RFC-5424)
// from `r` and assigns the StructuredData member.
//
// STRUCTURED-DATA = NILVALUE / 1*SD-ELEMENT
// SD-ELEMENT      = "[" SD-ID *(SP SD-PARAM) "]"
// SD-PARAM        = PARAM-NAME "=" %d34 PARAM-VALUE %d34
// SD-ID           = SD-NAME
// PARAM-NAME      = SD-NAME
// PARAM-VALUE     = UTF-8-STRING ; characters '"', '\' and ']' MUST be escaped.
// SD-NAME         = 1*32PRINTUSASCII except '=', SP, ']', %d34 (")
func (m *Message) readStructuredData(r io.RuneScanner) (err error) {
	m.StructuredData = []StructuredData{}

	ch, _, err := r.ReadRune()
	if err != nil {
		return err
	}
	if ch == '-' {
		return nil
	}
	r.UnreadRune()

	for {
		ch, _, err := r.ReadRune()
		if err == io.EOF {
			return nil
		} else if err != nil {
			return err // hard to reach without underlying IO error
		} else if ch == ' ' {
			r.UnreadRune()
			return nil
		} else if ch == '[' {
			r.UnreadRune()
			sde, err := readSDElement(r)
			if err != nil {
				return err
			}
			m.StructuredData = append(m.StructuredData, sde)
		} else {
			return BadFormat("StructuredData")
		}
	}
}
开发者ID:leavengood,项目名称:rfc5424,代码行数:43,代码来源:unmarshal.go

示例4: parseCmd

func parseCmd(rs io.RuneScanner) (string, error) {
	if err := skipSpace(rs); err != nil {
		return "", err
	}
	var esc bool
	var cmd string
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			return cmd, nil
		case err != nil:
			return "", nil
		case r == '\n':
			return cmd, nil
		case r == '\\':
			esc = true
		case esc && r == 'n':
			cmd += "\n"
			esc = false
		default:
			if esc {
				cmd += "\\"
			}
			cmd += string(r)
			esc = false
		}
	}
}
开发者ID:chai2010,项目名称:T,代码行数:28,代码来源:edit.go

示例5: ReadChar

// like in.ReadRune() but ignore all leading whitespace.
func ReadChar(in io.RuneScanner) (r rune, size int, err error) {
	r, size, err = in.ReadRune()
	for unicode.IsSpace(r) && err == nil {
		r, size, err = in.ReadRune()
	}
	return
}
开发者ID:siteshen,项目名称:go-practice,代码行数:8,代码来源:lisp.go

示例6: readSDElement

// readSDElement reads an SD-ELEMENT as defined by RFC-5424
//
// SD-ELEMENT      = "[" SD-ID *(SP SD-PARAM) "]"
// SD-PARAM        = PARAM-NAME "=" %d34 PARAM-VALUE %d34
// SD-ID           = SD-NAME
// PARAM-NAME      = SD-NAME
// PARAM-VALUE     = UTF-8-STRING ; characters '"', '\' and ']' MUST be escaped.
// SD-NAME         = 1*32PRINTUSASCII except '=', SP, ']', %d34 (")
func readSDElement(r io.RuneScanner) (element StructuredData, err error) {
	ch, _, err := r.ReadRune()
	if err != nil {
		return element, err // hard to reach without underlying IO error
	}
	if ch != '[' {
		return element, BadFormat("StructuredData[]") // unreachable
	}
	element.ID, err = readSdID(r)
	if err != nil {
		return element, err
	}
	for {
		ch, _, err := r.ReadRune()
		if err != nil {
			return element, err
		} else if ch == ']' {
			return element, nil
		} else if ch == ' ' {
			param, err := readSdParam(r)
			if err != nil {
				return element, err
			}
			element.Parameters = append(element.Parameters, *param)
		} else {
			return element, BadFormat("StructuredData[]")
		}
	}
}
开发者ID:leavengood,项目名称:rfc5424,代码行数:37,代码来源:unmarshal.go

示例7: readPriority

// readPriority reads the PRI as defined in RFC-5424 and assigns Severity and
// Facility accordingly.
func (m *Message) readPriority(r io.RuneScanner) error {
	ch, _, err := r.ReadRune()
	if err != nil {
		return err
	}
	if ch != '<' {
		return BadFormat("Priority")
	}

	rv := &bytes.Buffer{}
	for {
		ch, _, err := r.ReadRune()
		if err != nil {
			return err
		}
		if unicode.IsDigit(ch) {
			rv.WriteRune(ch)
			continue
		}
		if ch != '>' {
			return BadFormat("Priority")
		}

		// We have a complete integer expression
		priority, err := strconv.ParseInt(string(rv.Bytes()), 10, 32)
		if err != nil {
			return BadFormat("Priority")
		}
		m.Priority = int(priority)
		return nil

	}
}
开发者ID:leavengood,项目名称:rfc5424,代码行数:35,代码来源:unmarshal.go

示例8: readRune

func readRune(r io.RuneScanner) int {
	rune, _, err := r.ReadRune()
	if err != nil {
		return -1
	}
	return rune
}
开发者ID:shxiao,项目名称:clogure,代码行数:7,代码来源:read.go

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

示例10: readSpace

// readSpace reads a single space
func readSpace(r io.RuneScanner) error {
	ch, _, err := r.ReadRune()
	if err != nil {
		return err
	}
	if ch != ' ' {
		return BadFormat("expected space")
	}
	return nil
}
开发者ID:leavengood,项目名称:rfc5424,代码行数:11,代码来源:unmarshal.go

示例11: readVersion

// readVersion reads the version string fails if it isn't `1`
func (m *Message) readVersion(r io.RuneScanner) error {
	ch, _, err := r.ReadRune()
	if err != nil {
		return err
	}
	if ch != '1' {
		return BadFormat("Version")
	}
	return nil
}
开发者ID:leavengood,项目名称:rfc5424,代码行数:11,代码来源:unmarshal.go

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

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

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

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


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