stringsiter

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

stringsiter defines iterator source/collector that corresponds to std library `strings`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk(s string, n int) iter.Seq[string]

Chunk returns an iterator over non overlapping sub strings of n bytes. Sub slicing may cut in mid of utf8 sequences.

func Collect

func Collect(seq iter.Seq[string]) string

Collect concatenates all values form seq to a single string. If size of all value over seq

func CollectHinted added in v0.0.18

func CollectHinted(sizeHint int, seq iter.Seq[string]) string

CollectHinted is like Collect but can hint its internal buffer size to reduce allocation per call.

func CutNewLine

func CutNewLine(s string) (tokUntil int, skipUntil int)

CutNewLine is used with SplitFunc. The input strings will be splitted at "\n". It also skips "\r" preceding "\n".

func CutUpperCase

func CutUpperCase(s string) (tokUntil int, skipUntil int)

CutUpperCase is a split function for a SplitFunc that splits "UpperCasedWords" into "Upper" "Cased" "Words"

func CutWord

func CutWord(s string) (tokUntil int, skipUntil int)

CutWord is a split function for a SplitFunc that returns each space-separated word of text, with surrounding spaces deleted. It will never return an empty string. The definition of space is set by unicode.IsSpace.

func Join

func Join(sep string, seq iter.Seq[string]) string

Join is like Collect but inserts sep between every 2 values from seq, which corresponds to strings.Join.

func JoinHinted added in v0.0.18

func JoinHinted(sizeHint int, sep string, seq iter.Seq[string]) string

JoinHinted is like Join but can hint its internal buffer size to reduce allocation per call.

func RuneChunk

func RuneChunk(s string, n int) iter.Seq[string]

RuneChunk returns an iterator over non overlapping sub strings of n utf8 characters.

func SplitFunc

func SplitFunc(s string, n int, splitFn CutterFunc) iter.Seq[string]

SplitFunc returns an iterator over sub string of s cut by CutterFunc. When n > 0, SplitFunc cuts only n times and the returned iterator yields rest of string after n sub strings, if non empty. The sub strings from the iterator overlaps if splitFn decides so. splitFn is allowed to return negative offsets. In that case the returned iterator immediately yields rest of s and stops iteration.

Types

type CutterFunc

type CutterFunc func(s string) (tokUntil, skipUntil int)

CutterFunc is used with SplitFunc to cut string from head. s[:tokUntil] is yielded through StringsSplitFunc. s[tokUntil:skipUntil] will be ignored.

Jump to

Keyboard shortcuts

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