strings

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package strings ports numpy.strings: elementwise string operations over an N-dimensional array of Go strings. StrArray mirrors numgo.Array's view model (shape/strides/offset over shared data); all index arithmetic goes through internal/nditer (design.md P0-1).

Divergences from numpy.strings:

  • Broadcasting: not implemented. numpy broadcasts string operands, but Go callers pre-expand scalars via BroadcastTo; elementwise ops require equal shapes.
  • Mod, Encode, Decode: skipped (format-spec machinery; Go strings are UTF-8 already). Join/Split/SplitLines are kept even though numpy.strings removed them (numpy.char still has them).
  • Contains: a Go idiom numpy lacks, provided for parity with the strings package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atoi

func Atoi(a *StrArray) ([]int64, error)

Pure: Atoi converts every element with strconv.ParseInt base 10 into a plain []int64 in C order — int64 is not a numgo.Number, so no Array type exists for it (same precedent as the random package's arrayI). The error reports the C-order linear index of the first failing element.

func ParseFloat

func ParseFloat(a *StrArray) (*numgo.Array[float64], error)

Pure: ParseFloat converts every element with strconv.ParseFloat 64-bit. The returned array shares the input's shape; the error reports the C-order linear index of the first failing element.

Types

type ElementError

type ElementError struct {
	Index int
	Err   error
}

ElementError reports the C-order linear index of the element that failed to parse, wrapping strconv's own error text.

func (*ElementError) Error

func (e *ElementError) Error() string

Error formats the failure with the element's linear index.

func (*ElementError) Unwrap

func (e *ElementError) Unwrap() error

Unwrap returns the underlying parse error.

type StrArray

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

StrArray is an N-dimensional strided view over a flat data slice of strings. Strides are in element units. Views share data; use Copy for an independent array.

func Concatenate

func Concatenate(axis int, as ...*StrArray) *StrArray

Pure: Concatenate joins arrays along axis (negative allowed). All dimensions except axis must match exactly. The result is new data.

func FromFloat

func FromFloat(a *numgo.Array[float64], format string) *StrArray

Pure: FromFloat formats every element of a with the format verb (a fmt.Sprintf verb like "%g" or "%.3f") into a new StrArray of the same shape.

func FromSlice

func FromSlice(data []string, shape ...int) *StrArray

Pure: FromSlice returns a new array holding a copy of data. With no shape the result is 1-D; otherwise the element count must match.

func (*StrArray) At

func (a *StrArray) At(coords ...int) string

Pure: At returns the element at coords. It panics if the rank or index is invalid.

func (*StrArray) Capitalize

func (a *StrArray) Capitalize() *StrArray

Pure: Capitalize uppercases the first character and lowercases the rest of each element (numpy semantics).

func (*StrArray) Center

func (a *StrArray) Center(width int) *StrArray

Pure: Center pads each element with spaces on both sides to width; the extra space goes to the right (CPython: left = deficit/2, rounded down).

func (*StrArray) Contains

func (a *StrArray) Contains(sub string) []bool

Pure: Contains reports whether sub occurs in each element. A Go idiom numpy lacks (numpy composes it from find >= 0); documented addition.

func (*StrArray) Copy

func (a *StrArray) Copy() *StrArray

Pure: Copy returns an independent, C-order compact copy of the array.

func (*StrArray) Count

func (a *StrArray) Count(sub string, start, stop int) *StrArray

Pure: Count returns the number of non-overlapping occurrences of sub between start and stop in each element. Bounds are Python-style exclusive-stop when stop >= 0; a negative stop counts from the end (stop = -1 → whole element via the n+1 wrap matching Python's [start:-1] convention).

func (*StrArray) Data

func (a *StrArray) Data() []string

Shares data: Data returns the underlying storage starting at the view offset. For contiguous arrays it reads in C order; for non-contiguous views the element order does NOT match C order — use Ravel().Data() instead. Mutating it affects every array sharing the storage.

func (*StrArray) EndsWith

func (a *StrArray) EndsWith(suffix string, stop int) []bool

Pure: EndsWith reports whether each element ends with suffix before stop. A stop of -1 means the whole element.

func (*StrArray) ExpandTabs

func (a *StrArray) ExpandTabs(tabWidth int) *StrArray

Pure: ExpandTabs replaces each tab with spaces to the next tab stop of tabWidth runes (columns reset at newlines); tabWidth <= 0 removes tabs.

func (*StrArray) Find

func (a *StrArray) Find(sub string, start int) *StrArray

Pure: Find returns the lowest index of sub at or after start in each element, or -1 when absent.

func (*StrArray) Index

func (a *StrArray) Index(sub string, start int) *StrArray

Pure: Index is Find but panics "substring not found" (numpy ValueError wording) if any element lacks sub.

func (*StrArray) IsAlNum

func (a *StrArray) IsAlNum() []bool

Pure: IsAlNum reports whether every character is alphanumeric.

func (*StrArray) IsAlpha

func (a *StrArray) IsAlpha() []bool

Pure: IsAlpha reports whether every character is alphabetic.

func (*StrArray) IsContiguous

func (a *StrArray) IsContiguous() bool

Pure: IsContiguous reports whether the array is laid out in C order.

func (*StrArray) IsDecimal

func (a *StrArray) IsDecimal() []bool

Pure: IsDecimal reports whether every character is a Unicode decimal digit (identical to IsDigit here; Python separates them only for non-Nd digits).

func (*StrArray) IsDigit

func (a *StrArray) IsDigit() []bool

Pure: IsDigit reports whether every character is a Unicode decimal digit.

func (*StrArray) IsEmpty

func (a *StrArray) IsEmpty() []bool

Pure: IsEmpty reports whether each element is the empty string. A Go idiom (Python has no str.isempty); documented addition.

func (*StrArray) IsLower

func (a *StrArray) IsLower() []bool

Pure: IsLower reports whether all cased characters are lowercase and at least one exists.

func (*StrArray) IsNumeric

func (a *StrArray) IsNumeric() []bool

Pure: IsNumeric reports whether every character is numeric (digits, fractions, Roman numerals — Python str.isnumeric semantics).

func (*StrArray) IsSpace

func (a *StrArray) IsSpace() []bool

Pure: IsSpace reports whether every character is whitespace.

func (*StrArray) IsTitle

func (a *StrArray) IsTitle() []bool

Pure: IsTitle reports whether each element is title-cased: cased characters follow uncased ones and vice versa (Python str.istitle; empty → false).

func (*StrArray) IsUpper

func (a *StrArray) IsUpper() []bool

Pure: IsUpper reports whether all cased characters are uppercase and at least one exists.

func (*StrArray) Join

func (a *StrArray) Join(parts []string) *StrArray

Pure: Join joins parts with each element as the separator (numpy.char.join semantics; numpy.strings removed join).

func (*StrArray) LJust

func (a *StrArray) LJust(width int) *StrArray

Pure: LJust left-justifies each element in a field of width (pads right).

func (*StrArray) LStrip

func (a *StrArray) LStrip(chars string) *StrArray

Pure: LStrip removes leading chars (whitespace if empty).

func (*StrArray) Lower

func (a *StrArray) Lower() *StrArray

Pure: Lower lowercases every element.

func (*StrArray) Ndim

func (a *StrArray) Ndim() int

Pure: Ndim returns the number of dimensions.

func (*StrArray) Partition

func (a *StrArray) Partition(sep string) [][]string

Pure: Partition splits each element at the first sep into a []string{head, sep, tail}; a missing sep yields {elem, "", ""} (numpy semantics).

func (*StrArray) RFind

func (a *StrArray) RFind(sub string, stop int) *StrArray

Pure: RFind returns the highest index of sub before stop in each element, or -1 when absent. A stop of -1 searches the whole element.

func (*StrArray) RIndex

func (a *StrArray) RIndex(sub string, stop int) *StrArray

Pure: RIndex is RFind but panics "substring not found" if any element lacks sub.

func (*StrArray) RJust

func (a *StrArray) RJust(width int) *StrArray

Pure: RJust right-justifies each element in a field of width (pads left).

func (*StrArray) RPartition

func (a *StrArray) RPartition(sep string) [][]string

Pure: RPartition splits each element at the last sep into []string{head, sep, tail}; a missing sep yields {"", "", elem}.

func (*StrArray) RStrip

func (a *StrArray) RStrip(chars string) *StrArray

Pure: RStrip removes trailing chars (whitespace if empty).

func (*StrArray) Ravel

func (a *StrArray) Ravel() *StrArray

View: Ravel flattens to 1-D in C order. A contiguous array returns a view sharing data; a non-contiguous array is copied first, so sharing is not guaranteed.

func (*StrArray) Repeat

func (a *StrArray) Repeat(count int) *StrArray

Pure: Repeat repeats each element count times (numpy.strings.multiply). Negative counts panic (numpy ValueError).

func (*StrArray) Replace

func (a *StrArray) Replace(old, new string, n int) *StrArray

Pure: Replace replaces up to n occurrences of old with new in each element (n < 0 means all).

func (*StrArray) Reshape

func (a *StrArray) Reshape(shape ...int) *StrArray

View: Reshape views the array with a new shape when the data is contiguous; a non-contiguous array is copied first, so the result may not share data. At most one dimension may be -1 and is inferred.

func (*StrArray) Set

func (a *StrArray) Set(coords []int, v string) *StrArray

In-place: Set writes v at coords in place and returns a for chaining.

func (*StrArray) Shape

func (a *StrArray) Shape() []int

Pure: Shape returns a copy of the array's dimensions.

func (*StrArray) Size

func (a *StrArray) Size() int

Pure: Size returns the total number of elements.

func (*StrArray) Slice

func (a *StrArray) Slice(rs ...numgo.Range) *StrArray

View: Slice views a strided sub-array. Ranges cover the leading axes; trailing axes not mentioned are taken whole (numpy a[:2] semantics), so a zero Range or a missing axis means the entire axis. The result shares data. Bounds follow numpy: negative indices count from the end and a negative Step reverses the axis.

func (*StrArray) SliceVal

func (a *StrArray) SliceVal(start, stop int) *StrArray

Pure: SliceVal slices each element by Python-style [start:stop] byte bounds; negative values count from the end. Named SliceVal because StrArray.Slice is the view op (numpy.strings.slice).

func (*StrArray) Split

func (a *StrArray) Split(sep string) [][]string

Pure: Split splits each element at sep into a [][]string in C order. numpy strings removed split from its namespace (numpy.char keeps it); provided for chararray parity.

func (*StrArray) SplitLines

func (a *StrArray) SplitLines() [][]string

Pure: SplitLines splits each element at line boundaries (\n, \r\n, \r) into a [][]string in C order, dropping the trailing empty piece a final newline would produce (Python str.splitlines semantics).

func (*StrArray) StartsWith

func (a *StrArray) StartsWith(prefix string, start int) []bool

Pure: StartsWith reports whether each element starts with prefix from start.

func (*StrArray) Strip

func (a *StrArray) Strip(chars string) *StrArray

Pure: Strip removes leading and trailing chars (whitespace if empty).

func (*StrArray) Swapcase

func (a *StrArray) Swapcase() *StrArray

Pure: Swapcase swaps the case of every character.

func (*StrArray) Title

func (a *StrArray) Title() *StrArray

Pure: Title uppercases the first character of each word and lowercases the rest, matching numpy.strings.title: a character starts a word when the preceding character is uncased, so "don't do" → "Don'T Do". This equals Go's deprecated strings.Title and diverges from modern-English intuition; numpy wording is authoritative.

func (*StrArray) Translate

func (a *StrArray) Translate(table map[rune]rune) *StrArray

Pure: Translate maps runes through the table (absent runes pass through). numpy's delete parameter has no map representation — delete via Replace with "". Documented simplification.

func (*StrArray) Transpose

func (a *StrArray) Transpose(axes ...int) *StrArray

View: Transpose views the array with its axes permuted. With no axes it reverses them (numpy .T). The result shares data.

func (*StrArray) Upper

func (a *StrArray) Upper() *StrArray

Pure: Upper uppercases every element. Go's unicode simple case mapping keeps ß as ß, while numpy (full case mapping) yields "SS" — documented divergence; fixing it would need a special-case table, out of scope for the core.

func (*StrArray) ZFill

func (a *StrArray) ZFill(width int) *StrArray

Pure: ZFill pads each element with leading zeros to width, keeping a leading '+'/'-' sign ahead of the zeros.

Jump to

Keyboard shortcuts

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