tanga v0.7.0 Tanga

Tanga is a collection of string helpers similar to those that can be found in Ruby.

Link to this section Summary

Functions

Centers str in width. If width is greater than the length of str, returns a new String of length width with str centered and padded with padstr; otherwise, returns str

Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case. Incrementing nonalphanumerics uses the underlying character set’s collating sequence

Builds a set of characters from the other_str parameter(s) using the procedure described for String#count. Returns a new string where runs of the same character that occur in this set are replaced by a single character. If no arguments are given, all runs of identical characters are replaced by a single character

Inverts all characters in the given string to uppercase/lowercase accordingly

Link to this section Types

Link to this type t()
t() :: binary()

Link to this section Functions

Link to this function center(string, char_count, chars \\ " ")
center(t(), integer(), t()) :: t()
center(t(), float(), t()) :: t()
center(t(), t(), t()) :: t()

Centers str in width. If width is greater than the length of str, returns a new String of length width with str centered and padded with padstr; otherwise, returns str.

Examples

iex> Tanga.center("fin", 9, "~")
"~~~fin~~~"
Link to this function next(string)
next(t()) :: t()

Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case. Incrementing nonalphanumerics uses the underlying character set’s collating sequence.

If the increment generates a “carry,” the character to the left of it is incremented. This process repeats until there is no carry, adding an additional character if necessary.

Examples

iex> Tanga.next("aaa")
"aab"

iex> Tanga.next("12")
"13"
Link to this function squeeze(string)
squeeze(t()) :: t()

Builds a set of characters from the other_str parameter(s) using the procedure described for String#count. Returns a new string where runs of the same character that occur in this set are replaced by a single character. If no arguments are given, all runs of identical characters are replaced by a single character.

Examples

iex> Tanga.squeeze("aaa")
"a"

iex> Tanga.squeeze("baaabaaa", "a")
"baba"
Link to this function squeeze(string, chars)
squeeze(t(), t()) :: t()
Link to this function swapcase(string)
swapcase(t()) :: t()

Inverts all characters in the given string to uppercase/lowercase accordingly

Examples

iex> Tanga.swapcase("aBcD")
"AbCd"

iex> Tanga.swapcase("aB 123 xPTo")
"Ab 123 XptO"

iex> Tanga.swapcase("oLá")
"OlÁ"