View Source Hologram.Commons.StringUtils (hologram v0.2.0)

Summary

Functions

Prepends the prefix to the given string.

Prepends the prefix to the given string if the string is not empty.

Checks whether a string starts with a lowercase letter.

Wraps the given string with one string on the left side and another string on the right side.

Functions

prepend(str, prefix)

@spec prepend(String.t(), String.t()) :: String.t()

Prepends the prefix to the given string.

Examples

iex> prepend("abc", "xyz")
"xyzabc"

prepend_if_not_empty(str, prefix)

@spec prepend_if_not_empty(String.t(), String.t()) :: String.t()

Prepends the prefix to the given string if the string is not empty.

Examples

iex> prepend_if_not_empty("abc", "xyz")
"xyzabc"

iex> prepend_if_not_empty("", "xyz")
""

starts_with_lowercase?(str)

@spec starts_with_lowercase?(String.t()) :: boolean()

Checks whether a string starts with a lowercase letter.

  • This function uses the String.next_grapheme/1 function to extract the first letter of the string.
  • It converts the first letter to lowercase using String.downcase/1 and compares it with the original first letter to determine if it is lowercase.
  • If the input string is empty, the function returns false.

Parameters

  • str - The input string to be checked.

Returns

Returns true if the string starts with a lowercase letter, and false otherwise.

Examples

iex> starts_with_lowercase?("Hello")
false

iex> starts_with_lowercase?("world")
true

wrap(str, left, right)

@spec wrap(String.t(), String.t(), String.t()) :: String.t()

Wraps the given string with one string on the left side and another string on the right side.

Examples

iex> wrap("ab", "cd", "ef")
"cdabef"