View Source jhn_bstring (jhn_stdlib v5.3.3)

String Processing Functions for binary encoded strings.

This is a drop in replacement for the string module in stdlib working on binaries interpreted as strings of octets in Latin1.

The module generates ref binaries as much as possible so if copies are more suitable apply binary/copy/1 on the result. Functions affected are the sub string family and tokens/2.

Summary

Functions

Returns a string, where String is centred in the string and surrounded by blanks. The resulting string will have the length Number.

Returns a string, where String is centred in the string and surrounded by characters. The resulting string will have the length Number.

Returns a string consisting of Number of characters Character.

Returns a string consisting of Number of characters Character, the string ends with the string Tail.

Returns the index of the first occurrence of Character in String. 0 is returned if Character does not occur.

Concatenates two strings to form a new string. Returns the new string.

Returns a string containing String repeated Number times.

Returns the length of the maximum initial segment of String, which consists entirely of characters not from Chars.

Tests whether two strings are equal. Returns true if they are, otherwise false.

Returns a string with the elements of StringList separated by the string in Separator.

Returns the String with the length adjusted in accordance with Number. The left margin is fixed. If the length(String) < Number, String is padded with blanks.

Returns the String with the length adjusted in accordance with Number. The left margin is fixed. If the length(String) < Number, String is padded with Characters.

Returns the number of characters in the string.

Returns the index of the last occurrence of Character in String. 0 is returned if Character does not occur.

Returns the String with the length adjusted in accordance with Number. The right margin is fixed. If the length of (String) < Number, String is padded with blanks.

Returns the String with the length adjusted in accordance with Number. The right margin is fixed. If the length of (String) < Number, String is padded with Characters.

Returns the position where the last occurrence of SubString begins in String. 0 is returned if SubString does not exist in String.

Returns the length of the maximum initial segment of String, which consists entirely of characters from Chars.

Returns the position where the first occurrence of SubString begins in String. 0 is returned if SubString does not exist in String.

Returns a string, where leading and trailing blanks have been removed. The function strip/1 is equivalent to strip(String, both).

Returns a string, where leading and/or trailing blanks have been removed. Direction can be left, right, or both and indicates from which direction blanks are to be removed.

Returns a string, where leading and/or trailing blanks or a number of Character have been removed. Direction can be left, right, or both and indicates from which direction blanks are to be removed.

Returns a substring of String, starting at the position Start to the end of the string.

Returns a substring of String, starting at the position Start to the end of the string, or to and including the Stop position.

Returns the word in position Number of String. Words are separated by blanks .

Returns the word in position Number of String. Words are separated by Characters.

Returns a substring of String, starting at the position Start, and ending at the end of the string.

Returns a substring of String, starting at the position Start, and ending at the end of the string or at length Length.

Argument String is expected to start with a valid text represented float (the digits being ASCII values). Remaining characters in the string after the float are returned in Rest.

Argument String is expected to start with a valid text represented integer (the digits being ASCII values). Remaining characters in the string after the integer are returned in Rest.

The given string is case-converted. Note that the supported character set is ISO/IEC 8859-1 (a.k.a. Latin 1), all values outside this set is unchanged.

The given string is case-converted. Note that the supported character set is ISO/IEC 8859-1 (a.k.a. Latin 1), all values outside this set is unchanged.

Returns a list of tokens in String, separated by the characters in Separators.

Returns the number of words in String, separated by blanks.

Returns the number of words in String, separated by Character.

Types

-type direction() :: left | right | both.

Functions

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

Returns a string, where String is centred in the string and surrounded by blanks. The resulting string will have the length Number.

Link to this function

centre(Binary, Length, Char)

View Source
-spec centre(binary(), non_neg_integer(), char()) -> binary().

Returns a string, where String is centred in the string and surrounded by characters. The resulting string will have the length Number.

-spec chars(char(), non_neg_integer()) -> binary().

Returns a string consisting of Number of characters Character.

-spec chars(char(), non_neg_integer(), binary()) -> binary().

Returns a string consisting of Number of characters Character, the string ends with the string Tail.

-spec chr(binary(), char()) -> non_neg_integer().

Returns the index of the first occurrence of Character in String. 0 is returned if Character does not occur.

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

Concatenates two strings to form a new string. Returns the new string.

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

Returns a string containing String repeated Number times.

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

Returns the length of the maximum initial segment of String, which consists entirely of characters not from Chars.

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

Tests whether two strings are equal. Returns true if they are, otherwise false.

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

Returns a string with the elements of StringList separated by the string in Separator.

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

Returns the String with the length adjusted in accordance with Number. The left margin is fixed. If the length(String) < Number, String is padded with blanks.

Link to this function

left(Binary, Length, Char)

View Source
-spec left(binary(), non_neg_integer(), char()) -> binary().

Returns the String with the length adjusted in accordance with Number. The left margin is fixed. If the length(String) < Number, String is padded with Characters.

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

Returns the number of characters in the string.

-spec rchr(binary(), char()) -> non_neg_integer().

Returns the index of the last occurrence of Character in String. 0 is returned if Character does not occur.

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

Returns the String with the length adjusted in accordance with Number. The right margin is fixed. If the length of (String) < Number, String is padded with blanks.

Link to this function

right(Binary, Length, Char)

View Source
-spec right(binary(), non_neg_integer(), char()) -> binary().

Returns the String with the length adjusted in accordance with Number. The right margin is fixed. If the length of (String) < Number, String is padded with Characters.

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

Returns the position where the last occurrence of SubString begins in String. 0 is returned if SubString does not exist in String.

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

Returns the length of the maximum initial segment of String, which consists entirely of characters from Chars.

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

Returns the position where the first occurrence of SubString begins in String. 0 is returned if SubString does not exist in String.

-spec strip(binary()) -> binary().

Returns a string, where leading and trailing blanks have been removed. The function strip/1 is equivalent to strip(String, both).

Link to this function

strip(Binary, Direction)

View Source
-spec strip(binary(), direction()) -> binary().

Returns a string, where leading and/or trailing blanks have been removed. Direction can be left, right, or both and indicates from which direction blanks are to be removed.

-spec strip(binary(), direction(), char()) -> binary().

Returns a string, where leading and/or trailing blanks or a number of Character have been removed. Direction can be left, right, or both and indicates from which direction blanks are to be removed.

Link to this function

sub_string(Binary, Start)

View Source
-spec sub_string(binary(), pos_integer()) -> binary().

Returns a substring of String, starting at the position Start to the end of the string.

Link to this function

sub_string(Binary, Start, Stop)

View Source
-spec sub_string(binary(), pos_integer(), pos_integer()) -> binary().

Returns a substring of String, starting at the position Start to the end of the string, or to and including the Stop position.

Link to this function

sub_word(Binary, Number)

View Source
-spec sub_word(binary(), non_neg_integer()) -> binary().

Returns the word in position Number of String. Words are separated by blanks .

Link to this function

sub_word(Binary, Number, Separator)

View Source
-spec sub_word(binary(), non_neg_integer(), non_neg_integer()) -> binary().

Returns the word in position Number of String. Words are separated by Characters.

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

Returns a substring of String, starting at the position Start, and ending at the end of the string.

Link to this function

substr(Binary, Start, Length)

View Source
-spec substr(binary(), pos_integer(), non_neg_integer()) -> binary().

Returns a substring of String, starting at the position Start, and ending at the end of the string or at length Length.

-spec to_float(binary()) -> {float(), binary()} | {error, _}.

Argument String is expected to start with a valid text represented float (the digits being ASCII values). Remaining characters in the string after the float are returned in Rest.

-spec to_integer(binary()) -> {integer(), binary()} | {error, _}.

Argument String is expected to start with a valid text represented integer (the digits being ASCII values). Remaining characters in the string after the integer are returned in Rest.

-spec to_lower(binary()) -> binary().

The given string is case-converted. Note that the supported character set is ISO/IEC 8859-1 (a.k.a. Latin 1), all values outside this set is unchanged.

-spec to_upper(binary()) -> binary().

The given string is case-converted. Note that the supported character set is ISO/IEC 8859-1 (a.k.a. Latin 1), all values outside this set is unchanged.

Link to this function

tokens(Binary, Separators)

View Source
-spec tokens(binary(), binary()) -> [binary()].

Returns a list of tokens in String, separated by the characters in Separators.

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

Returns the number of words in String, separated by blanks.

Link to this function

words(Binary, Separator)

View Source
-spec words(binary(), non_neg_integer()) -> non_neg_integer().

Returns the number of words in String, separated by Character.