View Source z_string (zotonic_stdlib v1.16.0)

String related functions

Link to this section 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 the first and last char if they are double quotes.

Link to this section Functions

-spec concat(string() | binary(), string() | binary()) -> string() | binary().
Concatenate two strings (list or binary). Return type matching the first part.
-spec contains(iodata(), iodata()) -> boolean().
Return true if What is found in the string
-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.
-spec ends_with(iodata(), iodata()) -> boolean().
Return true if Word ends with End
Escape special characters for ical RFC2445 elements
-spec first_char(binary() | list()) -> non_neg_integer().
Return the first character of a string.
-spec is_string(iodata()) -> boolean().
Check if the variable is a one dimensional list of bytes, or a valid utf-8 binary.
-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
-spec last_char(binary() | string()) -> non_neg_integer().
Return the last character of a string
-spec len(binary() | string() | undefined) -> integer().
-spec line(string() | binary()) -> string() | binary().
Make sure that the string is on one line only, replace control characters with spaces
-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
-spec nospaces(iodata()) -> iodata().
Remove all spaces and control characters from a string.
Replace a string inside another string Copyright 2008 Rusty Klophaus (Nitrogen, MIT License)
-spec sanitize_utf8(string() | binary()) -> binary().
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
-spec split_lines(binary()) -> [binary()].
Split the binary into lines. Line separators can be \r, \n or \r\n.
-spec starts_with(iodata(), iodata()) -> boolean().
Return true if Start is a prefix of Word
-spec to_lower(string() | binary() | atom()) -> binary().
Return a lowercase string for the input
-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
-spec to_rootname(file:filename_all()) -> binary().
Filter a filename so that we obtain a basename that is safe to use.
-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.
-spec to_upper(string() | binary() | atom()) -> binary().
Return a uppercase string for the input
-spec trim(iodata()) -> binary().
Remove whitespace at the start and end of the string
-spec trim(iodata(), integer()) -> binary().
Remove all occurrences of a character at the start and end of a string.
-spec trim_left(binary() | list()) -> binary() | list().
Remove whitespace at the start the string
-spec trim_left(binary() | list(), integer()) -> binary() | list().
Remove all occurrences of a char at the start of a string
-spec trim_right(iodata()) -> binary().
Remove whitespace at the end of the string
-spec trim_right(iodata(), integer()) -> binary().
Remove all occurrences of a char at the end of the string
Link to this function

truncate(String, Length)

View Source
-spec truncate(String :: undefined | string() | binary(), Length :: integer()) -> undefined | binary().
Truncate a string. Append the '...' character at the place of break off.
Link to this function

truncate(String, Length, Append)

View Source
-spec truncate(String :: undefined | string() | binary(),
         Length :: integer(),
         Append :: binary() | string()) ->
            binary().
Link to this function

truncatechars(String, Length)

View Source
-spec truncatechars(String :: undefined | string() | binary(), Length :: integer()) ->
                 undefined | binary().
Truncate a string, count all characters. No special handling of entities and tags.
Link to this function

truncatechars(String, Length, Append)

View Source
-spec truncatechars(String :: undefined | string() | binary(),
              Length :: integer(),
              Append :: binary() | string()) ->
                 binary().
Truncate a string, count all words. No special handling of entities and tags.
Link to this function

truncatewords(S, Words, Append)

View Source
-spec unquote(iodata()) -> iodata().
Remove the first and last char if they are double quotes.