package corestrings

import "github.com/purpleidea/mgmt/lang/core/strings"

Index

Constants

const (
	// ModuleName is the prefix given to all the functions in this module.
	ModuleName = "strings"
)

Functions

func JoinNonempty

func JoinNonempty(ctx context.Context, input []types.Value) (types.Value, error)

JoinNonempty behaves exactly like the regular string join, except it filters out empty elements first. Since this behaviour is commonly useful when writing scripts, we include it as a built-in primitive, since it is also cheaper than running the graph changing, filter function. TODO: compiler optimization: find patterns where someone used the filter function as previously described, and replace it with this implementation.

func LeftPad

func LeftPad(ctx context.Context, input []types.Value) (types.Value, error)

LeftPad adds multiples of the pad string to the left of the input string until it reaches a minimum length. If the padding string is not an integer multiple of the missing length to pad, then this will overshoot. It is better to overshoot than to undershoot because if you need a string of a precise length, then it's easier to truncate the result, rather than having to pad even more. Most scenarios pad with a single char meaning this is not even an issue.

func RightPad

func RightPad(ctx context.Context, input []types.Value) (types.Value, error)

RightPad adds multiples of the pad string to the right of the input string until it reaches a minimum length. If the padding string is not an integer multiple of the missing length to pad, then this will overshoot. It is better to overshoot than to undershoot because if you need a string of a precise length, then it's easier to truncate the result, rather than having to pad even more. Most scenarios pad with a single char meaning this is not even an issue.

func Split

func Split(ctx context.Context, input []types.Value) (types.Value, error)

Split splits the input string using the separator and returns the segments as a list.

func SubStr

func SubStr(ctx context.Context, input []types.Value) (types.Value, error)

SubStr returns a substring of the input string from low to high.

func ToLower

func ToLower(ctx context.Context, input []types.Value) (types.Value, error)

ToLower turns a string to lowercase.

Source Files

join_nonempty.go pad.go split.go strings.go substring.go to_lower.go

Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
6 packages
Last checked
4 days ago

Tools for package owners.