Tomlex.StringHelpers

A set of conveniencies to use with strings.

Source

Summary

booleanize_string(other_string)

Casts the strings "true" and "false" to their boolean counterparts. Returns the string unchanged otherwise

cast_string(string)

Casts a string to the more appropriate elixir type. If the string cannot be casted to any of the valid types for tomlex, it will return the string unchanged

unquote_string(string)

Removes quotes and escaped characters from a string

Types

Functions

booleanize_string(other_string)

Specs:

Casts the strings "true" and "false" to their boolean counterparts. Returns the string unchanged otherwise.

Examples

iex> Tomlex.StringHelpers.booleanize_string("true")
true

iex> Tomlex.StringHelpers.booleanize_string("not boolean")
"not boolean"
Source
cast_string(string)

Specs:

Casts a string to the more appropriate elixir type. If the string cannot be casted to any of the valid types for tomlex, it will return the string unchanged.

Examples

iex> Tomlex.StringHelpers.cast_string("123")
123

iex> Tomlex.StringHelpers.cast_string("123.4")
123.4

iex> Tomlex.StringHelpers.cast_string("false")
false

iex> Tomlex.StringHelpers.cast_string("random string")
"random string"
Source
unquote_string(string)

Specs:

Removes quotes and escaped characters from a string.

Examples

iex> Tomlex.StringHelpers.unquote_string("\"value\"\\n23")
"value\n23"
Source