View Source z_string (zotonic_stdlib v1.23.1)

String related functions

Summary

Functions

Concatenate two strings (list or binary). Return type matching the first part.

Return true if What is found in the string

Calculate the Levensthein distance between two strings. Adapted from https://rosettacode.org/wiki/Levenshtein_distance#Erlang to use binary utf8 strings and maps. The smaller the returned integer the closer the strings are. Distance 0 means the two strings are equal.

Return true if Word ends with End

Escape special characters for ical RFC2445 elements

Return the first character of a string.

Check if the variable is a one dimensional list of bytes, or a valid utf-8 binary.

Is the character an ASCII or Unicode whitespace character? See @link https://en.wikipedia.org/wiki/Whitespace_character

Return the last character of a string

Make sure that the string is on one line only, replace control characters with spaces

Transliterate an unicode string to an ascii string with lowercase characters. Tries to transliterate some characters to a..z

Remove all spaces and control characters from a string.

Replace a string inside another string Copyright 2008 Rusty Klophaus (Nitrogen, MIT License)

Sanitize an utf-8 string, remove all non-utf-8 characters.

Split a string, see http://www.erlang.org/pipermail/erlang-questions/2008-October/038896.html

Split the binary into lines. Line separators can be \r, \n or \r\n.

Return true if Start is a prefix of Word

Return a lowercase string for the input

Map a string to a value that can be used as a name or slug. Maps all characters to lowercase and remove non digalpha chars

Filter a filename so that we obtain a basename that is safe to use.

Map a string to a slug that can be used in the uri of a page. Same as a name, but then with dashes instead of underscores.

Return a uppercase string for the input

Remove whitespace at the start and end of the string

Remove all occurrences of a character at the start and end of a string.

Remove whitespace at the start the string

Remove all occurrences of a char at the start of a string

Remove whitespace at the end of the string

Remove all occurrences of a char at the end of the string

Truncate a string. Append the '...' character at the place of break off.

Truncate a string, count all characters. No special handling of entities and tags.

Truncate a string, count all words. No special handling of entities and tags.

Remove all accents from all characters.

Remove the first and last char if they are double quotes.

Functions

concat(A, B)

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

Concatenate two strings (list or binary). Return type matching the first part.

contains(What, B)

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

Return true if What is found in the string

distance(S, T)

-spec distance(S, T) -> Distance
                  when S :: binary() | string(), T :: binary() | string(), Distance :: non_neg_integer().

Calculate the Levensthein distance between two strings. Adapted from https://rosettacode.org/wiki/Levenshtein_distance#Erlang to use binary utf8 strings and maps. The smaller the returned integer the closer the strings are. Distance 0 means the two strings are equal.

ends_with(End, B)

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

Return true if Word ends with End

escape_ical(L)

Escape special characters for ical RFC2445 elements

first_char(_)

-spec first_char(binary() | list()) -> non_neg_integer().

Return the first character of a string.

is_string(Rest)

-spec is_string(iodata()) -> boolean().

Check if the variable is a one dimensional list of bytes, or a valid utf-8 binary.

is_whitespace(C)

-spec is_whitespace(non_neg_integer()) -> boolean().

Is the character an ASCII or Unicode whitespace character? See @link https://en.wikipedia.org/wiki/Whitespace_character

last_char(L)

-spec last_char(binary() | string()) -> non_neg_integer().

Return the last character of a string

len(L)

-spec len(binary() | string() | undefined) -> integer().

line(B)

-spec line(string() | binary()) -> string() | binary().

Make sure that the string is on one line only, replace control characters with spaces

normalize(B)

-spec normalize(string() | binary() | atom() | {trans, list()}) -> binary().

Transliterate an unicode string to an ascii string with lowercase characters. Tries to transliterate some characters to a..z

nospaces(B)

-spec nospaces(iodata()) -> iodata().

Remove all spaces and control characters from a string.

replace(String, S1, S2)

Replace a string inside another string Copyright 2008 Rusty Klophaus (Nitrogen, MIT License)

sanitize_utf8(L)

-spec sanitize_utf8(string() | binary()) -> binary().

Sanitize an utf-8 string, remove all non-utf-8 characters.

split(String, L)

Split a string, see http://www.erlang.org/pipermail/erlang-questions/2008-October/038896.html

split_lines(B)

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

Split the binary into lines. Line separators can be \r, \n or \r\n.

starts_with(Start, B)

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

Return true if Start is a prefix of Word

to_lower(B)

-spec to_lower(string() | binary() | atom()) -> binary().

Return a lowercase string for the input

to_name(V)

-spec to_name(string() | binary() | atom() | {trans, list()}) -> binary().

Map a string to a value that can be used as a name or slug. Maps all characters to lowercase and remove non digalpha chars

to_rootname(Filename)

-spec to_rootname(file:filename_all()) -> binary().

Filter a filename so that we obtain a basename that is safe to use.

to_slug(Title)

-spec to_slug(string() | binary() | atom()) -> binary().

Map a string to a slug that can be used in the uri of a page. Same as a name, but then with dashes instead of underscores.

to_upper(B)

-spec to_upper(string() | binary() | atom()) -> binary().

Return a uppercase string for the input

trim(B)

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

Remove whitespace at the start and end of the string

trim(B, Char)

-spec trim(iodata(), integer()) -> binary().

Remove all occurrences of a character at the start and end of a string.

trim_left(S)

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

Remove whitespace at the start the string

trim_left(S, Char)

-spec trim_left(binary() | list(), integer()) -> binary() | list().

Remove all occurrences of a char at the start of a string

trim_left_func(Bin, F)

trim_right(B)

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

Remove whitespace at the end of the string

trim_right(B, Char)

-spec trim_right(iodata(), integer()) -> binary().

Remove all occurrences of a char at the end of the string

truncate(String, Length)

-spec truncate(String :: undefined | string() | binary(), Length :: integer()) -> undefined | binary().

Truncate a string. Append the '...' character at the place of break off.

truncate(String, Length, Append)

-spec truncate(String :: undefined | string() | binary(),
               Length :: integer(),
               Append :: binary() | string()) ->
                  binary().

truncatechars(String, Length)

-spec truncatechars(String :: undefined | string() | binary(), Length :: integer()) ->
                       undefined | binary().

Truncate a string, count all characters. No special handling of entities and tags.

truncatechars(String, Length, Append)

-spec truncatechars(String :: undefined | string() | binary(),
                    Length :: integer(),
                    Append :: binary() | string()) ->
                       binary().

truncatewords(S, Words)

Truncate a string, count all words. No special handling of entities and tags.

truncatewords(S, Words, Append)

unaccent(S)

-spec unaccent(S) -> S1 when S :: unicode:chardata(), S1 :: binary().

Remove all accents from all characters.

unquote(S)

-spec unquote(iodata()) -> iodata().

Remove the first and last char if they are double quotes.

unquote(S, Q)