NAME

Clownfish::String - Immutable string holding Unicode characters.

SYNOPSIS

my $string = Clownfish::String->new('abc');
print $string->to_perl, "\n";

DESCRIPTION

CONSTRUCTORS

new

my $string = Clownfish::String->new($perl_string);

Return a String containing the passed-in Perl string.

METHODS

cat

$string->cat($other);

Return the concatenation of the String and other.

to_i64

$string->to_i64();

Extract a 64-bit integer from a decimal string. See basex_to_i64() for details.

basex_to_i64

$string->basex_to_i64($base);

Extract a 64-bit integer from a variable-base stringified version. Expects an optional minus sign followed by base-x digits, stopping at any non-digit character. Returns zero if no digits are found. If the value exceeds the range of an int64_t, the result is undefined.

  • base - A base between 2 and 36.

to_f64

$string->to_f64();

Convert a string to a floating-point number using the C library function strtod.

starts_with

$string->starts_with($prefix);

Test whether the String starts with prefix.

ends_with

$string->ends_with($suffix);

Test whether the String ends with suffix.

contains

$string->contains($substring);

Test whether the String contains substring.

find

$string->find($substring);

Return a StringIterator pointing to the first occurrence of substring within the String, or undef if the substring does not match.

length

$string->length();

Return the number of Unicode code points the String contains.

get_size

$string->get_size();

Return the number of bytes occupied by the String’s internal content.

to_bytebuf

$string->to_bytebuf();

Return a ByteBuf which holds a copy of the String.

clone

$string->clone();

Return a clone of the object.

compare_to

$string->compare_to($other);

Indicate whether one String is less than, equal to, or greater than another. The Unicode code points of the Strings are compared lexicographically. Throws an exception if other is not a String.

Returns: 0 if the Strings are equal, a negative number if self is less than other, and a positive number if self is greater than other.

trim

$string->trim();

Return a a copy of the String with Unicode whitespace characters removed from both top and tail. Whitespace is any character that has the Unicode property White_Space.

trim_top

$string->trim_top();

Return a a copy of the String with leading Unicode whitespace removed. Whitespace is any character that has the Unicode property White_Space.

trim_tail

$string->trim_tail();

Return a a copy of the String with trailing Unicode whitespace removed. Whitespace is any character that has the Unicode property White_Space.

code_point_at

$string->code_point_at($tick);

Return the Unicode code point located tick code points in from the top. Return CFISH_STR_OOB if out of bounds.

code_point_from

$string->code_point_from($tick);

Return the Unicode code point located tick code points counting backwards from the end. Return CFISH_STR_OOB if out of bounds.

substring

$string->substring(
    offset => $int,  # required
    length => $int,  # required
);

Return a new String containing a copy of the specified substring.

  • offset - Offset from the top, in code points.

  • length - The desired length of the substring, in code points.

top

$string->top();

Return an iterator initialized to the start of the string.

tail

$string->tail();

Return an iterator initialized to the end of the string.

INHERITANCE

Clownfish::String isa Clownfish::Obj.