Capstone.Vendor.Sourceror.Code.String (Capstone v0.33.3)

Copy Markdown View Source

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

string?(zipper)

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

Examples

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

See also update_string/2.

update_string(zipper, func)

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

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

Examples

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

See also string?/1.