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


Golang strings.Reader类代码示例

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


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

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

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

func sum(stream *strings.Reader) (s int) {
	v, err := stream.ReadByte()
	for ; v != 0 && err != os.EOF; v, err = stream.ReadByte() {
		s += int(v)
	}

	return
}
开发者ID:dgquintas,项目名称:my-code-samples,代码行数:8,代码来源:brute.go

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

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

示例8: applyHeadersToRequest

func (s *GitUploadPackService) applyHeadersToRequest(req *http.Request, content *strings.Reader) {
	req.Header.Add("User-Agent", "git/1.0")
	req.Header.Add("Host", "github.com")

	if content == nil {
		req.Header.Add("Accept", "*/*")
	} else {
		req.Header.Add("Accept", "application/x-git-upload-pack-result")
		req.Header.Add("Content-Type", "application/x-git-upload-pack-request")
		req.Header.Add("Content-Length", string(content.Len()))
	}
}
开发者ID:johnkewforks,项目名称:go-git,代码行数:12,代码来源:git_upload_pack.go

示例9: Example_reset

// In performance critical applications, Reset can be used to discard the
// current compressor or decompressor state and reinitialize them quickly
// by taking advantage of previously allocated memory.
func Example_reset() {
	proverbs := []string{
		"Don't communicate by sharing memory, share memory by communicating.\n",
		"Concurrency is not parallelism.\n",
		"The bigger the interface, the weaker the abstraction.\n",
		"Documentation is for users.\n",
	}

	var r strings.Reader
	var b bytes.Buffer
	buf := make([]byte, 32<<10)

	zw, err := flate.NewWriter(nil, flate.DefaultCompression)
	if err != nil {
		log.Fatal(err)
	}
	zr := flate.NewReader(nil)

	for _, s := range proverbs {
		r.Reset(s)
		b.Reset()

		// Reset the compressor and encode from some input stream.
		zw.Reset(&b)
		if _, err := io.CopyBuffer(zw, &r, buf); err != nil {
			log.Fatal(err)
		}
		if err := zw.Close(); err != nil {
			log.Fatal(err)
		}

		// Reset the decompressor and decode to some output stream.
		if err := zr.(flate.Resetter).Reset(&b, nil); err != nil {
			log.Fatal(err)
		}
		if _, err := io.CopyBuffer(os.Stdout, zr, buf); err != nil {
			log.Fatal(err)
		}
		if err := zr.Close(); err != nil {
			log.Fatal(err)
		}
	}

	// Output:
	// Don't communicate by sharing memory, share memory by communicating.
	// Concurrency is not parallelism.
	// The bigger the interface, the weaker the abstraction.
	// Documentation is for users.
}
开发者ID:Harvey-OS,项目名称:go,代码行数:52,代码来源:example_test.go

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

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

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

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

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

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


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