View Source cure_string_native (cure v0.1.0)

Native Erlang implementations of string operations for Cure.

Provides high-performance string manipulation functions that operate on UTF-8 binaries (String type) and charlists (Charlist type).

Summary

Functions

Get the grapheme at a specific index (0-based). Returns {ok, Grapheme} or {error, out_of_bounds}.

Get the byte size of a string.

Capitalize the first grapheme of a string.

Get a list of Unicode codepoints from a string.

Concatenate two strings efficiently.

Check if a string contains a substring.

Convert string to lowercase (Unicode-aware).

Duplicate a string n times.

Check if a string ends with a given suffix.

Get the first grapheme of a string.

Convert a binary to a string, validating UTF-8. Returns {ok, String} or {error, invalid_utf8}.

Convert a charlist to a UTF-8 string.

Split a string into a list of grapheme clusters.

Check if a string is empty.

Join a list of strings with a separator.

Get the last grapheme of a string.

Get the length of a string in graphemes (Unicode-aware).

Pad a string on the left to a given width.

Pad a string on the right to a given width.

Replace the first occurrence of a pattern.

Replace all occurrences of a pattern.

Reverse a string (Unicode-aware, reverses graphemes).

Extract a substring by grapheme position and length.

Split a string by a pattern.

Split a string at a specific grapheme index.

Check if a string starts with a given prefix.

Convert string to atom.

Convert string to raw binary (identity function for strings).

Convert a UTF-8 string to a charlist.

Trim whitespace from both ends of a string.

Trim whitespace from the left side of a string.

Trim whitespace from the right side of a string.

Convert string to uppercase (Unicode-aware).

Check if a binary is valid UTF-8.

Functions

at(String, Index)

-spec at(binary(), integer()) -> {ok, binary()} | {error, atom()}.

Get the grapheme at a specific index (0-based). Returns {ok, Grapheme} or {error, out_of_bounds}.

byte_size(String)

-spec byte_size(binary()) -> non_neg_integer().

Get the byte size of a string.

capitalize/1

-spec capitalize(binary()) -> binary().

Capitalize the first grapheme of a string.

codepoints(String)

-spec codepoints(binary()) -> [integer()].

Get a list of Unicode codepoints from a string.

concat(S1, S2)

-spec concat(binary(), binary()) -> binary().

Concatenate two strings efficiently.

contains(String, Substring)

-spec contains(binary(), binary()) -> boolean().

Check if a string contains a substring.

downcase(String)

-spec downcase(binary()) -> binary().

Convert string to lowercase (Unicode-aware).

duplicate(String, N)

-spec duplicate(binary(), non_neg_integer()) -> binary().

Duplicate a string n times.

ends_with(String, Suffix)

-spec ends_with(binary(), binary()) -> boolean().

Check if a string ends with a given suffix.

first/1

-spec first(binary()) -> {ok, binary()} | {error, atom()}.

Get the first grapheme of a string.

from_binary(Bin)

-spec from_binary(binary()) -> {ok, binary()} | {error, atom()}.

Convert a binary to a string, validating UTF-8. Returns {ok, String} or {error, invalid_utf8}.

from_charlist(Charlist)

-spec from_charlist(list()) -> binary().

Convert a charlist to a UTF-8 string.

graphemes(String)

-spec graphemes(binary()) -> [binary()].

Split a string into a list of grapheme clusters.

is_empty/1

-spec is_empty(binary()) -> boolean().

Check if a string is empty.

join/2

-spec join([binary()], binary()) -> binary().

Join a list of strings with a separator.

last/1

-spec last(binary()) -> {ok, binary()} | {error, atom()}.

Get the last grapheme of a string.

length(String)

-spec length(binary()) -> non_neg_integer().

Get the length of a string in graphemes (Unicode-aware).

pad_left(String, Width, Padding)

-spec pad_left(binary(), non_neg_integer(), binary()) -> binary().

Pad a string on the left to a given width.

pad_right(String, Width, Padding)

-spec pad_right(binary(), non_neg_integer(), binary()) -> binary().

Pad a string on the right to a given width.

replace(String, Pattern, Replacement)

-spec replace(binary(), binary(), binary()) -> binary().

Replace the first occurrence of a pattern.

replace_all(String, Pattern, Replacement)

-spec replace_all(binary(), binary(), binary()) -> binary().

Replace all occurrences of a pattern.

reverse(String)

-spec reverse(binary()) -> binary().

Reverse a string (Unicode-aware, reverses graphemes).

slice(String, Start, Length)

-spec slice(binary(), integer(), non_neg_integer()) -> binary().

Extract a substring by grapheme position and length.

split(String, Pattern)

-spec split(binary(), binary()) -> [binary()].

Split a string by a pattern.

split_at(String, Index)

-spec split_at(binary(), integer()) -> {binary(), binary()}.

Split a string at a specific grapheme index.

starts_with(String, Prefix)

-spec starts_with(binary(), binary()) -> boolean().

Check if a string starts with a given prefix.

to_atom(String)

-spec to_atom(binary()) -> atom().

Convert string to atom.

to_binary(String)

-spec to_binary(binary()) -> binary().

Convert string to raw binary (identity function for strings).

to_charlist(String)

-spec to_charlist(binary()) -> list().

Convert a UTF-8 string to a charlist.

trim(String)

-spec trim(binary()) -> binary().

Trim whitespace from both ends of a string.

trim_left(String)

-spec trim_left(binary()) -> binary().

Trim whitespace from the left side of a string.

trim_right(String)

-spec trim_right(binary()) -> binary().

Trim whitespace from the right side of a string.

upcase(String)

-spec upcase(binary()) -> binary().

Convert string to uppercase (Unicode-aware).

valid_utf8(Bin)

-spec valid_utf8(binary()) -> boolean().

Check if a binary is valid UTF-8.