View Source Sourceror.Code.String (Sourceror v1.11.0)

Utilities for working with strings.

Summary

Functions

Returns true if the node represents a literal string, false otherwise.

Updates a node representing a string with the result of the given function.

Functions

@spec string?(Sourceror.Zipper.t()) :: boolean()

Returns true if the node represents a literal string, false otherwise.

Examples

iex> zipper = Sourceror.parse_string!("\"hello\"") |> Sourceror.Zipper.zip()
iex> Sourceror.Code.String.string?(zipper)
true
iex> zipper = Sourceror.parse_string!("123") |> Sourceror.Zipper.zip()
iex> Sourceror.Code.String.string?(zipper)
false

See also update_string/2.

Link to this function

update_string(zipper, func)

View Source
@spec update_string(Sourceror.Zipper.t(), (String.t() -> {:ok, String.t()} | :error)) ::
  {:ok, Sourceror.Zipper.t()} | :error

Updates a node representing a string with the result of the given function.

Examples

iex> zipper = Sourceror.parse_string!("\"hello\"") |> Sourceror.Zipper.zip()
iex> {:ok, zipper} = Sourceror.Code.String.update_string(zipper, fn str -> {:ok, str <> " world"} end)
iex> Sourceror.to_string(zipper.node)
"\"hello world\""

See also string?/1.