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


Golang io.RuneScanner類代碼示例

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


在下文中一共展示了RuneScanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: readRune

func readRune(r io.RuneScanner) int {
	rune, _, err := r.ReadRune()
	if err != nil {
		return -1
	}
	return rune
}
開發者ID:shxiao,項目名稱:clogure,代碼行數:7,代碼來源:read.go

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

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

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

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

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

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

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

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

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

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

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

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

示例14: scan

func (d *Dec) scan(r io.RuneScanner) error {
	d.coef.hi = 0
	d.coef.lo = 0
	d.scale = 0
	ch, _, err := r.ReadRune()
	if err != nil {
		return err
	}
	var neg bool
	switch ch {
	case '-':
		neg = true
	case '+':
	default:
		r.UnreadRune()
	}
	var dec bool
	for {
		ch, _, err = r.ReadRune()
		if err == io.EOF {
			goto ExitLoop
		}
		if err != nil {
			return err
		}
		switch {
		case ch == '.':
			if dec {
				r.UnreadRune()
				goto ExitLoop
			}
			dec = true
		case ch >= '0' && ch <= '9':
			d.coef.Mul(&d.coef, intTen)
			var z Int128
			z.SetInt64(int64(ch - '0'))
			d.coef.Add(&d.coef, &z)
			if dec {
				d.scale++
			}
		default:
			r.UnreadRune()
			goto ExitLoop
		}
	}
ExitLoop:
	if neg {
		d.Neg(d)
	}
	return nil
}
開發者ID:jmptrader,項目名稱:decimal-1,代碼行數:51,代碼來源:dec.go

示例15: parseMarkRune

func parseMarkRune(rs io.RuneScanner) (rune, error) {
	for {
		switch r, _, err := rs.ReadRune(); {
		case err == io.EOF:
			return '.', nil
		case err != nil:
			return 0, err
		case unicode.IsSpace(r):
			continue
		default:
			return r, nil
		}
	}
}
開發者ID:chai2010,項目名稱:T,代碼行數:14,代碼來源:edit.go


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