foreach

package
Version: v0.0.0-...-fb495b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Go Reference

golang.org/x/build/internal/foreach

Package foreach provides allocation-conscious helpers for iterating over lines of text.

Documentation

Overview

Package foreach provides allocation-conscious helpers for iterating over lines of text.

They're factored out into a separate small package primarily to allow them to have allocation-measuring tests that need to run without interference from other goroutine-leaking tests.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Line

func Line(v []byte, f func([]byte) error) error

Line calls f on each line in v, without the trailing '\n'. The final line need not include a trailing '\n'. Returns first non-nil error returned by f.

Example
package main

import (
	"fmt"

	"golang.org/x/build/internal/foreach"
)

func main() {
	v := []byte(`line 1
line 2
line 3


after two blank lines
last line`)
	foreach.Line(v, func(b []byte) error {
		fmt.Printf("%q\n", b)
		return nil
	})

}
Output:

"line 1"
"line 2"
"line 3"
""
""
"after two blank lines"
"last line"

func LineStr

func LineStr(s string, f func(string) error) error

LineStr calls f on each line in s, without the trailing '\n'. The final line need not include a trailing '\n'. Returns first non-nil error returned by f.

LineStr is the string variant of Line.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL