stringutil

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CutLast added in v0.0.3

func CutLast(s, sep string) (before, after string, found bool)

CutLast is strings.Cut, but cutting at the last occurrence of sep rather than the first.

func CutPrefix

func CutPrefix(s, prefix string) (after string, found bool)

CutPrefix behaves like strings.Cut, but only cuts a prefix, not anywhere in the string.

func CutSuffix added in v0.0.3

func CutSuffix(s, suffix string) (before string, found bool)

CutSuffix behaves like strings.Cut, but only cuts a suffix, not anywhere in the string.

func CutTwice

func CutTwice(s, sep1, sep2 string) (before, between, after string, found bool)

CutTwice calls strings.Cut twice to split s into three strings. If either separator isn't found in s, returns s, "", "", false.

func ReadJSONFile

func ReadJSONFile(path string, i any) (err error)

ReadJSONFile reads one JSON value from the specified file. Supports BOM.

func WriteJSONFile

func WriteJSONFile(path string, i any) (err error)

WriteJSONFile writes one specified value to a file as indented JSON with a trailing newline.

Types

type CRLFToLF added in v0.0.8

type CRLFToLF struct{}

CRLFToLF is a transform.Transformer that converts all occurrences of "\r\n" to "\n", leaving lone '\r' (not followed by '\n') untouched.

func (CRLFToLF) Reset added in v0.0.8

func (CRLFToLF) Reset()

Reset implements transform.Transformer. No state to clear.

func (CRLFToLF) Transform added in v0.0.8

func (CRLFToLF) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform converts CRLF to LF. Implements transform.Transformer. It's careful about chunk boundaries and dst capacity.

Jump to

Keyboard shortcuts

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