text

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 6 Imported by: 60

Documentation

Overview

Package text provides common text handling capabilities.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LineNumber

func LineNumber(s string) string

LineNumber prefixes returns s prefixed with a line number for each line, starting from 1. Useful for adding line numbers to source.

Example
package main

import (
	"fmt"

	"github.com/google/gapid/core/text"
)

func main() {
	fmt.Println(text.LineNumber(
		`This is some text.
That will have line numbers
added to it.

You may notice that the
line numbers will be of
a fixed width
so that text doesn't move
off to the right once
you get to the 10th line.`))
}
Output:

 1: This is some text.
 2: That will have line numbers
 3: added to it.
 4:
 5: You may notice that the
 6: line numbers will be of
 7: a fixed width
 8: so that text doesn't move
 9: off to the right once
10: you get to the 10th line.

func Quote added in v1.1.0

func Quote(s []string) []string

Quote takes a slice of strings, and returns a slice where each string has been quoted and escaped to pass down to the command-line.

func SplitArgs

func SplitArgs(s string) []string

SplitArgs splits and returns the string s separated by non-quoted whitespace. Useful for splitting a string containing multiple command-line parameters.

Example
package main

import (
	"fmt"

	"github.com/google/gapid/core/text"
)

func main() {
	for i, s := range text.SplitArgs(`--cat=meow -dog woof "fish"="\"blub blub\""`) {
		fmt.Printf("%v: '%v'\n", i, s)
	}
}
Output:

0: '--cat=meow'
1: '-dog'
2: 'woof'
3: 'fish="blub blub"'

func Writer

func Writer(to func(string) error) io.WriteCloser

Writer returns a io writer that collects lines out of a stream and hands them to the supplied function.

Types

type LimitWriter

type LimitWriter struct {
	// contains filtered or unexported fields
}

LimitWriter limits the length of string written through it.

func NewLimitWriter

func NewLimitWriter(to io.Writer, limit int, elisionMarker string) *LimitWriter

NewLimitWriter returns an io.Writer that limits the amount of text written through it and optionally adds a marker if it causes the limit to be reached.

func (*LimitWriter) Flush

func (w *LimitWriter) Flush() error

Flush any writes to the underlying stream. It also makes the writer assume the limit has been reached for the purpose of any further writes.

func (*LimitWriter) Write

func (w *LimitWriter) Write(data []byte) (int, error)

Write will write as much of the string as it can to the underlying writer, if he total number of runes written would exceed the limit, the last part of the string is replaced by the elisionMarker. This method may buffer data, you must call Flush for it all to appear in the underlying stream.

Directories

Path Synopsis
Package cases contains functions for Maping strings between various cases (snake, pascal, etc).
Package cases contains functions for Maping strings between various cases (snake, pascal, etc).
Package parse provides support functionality for writing scannerless parsers.
Package parse provides support functionality for writing scannerless parsers.
cst
Package reflow supports rewriting the whitespace in a stream of runes.
Package reflow supports rewriting the whitespace in a stream of runes.

Jump to

Keyboard shortcuts

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