This project has retired. For details please refer to its Attic page.
Clownfish::String – Apache Clownfish Documentation
Apache Lucy™

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

my $result = $string->cat($other);

Return the concatenation of the String and other.

to_i64

my $int = $string->to_i64();

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

basex_to_i64

my $int = $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

my $float = $string->to_f64();

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

starts_with

my $bool = $string->starts_with($prefix);

Test whether the String starts with prefix.

ends_with

my $bool = $string->ends_with($suffix);

Test whether the String ends with suffix.

contains

my $bool = $string->contains($substring);

Test whether the String contains substring.

find

my $string_iterator = $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

my $int = $string->length();

Return the number of Unicode code points the String contains.

get_size

my $int = $string->get_size();

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

to_bytebuf

my $byte_buf = $string->to_bytebuf();

Return a ByteBuf which holds a copy of the String.

clone

my $result = $string->clone();

Return a clone of the object.

compare_to

my $int = $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

my $result = $string->trim();

Return 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

my $result = $string->trim_top();

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

trim_tail

my $result = $string->trim_tail();

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

code_point_at

my $int = $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

my $int = $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

my $result = $string->substring(
    offset => $offset  # required
    length => $length  # required
);

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

  • offset - Offset from the top, in code points.
  • length - The desired length of the substring, in code points.

top

my $string_iterator = $string->top();

Return an iterator initialized to the start of the string.

tail

my $string_iterator = $string->tail();

Return an iterator initialized to the end of the string.

INHERITANCE

Clownfish::String isa Clownfish::Obj.