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


Golang Reader.ReadRune方法代码示例

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


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

示例1: quotedWordCutter

func quotedWordCutter(reader *strings.Reader) (string, bool) {
	var buffer bytes.Buffer
	for {
		if reader.Len() <= 0 {
			return "", false
		}
		ch, _, _ := reader.ReadRune()
		if ch != ' ' {
			reader.UnreadRune()
			break
		}
	}
	quote := NULQUOTE
	yenCount := 0
	for reader.Len() > 0 {
		ch, _, _ := reader.ReadRune()
		if yenCount%2 == 0 {
			if quote == NULQUOTE && (ch == '"' || ch == '\'') {
				quote = ch
			} else if quote != NULQUOTE && ch == quote {
				quote = NULQUOTE
			}
		}
		if ch == ' ' && quote == NULQUOTE {
			break
		}
		if ch == '\\' {
			yenCount++
		} else {
			yenCount = 0
		}
		buffer.WriteRune(ch)
	}
	return buffer.String(), true
}
开发者ID:tyochiai,项目名称:nyagos,代码行数:35,代码来源:splitq.go

示例2: nextRune

func nextRune(r *strings.Reader) rune {
	ch, _, err := r.ReadRune()
	if err != nil {
		return utf8.RuneError
	}
	return unicode.ToLower(ch)
}
开发者ID:carriercomm,项目名称:lsp,代码行数:7,代码来源:sort.go

示例3: insertHistory

func insertHistory(buffer *bytes.Buffer, reader *strings.Reader, historyNo int) {
	history1 := conio.DefaultEditor.Histories[historyNo]
	ch, siz, _ := reader.ReadRune()
	if siz > 0 && ch == '^' {
		if len(history1.Word) >= 2 {
			buffer.WriteString(history1.At(1))
		}
	} else if siz > 0 && ch == '$' {
		if len(history1.Word) >= 2 {
			buffer.WriteString(history1.At(-1))
		}
	} else if siz > 0 && ch == '*' {
		if len(history1.Word) >= 2 {
			buffer.WriteString(strings.Join(history1.Word[1:], " "))
		}
	} else if siz > 0 && ch == ':' {
		n, count := atoi_(reader)
		if count <= 0 {
			buffer.WriteRune(':')
		} else if n < len(history1.Word) {
			buffer.WriteString(history1.Word[n])
		}
	} else {
		if siz > 0 {
			reader.UnreadRune()
		}
		buffer.WriteString(history1.Line)
	}
}
开发者ID:tyochiai,项目名称:nyagos,代码行数:29,代码来源:history.go

示例4: uiDraw

func (t *Tree) uiDraw() {
	t.ui.beginDraw()
	defer t.ui.endDraw()

	if t.lines == nil {
		t.Rebuild()
	}

	line := 0
	for y := t.y0; y < t.y1; y++ {
		var reader *strings.Reader
		var item TreeItem
		level := 0
		if line < len(t.lines) {
			item = t.lines[line].Item
			level = t.lines[line].Level
			reader = strings.NewReader(item.String())
		}
		for x := t.x0; x < t.x1; x++ {
			var chr rune = ' '
			fg := t.Fg
			bg := t.Bg
			dx := x - t.x0
			dy := y - t.y0
			if reader != nil && level*2 <= dx {
				if ch, _, err := reader.ReadRune(); err == nil {
					chr = ch
					fg, bg = item.TreeItemStyle(fg, bg, t.active && t.activeLine == dy)
				}
			}
			termbox.SetCell(x, y, chr, termbox.Attribute(fg), termbox.Attribute(bg))
		}
		line++
	}
}
开发者ID:dardevelin,项目名称:barnard,代码行数:35,代码来源:tree.go

示例5: collectQuotation

func collectQuotation(r *strings.Reader) *Quotation {
	var buffer bytes.Buffer
	for ch, _, err := r.ReadRune(); err == nil && ch != ']'; ch, _, err = r.ReadRune() {
		buffer.WriteRune(ch)
	}

	parsedTokens := tokenize(buffer.String())

	return &Quotation{*parsedTokens}
}
开发者ID:zacbrown,项目名称:throf,代码行数:10,代码来源:interpreter.go

示例6: Get

// Get the Trie at the end of a strings.Reader
func (t *Trie) Get(s *strings.Reader) *Trie {
	rune, _, err := s.ReadRune()
	if err != nil {
		// We have reached EOF
		return t
	}
	t = t.children[rune]
	if t == nil {
		return nil
	}
	return t.Get(s)
}
开发者ID:sbuss,项目名称:gospell,代码行数:13,代码来源:trie.go

示例7: tokenize

func tokenize(mode int, maxTokenSize int, str *strings.Reader, l int, token string, buffer []string) []string {
	ch, _, err := str.ReadRune()
	if err == io.EOF {
		if l > 0 {
			buffer = append(buffer, token)
		}
		return buffer
	} else {
		switch mode {
		case apostrophe:
			if isLetter(ch) {
				return tokenize(normal, maxTokenSize, str, l+2, token+"'"+string(ch), buffer)
			} else {
				buffer = append(buffer, token)
				return tokenize(start, maxTokenSize, str, 0, "", buffer)
			}
		case start:
			if isLetter(ch) {
				return tokenize(normal, maxTokenSize, str, l+1, token+string(ch), buffer)
			} else if isCJK(ch) {
				buffer = append(buffer, string(ch))
				return tokenize(start, maxTokenSize, str, 0, "", buffer)
			} else {
				return tokenize(start, maxTokenSize, str, 0, "", buffer)
			}
		case skip:
			if isLetter(ch) || ch == '\'' {
				return tokenize(skip, maxTokenSize, str, l+1, token, buffer)
			} else {
				return tokenize(start, maxTokenSize, str, 0, "", buffer)
			}
		default:
			if isLetter(ch) {
				if l+1 > maxTokenSize {
					log.Printf("Token is too long: “%v”, skipping it", token)
					return tokenize(skip, maxTokenSize, str, l+1, token, buffer)
				}
				return tokenize(normal, maxTokenSize, str, l+1, token+string(ch), buffer)
			} else if ch == '\'' && l > 0 {
				return tokenize(apostrophe, maxTokenSize, str, l, token, buffer)
			} else {
				if l > 0 {
					buffer = append(buffer, token)
				}
				return tokenize(start, maxTokenSize, str, 0, "", buffer)
			}
		}
	}
}
开发者ID:vspy,项目名称:gosearch,代码行数:49,代码来源:processing.go

示例8: Insert

// Insert a strings.Reader into the Trie
func (t *Trie) Insert(s *strings.Reader) {
	rune, _, err := s.ReadRune()
	if err != nil {
		// We have reached EOF
		t.leaf = true
		return
	}

	child := t.children[rune]
	if child == nil {
		child = NewTrie()
		t.children[rune] = child
	}
	child.Insert(s)
}
开发者ID:sbuss,项目名称:gospell,代码行数:16,代码来源:trie.go

示例9: addRunes

// Internal function: adds items to the trie, reading runes from a strings.Reader.  It returns
// the leaf node at which the addition ends.
func (p *Trie) addRunes(r *strings.Reader) *Trie {
	rune, _, err := r.ReadRune()
	if err != nil {
		p.leaf = true
		return p
	}

	n := p.children[rune]
	if n == nil {
		n = NewTrie()
		p.children[rune] = n
	}

	// recurse to store sub-runes below the new node
	return n.addRunes(r)
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:18,代码来源:trie.go

示例10: atoi_

func atoi_(reader *strings.Reader) (int, int) {
	n := 0
	count := 0
	for reader.Len() > 0 {
		ch, _, _ := reader.ReadRune()
		index := strings.IndexRune("0123456789", ch)
		if index >= 0 {
			n = n*10 + index
			count++
		} else {
			reader.UnreadRune()
			break
		}
	}
	return n, count
}
开发者ID:tyochiai,项目名称:nyagos,代码行数:16,代码来源:history.go

示例11: includes

// Internal string inclusion function.
func (p *Trie) includes(r *strings.Reader) *Trie {
	rune, _, err := r.ReadRune()
	if err != nil {
		if p.leaf {
			return p
		}
		return nil
	}

	child, ok := p.children[rune]
	if !ok {
		return nil // no node for this rune was in the trie
	}

	// recurse down to the next node with the remainder of the string
	return child.includes(r)
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:18,代码来源:trie.go

示例12: removeRunes

// Internal string removal function.  Returns true if this node is empty following the removal.
func (p *Trie) removeRunes(r *strings.Reader) bool {
	rune, _, err := r.ReadRune()
	if err != nil {
		// remove value, remove leaf flag
		p.value = nil
		p.leaf = false
		return len(p.children) == 0
	}

	child, ok := p.children[rune]
	if ok && child.removeRunes(r) {
		// the child is now empty following the removal, so prune it
		p.children[rune] = nil, false
	}

	return len(p.children) == 0
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:18,代码来源:trie.go

示例13: MatchReader

func (n *Node) MatchReader(reader *strings.Reader) bool {
	if reader.Len() == 0 && n.Terminal {
		return true
	}

	r, _, err := reader.ReadRune()

	if err != nil {
		fmt.Println("Bad rune")
	}

	next, ok := n.Next(r)

	if !ok {
		return false
	}

	return next.MatchReader(reader)
}
开发者ID:aweeks,项目名称:GoRegex,代码行数:19,代码来源:dfa.go

示例14: uiDraw

func (t *Textview) uiDraw() {
	t.ui.beginDraw()
	defer t.ui.endDraw()

	var reader *strings.Reader
	line := len(t.parsedLines) - 1 - t.CurrentLine
	if line < 0 {
		line = 0
	}
	totalLines := len(t.parsedLines)
	if totalLines == 0 {
		totalLines = 1
	}
	currentScrollLine := t.y1 - 1 - int((float32(t.CurrentLine)/float32(totalLines))*float32(t.y1-t.y0))
	for y := t.y1 - 1; y >= t.y0; y-- {
		if t.parsedLines != nil && line >= 0 {
			reader = strings.NewReader(t.parsedLines[line])
		} else {
			reader = nil
		}
		for x := t.x0; x < t.x1; x++ {
			var chr rune = ' '
			if x == t.x1-1 { // scrollbar
				if y == currentScrollLine {
					chr = '█'
				} else {
					chr = '░'
				}
			} else if x < t.x1-3 {
				if reader != nil {
					if ch, _, err := reader.ReadRune(); err == nil {
						chr = ch
					}
				}
			}
			termbox.SetCell(x, y, chr, termbox.Attribute(t.Fg), termbox.Attribute(t.Bg))
		}
		line--
	}
}
开发者ID:dardevelin,项目名称:barnard,代码行数:40,代码来源:textview.go

示例15: scanToken

func scanToken(rd *strings.Reader) (token string, err error) {
	r, _, err := rd.ReadRune()
	if err != nil {
		return "", err
	}
	if isSplitRune(r) {
		return string(r), nil
	}

	var tok []rune
	for {
		tok = append(tok, r)
		r, _, err = rd.ReadRune()
		if err != nil {
			return "", err
		}
		if isSplitRune(r) {
			rd.UnreadRune()
			return string(tok), nil
		}
	}
}
开发者ID:ironzhang,项目名称:golang,代码行数:22,代码来源:quotes.go


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