crstrings

package
v0.0.0-...-fe658a2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterEmpty

func FilterEmpty(elems []string) []string

FilterEmpty removes empty strings from the given slice.

func If

func If(flag bool, trueValue string) string

If returns the given value if the flag is true, otherwise an empty string.

func IfElse

func IfElse(flag bool, trueValue, falseValue string) string

IfElse returns the value that matches the value of the flag.

func Indent

func Indent(prepend, str string) string

Indent prepends a string to every line of the given string.

If the string ends in a newline, the resulting string also ends in a newline.

func JoinStringers

func JoinStringers[T fmt.Stringer](delim string, args ...T) string

JoinStringers concatenates the string representations of the given fmt.Stringer implementations.

func Lines

func Lines(s string) []string

Lines breaks up the given string into lines.

func LinesSeq

func LinesSeq(s string) iter.Seq[string]

LinesSeq returns an iterator over the lines of the given string.

func MapAndJoin

func MapAndJoin[T any](fn func(T) string, delim string, args ...T) string

MapAndJoin converts each argument to a string using the given function and joins the strings with the given delimiter.

func UnwrapText

func UnwrapText(input string) string

UnwrapText reformats wrapped lines by replacing single newlines with spaces, while preserving blank-line paragraph breaks. This allows defining long strings in a readable fashion.

More specifically:

  • the input string is broken up into lines;
  • each line is trimmed of leading and trailing whitespace;
  • leading or trailing empty lines are discarded;
  • each run of non-empty lines is joined into a single line, with a space separator;
  • resulting single lines are joined with a blank line in-between.

For example: UnwrapText(`

This is a paragraph that
is wrapped on multiple lines.

This is another paragraph.

`) returns "This is a paragraph that is wrapped on multiple lines.\n\nThis is another paragraph."

func WithSep

func WithSep(a string, separator string, b string) string

WithSep prints the strings a and b with the given separator in-between, unless one of the strings is empty (in which case the other string is returned).

Types

This section is empty.

Jump to

Keyboard shortcuts

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