View Source PhpAssocMap.Utils (PhpAssocMap v3.0.0)

Helper functions to work with strings

Summary

Functions

Converts a key and a value into an associative array association using arrow

Convert a string for a literal string by escaping quotes and wrapping into them

Wraps a value inside specified string.

Types

@type raw_value() ::
  binary()
  | boolean()
  | integer()
  | float()
  | nil
  | :open_bracket
  | {:raw, binary()}

Functions

@spec associate(raw_value(), raw_value()) :: binary()

Converts a key and a value into an associative array association using arrow

Exemples

iex> PhpAssocMap.Utils.associate("my_key", "Some value")
"'my_key'=>'Some value'"
@spec stringify(raw_value()) :: binary()

Convert a string for a literal string by escaping quotes and wrapping into them

Exemples

iex> PhpAssocMap.Utils.stringify("Jon's")
"'Jon\\'s'"

iex> PhpAssocMap.Utils.stringify(true)
"true"

iex> PhpAssocMap.Utils.stringify(24)
"24"

iex> PhpAssocMap.Utils.stringify(24.10)
"24.1"

iex> PhpAssocMap.Utils.stringify(nil)
"null"

iex> PhpAssocMap.Utils.stringify(:open_bracket)
"["
@spec wrap(binary(), binary()) :: binary()

Wraps a value inside specified string.

Using wrap/2 will wrap both end using the same string. Using the wrap/3 will wrap left with second parameter and right with third

Exemples

iex> PhpAssocMap.Utils.wrap("house", "*")
"*house*"

iex> PhpAssocMap.Utils.wrap("house", "{", "}")
"{house}"
Link to this function

wrap(string, left, right)

View Source
@spec wrap(binary(), binary(), binary()) :: binary()