Module estring

Extra string functions that aren't available in stdlib string module.

Copyright © 2009 Mr Buzz, Inc.

Authors: Jacob Perkins.

Description

Extra string functions that aren't available in stdlib string module.

Function Index

encode_utf8/1Encode a string as utf-8.
is_upper/1Tests if String is upper case.
is_utf8/1Test if string is utf-8 encoded.
join/2
lcs_len/2Return length of the longest common subsequence (lcs) between two lists.
partial_match/2Tests if two strings are similar using prefix and suffix matching.
querydecode/1Decode a url query string.
random/1Returns a random alphanumeric string of length Size.
read_file/1Returns the contents of file as a list.
replace/3Replace first instance of Key in String with Val.
replace_all/3Replaces all instances of Key in String with Val.
similar/2Test if two strings are similar using the ratio of the lcs_len divided by length of the shortest string.
split/2Splits String at first instance of Sep.
splitc/2Faster, character based version of split/2.
strip/1Strips newline and whitespace characters from String.
strip_all/2Strip all characters from both ends of string.
striptokens/1Tokenize the string, then strip each token.
striptokens/2Tokenize the string with separators, then strip each token.
title_word/1Title case word by converting first character to upper case and rest of characters to lower case.
to_title/1Title cases String, calling title_word/1 on each word.
tokenize/2Return a list containing tokens from each string.
urldecode/1Decode the query part of a url.
utf8_to_unicode/1Convert a utf-8 string to unicode.

Function Details

encode_utf8/1

encode_utf8() -> term()

Equivalent to xmerl_ucs:to_utf8(String).

Encode a string as utf-8.

is_upper/1

is_upper(String::string()) -> bool()

Tests if String is upper case.

See also: string:to_upper/1.

is_utf8/1

is_utf8(String::string()) -> bool()

Test if string is utf-8 encoded.

See also: xmerl_ucs:is_incharset/2.

join/2

join() -> term()

lcs_len/2

lcs_len(A::list(), B::list()) -> integer()

Return length of the longest common subsequence (lcs) between two lists. Use this function to find out how similar two strings are. Think of the lcs_len as the 'edit distance' between two strings, meaning the number of edits required to go from one string to the other.

partial_match/2

partial_match(B::string(), A::string()) -> bool()

Tests if two strings are similar using prefix and suffix matching. The strings are similar if A is a prefix or suffix of B. This function is an interim replacement for similar/2 until lcs_len/2 is optimized.

querydecode/1

querydecode(Query::string()) -> [{string(), string()}]

Decode a url query string.

See also: split/2.

random/1

random(Size::integer()) -> string()

Returns a random alphanumeric string of length Size.

See also: emath:random/1.

read_file/1

read_file(Filename::string()) -> list()

Returns the contents of file as a list.

See also: file:read_file/1.

replace/3

replace(String::string(), Key::string(), Val::string()) -> Result

Replace first instance of Key in String with Val. Returns {error, notfound} if Key is not in String.

replace_all/3

replace_all(String::string(), Key::string(), Val::string()) -> {ok, string()}

Replaces all instances of Key in String with Val. If there are no instances of Key in String, then will return {ok, String}.

See also: replace/3.

similar/2

similar(A::string(), B::string()) -> bool()

Test if two strings are similar using the ratio of the lcs_len divided by length of the shortest string. Strings are lowercased before comparing.

See also: lcs_len/2.

split/2

split(S::string(), Sep::string()) -> [string() | string()]

Splits String at first instance of Sep. This is an alternative to string:tokens that is much more efficient if you know that you only need to split once. Fails if Sep is not found in String.

See also: string:tokens/2.

splitc/2

splitc(S::string(), C::char()) -> {string(), string()}

Faster, character based version of split/2.

strip/1

strip(String::string()) -> string()

Strips newline and whitespace characters from String. string:strip only strips whitespace by default.

See also: string:strip/1, string:strip/3.

strip_all/2

strip_all(String::string(), Chars::[char()]) -> string()

Strip all characters from both ends of string.

See also: string:strip/3.

striptokens/1

striptokens(String::string()) -> [string()]

Equivalent to striptokens(String, ",").

Tokenize the string, then strip each token.

striptokens/2

striptokens(String::string(), Sep::string()) -> [string()]

Tokenize the string with separators, then strip each token.

See also: string:tokens/2.

title_word/1

title_word(Rest::string()) -> string()

Title case word by converting first character to upper case and rest of characters to lower case.

See also: string:to_lower/1, string:to_upper/1.

to_title/1

to_title(String::string()) -> string()

Title cases String, calling title_word/1 on each word.

See also: title_word/1.

tokenize/2

tokenize(Strings::[string()], Sep::string()) -> [string()]

Return a list containing tokens from each string.

See also: string:tokens/2.

urldecode/1

urldecode(URL::string()) -> [{string(), string()}]

Decode the query part of a url.

See also: querydecode/1.

utf8_to_unicode/1

utf8_to_unicode() -> term()

Equivalent to xmerl_ucs:to_unicode(String, 'utf-8').

Convert a utf-8 string to unicode.


Generated by EDoc, Jul 14 2009, 14:06:01.