Module bstring

String Processing Functions for binary encoded strings.

Copyright © (C) 2013-2020, Jan Henry Nystrom <JanHenryNystrom@gmail.com> -------------------------------------------------------------------

Authors: Jan Henry Nystrom (JanHenryNystrom@gmail.com).

Description

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.

Data Types

direction()

direction() = left | right | both

Function Index

centre/2 Returns a string, where String is centred in the string and surrounded by blanks.
centre/3 Returns a string, where String is centred in the string and surrounded by characters.
chars/2 Returns a string consisting of Number of characters Character.
chars/3 Returns a string consisting of Number of characters Character, the string ends with the string Tail.
chr/2 Returns the index of the first occurrence of Character in String.
concat/2 Concatenates two strings to form a new string.
copies/2 Returns a string containing String repeated Number times.
cspan/2 Returns the length of the maximum initial segment of String, which consists entirely of characters not from Chars.
equal/2 Tests whether two strings are equal.
join/2 Returns a string with the elements of StringList separated by the string in Separator.
left/2 Returns the String with the length adjusted in accordance with Number.
left/3 Returns the String with the length adjusted in accordance with Number.
len/1 Returns the number of characters in the string.
rchr/2 Returns the index of the last occurrence of Character in String.
right/2 Returns the String with the length adjusted in accordance with Number.
right/3 Returns the String with the length adjusted in accordance with Number.
rstr/2 Returns the position where the last occurrence of SubString begins in String.
span/2 Returns the length of the maximum initial segment of String, which consists entirely of characters from Chars.
str/2 Returns the position where the first occurrence of SubString begins in String.
strip/1 Returns a string, where leading and trailing blanks have been removed.
strip/2 Returns a string, where leading and/or trailing blanks have been removed.
strip/3 Returns a string, where leading and/or trailing blanks or a number of Character have been removed.
sub_string/2 Returns a substring of String, starting at the position Start to the end of the string.
sub_string/3 Returns a substring of String, starting at the position Start to the end of the string, or to and including the Stop position.
sub_word/2 Returns the word in position Number of String.
sub_word/3 Returns the word in position Number of String.
substr/2 Returns a substring of String, starting at the position Start, and ending at the end of the string.
substr/3 Returns a substring of String, starting at the position Start, and ending at the end of the string or at length Length.
to_float/1 Argument String is expected to start with a valid text represented float (the digits being ASCII values).
to_integer/1 Argument String is expected to start with a valid text represented integer (the digits being ASCII values).
to_lower/1 The given string is case-converted.
to_upper/1 The given string is case-converted.
tokens/2 Returns a list of tokens in String, separated by the characters in Separators.
words/1 Returns the number of words in String, separated by blanks.
words/2 Returns the number of words in String, separated by Character.

Function Details

centre/2

centre(Binary::binary(), Length::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.

centre/3

centre(Binary::binary(), Length::non_neg_integer(), Char::char()) -> binary()

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

chars/2

chars(Char::char(), No::non_neg_integer()) -> binary()

Returns a string consisting of Number of characters Character.

chars/3

chars(Char::char(), No::non_neg_integer(), T::binary()) -> binary()

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

chr/2

chr(B::binary(), C::char()) -> non_neg_integer()

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

concat/2

concat(B1::binary(), B2::binary()) -> binary()

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

copies/2

copies(Binary::binary(), No::non_neg_integer()) -> binary()

Returns a string containing String repeated Number times.

cspan/2

cspan(B::binary(), Cs::binary()) -> non_neg_integer()

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

equal/2

equal(B::binary(), X2::binary()) -> boolean()

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

join/2

join(T::[binary()], Separator::binary()) -> binary()

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

left/2

left(Binary::binary(), Length::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.

left/3

left(Binary::binary(), Length::non_neg_integer(), Char::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.

len/1

len(B::binary()) -> non_neg_integer()

Returns the number of characters in the string.

rchr/2

rchr(B::binary(), C::char()) -> non_neg_integer()

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

right/2

right(Binary::binary(), Length::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.

right/3

right(Binary::binary(), Length::non_neg_integer(), Char::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.

rstr/2

rstr(B::binary(), Sub::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.

span/2

span(B::binary(), Cs::binary()) -> non_neg_integer()

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

str/2

str(B::binary(), Sub::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.

strip/1

strip(Binary::binary()) -> binary()

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

strip/2

strip(Binary::binary(), Direction::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.

strip/3

strip(Binary::binary(), X2::direction(), Char::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.

sub_string/2

sub_string(Binary::binary(), Start::pos_integer()) -> binary()

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

sub_string/3

sub_string(Binary::binary(), Start::pos_integer(), Stop::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.

sub_word/2

sub_word(Binary::binary(), Number::non_neg_integer()) -> binary()

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

sub_word/3

sub_word(Binary::binary(), Number::non_neg_integer(), Separator::non_neg_integer()) -> binary()

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

substr/2

substr(Binary::binary(), Start::non_neg_integer()) -> binary()

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

substr/3

substr(Binary::binary(), Start::pos_integer(), Length::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.

to_float/1

to_float(Binary::binary()) -> {float(), binary()} | {error, term()}

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.

to_integer/1

to_integer(Binary::binary()) -> {integer(), binary()} | {error, term()}

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.

to_lower/1

to_lower(Binary::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.

to_upper/1

to_upper(Binary::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.

tokens/2

tokens(Binary::binary(), Separators::binary()) -> [binary()]

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

words/1

words(Binary::binary()) -> non_neg_integer()

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

words/2

words(Binary::binary(), Separator::non_neg_integer()) -> non_neg_integer()

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


Generated by EDoc