Search documentation of jhn_stdlib

# jhn_bstring (jhn_stdlib v5.10.3)

View Source

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

## Types

direction/0

## Functions

centre(Binary, Length)

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

centre(Binary, Length, Char)

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

chars(Char, No)

Returns a string consisting of Number of characters Character.

chars(Char, No, T)

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

chr(B, C)

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

concat(B1, B2)

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

copies(Binary, No)

Returns a string containing String repeated Number times.

cspan(B, Cs)

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

equal(B, _)

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

join(T, Separator)

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

left(Binary, Length)

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(Binary, Length, Char)

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(B)

Returns the number of characters in the string.

rchr(B, C)

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

right(Binary, Length)

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(Binary, Length, Char)

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(B, Sub)

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

span(B, Cs)

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

str(B, Sub)

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

strip(Binary)

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

strip(Binary, Direction)

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(Binary, _, Char)

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(Binary, Start)

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

sub_string(Binary, Start, Stop)

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(Binary, Number)

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

sub_word(Binary, Number, Separator)

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

substr(Binary, Start)

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

substr(Binary, Start, Length)

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

to_float(Binary)

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(Binary)

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(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(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(Binary, Separators)

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

words(Binary)

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

words(Binary, Separator)

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

# Types

# direction/0

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

# Functions

# centre(Binary, Length)

    -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.

# centre(Binary, Length, Char)

    -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.

# chars(Char, No)

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

Returns a string consisting of Number of characters Character.

# chars(Char, No, T)

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

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

# chr(B, C)

    -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.

# concat(B1, B2)

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

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

# copies(Binary, No)

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

Returns a string containing String repeated Number times.

# cspan(B, Cs)

    -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.

# equal(B, _)

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

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

# join(T, Separator)

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

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

# left(Binary, Length)

    -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.

# left(Binary, Length, Char)

    -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.

# len(B)

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

Returns the number of characters in the string.

# rchr(B, C)

    -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.

# right(Binary, Length)

    -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.

# right(Binary, Length, Char)

    -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.

# rstr(B, Sub)

    -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.

# span(B, Cs)

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

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

# str(B, Sub)

    -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.

# strip(Binary)

    -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).

# strip(Binary, Direction)

    -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.

# strip(Binary, _, Char)

    -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.

# sub_string(Binary, Start)

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

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

# sub_string(Binary, Start, Stop)

    -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.

# sub_word(Binary, Number)

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

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

# sub_word(Binary, Number, Separator)

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

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

# substr(Binary, Start)

    -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.

# substr(Binary, Start, Length)

    -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.

# to_float(Binary)

    -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.

# to_integer(Binary)

    -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.

# to_lower(Binary)

    -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.

# to_upper(Binary)

    -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.

# tokens(Binary, Separators)

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

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

# words(Binary)

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

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

# words(Binary, Separator)

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

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