Skip to content

Space.sh module to analyze and manipulate on strings.

License

Notifications You must be signed in to change notification settings

space-sh/string

Repository files navigation

String manipulation module | build status

Functions

STRING_TRIM()

Trim whitespace (spaces and tabs) from a string left and right.

Parameters:

  • $1: the name of the variable to trim.

Expects:

  • $1: The variable should be set with the value to trim.
  • This variable is directly trimmed on.

Returns:

  • non-zero if string error

STRING_SUBST()

Substitute text in place.

Parameters:

  • $1: variable name to substitute in.
  • $2: text to substitute away.
  • $3: text to insert in place.
  • $4: global, set to "1" to substitute all occurrences.

STRING_INDEXOF()

Find the first index of sub string in string.

Parameters:

  • $1: sub string to search for.
  • $2: string to search in.
  • $3: optional variable name to store index value to. -1 when sub string not found.

Returns:

  • 0: if sub string found, 1 otherwise.

STRING_ESCAPE()

Escape in place up the occurrences of quotes, dollar signs, parenthesis, etc.

It is optional which of ", $, (, ), <, >, | and & to escape.

Parameters:

  • $1: Name of the variable to escape up, in place.
  • $2: Optional which characters to escape, defaults to '"$'.

_STRING_ESCAPE()

Helper function.

Parameters:

  • $1: name of variable to escape
  • $2: character to escape.

STRING_ITEM_COUNT()

Count all items in a string, split on current IFS.

Parameters:

  • $1: string to count items in.
  • $2: variable name to store count in

STRING_ITEM_GET()

Get an item in a string by it's index,
where string is split on the current IFS.

Parameters:

  • $1: string to get item from.
  • $2: index of item to get.
  • $3: variable name to store item to.

STRING_ITEM_INDEXOF()

Find the first index of item in string.

Parameters:

  • $1: string to lookup item in.
  • $2: string of item to find.
  • $3: variable name to store item index in, -1 when not found.

Returns:

  • 0: if item found, 1 otherwise.

About

Space.sh module to analyze and manipulate on strings.

Resources

License

Stars

Watchers

Forks

Languages