TITLE ^

CardinalString - Cardinal String class and related functions

DESCRIPTION ^

This file sets up the CardinalString type.

Stolen from Rakudo

Methods ^

chars()
Returns the number of characters in self
size()
concat()
Adds given object to self. Returns self
reverse()
Returns a new CardinalString with the characters of self in reverse order.
reverse!()
Returns the characters in self in reverse order. Destructive update.
downcase()
Returns a copy of self with all upper case letters converted to lower case
upcase()
Returns a copy of self with all lower case letters converted to upper case
capitalize()
    Returns a copy of C<self> with the first character converted to uppercase and the remainder to lowercase.
TODO: Read from the global record separator
TODO: Read from the global record separator
length()
 Return the number of characters in C<self>
'[]'
 subscript operator. Accepts [(-)? int], [(-)?int, (-)?int]
'[]='
Warning: Partial implementation. Look for TODO
perl()
Returns a Perl representation of the Str.
to_s()
Returns self

Functions ^

lc()
 our Str multi Str::lc ( Str $string )
Returns the input string after converting each character to its lowercase form, if uppercase.
lcfirst()
 our Str multi Str::lcfirst ( Str $string )
Like lc, but only affects the first character.
uc
 our Str multi Str::uc ( Str $string )
Returns the input string after converting each character to its uppercase form, if lowercase. This is not a Unicode "titlecase" operation, but a full "uppercase".
ucfirst
 our Str multi Str::ucfirst ( Str $string )
Performs a Unicode "titlecase" operation on the first character of the string.
capitalize
 our Str multi Str::capitalize ( Str $string )
Has the effect of first doing an lc on the entire string, then performing a s:g/(\w+)/{ucfirst $1}/ on it.
split
 our CardinalArray multi Str::split ( Str $delimiter ,  Str $input = $+_, Int $limit = inf )
 our CardinalArray multi Str::split ( Rule $delimiter = /\s+/,  Str $input = $+_, Int $limit = inf )
 our CardinalArray multi Str::split ( Str $input :  Str $delimiter          , Int $limit = inf )
 our CardinalArray multi Str::split ( Str $input : Rule $delimiter          , Int $limit = inf )
String delimiters must not be treated as rules but as constants. The default is no longer ' ' since that would be interpreted as a constant. P5's split(' ') will translate to .words or some such. Null trailing fields are no longer trimmed by default. We might add some kind of :trim flag or introduce a trimlist function of some sort.Note: partial implementation only
join
Note: partial implementation only
substr
 multi substr (Str $s, StrPos $start  : StrPos $end,      $replace)
 multi substr (Str $s, StrPos $start,   StrLen $length  : $replace)
 multi substr (Str $s, StrLen $offset : StrLen $length,   $replace)
Note: partial implementation only
chop
 our Str method Str::chop ( Str  $string: )
Returns string with one Char removed from the end.

TODO Functions ^

p5chop
 our Char multi P5emul::Str::p5chop ( Str  $string is rw )
 our Char multi P5emul::Str::p5chop ( Str *@strings = ($+_) is rw )
Trims the last character from $string, and returns it. Called with a list, it chops each item in turn, and returns the last character chopped.
p5chomp
 our Int multi P5emul::Str::p5chomp ( Str  $string is rw )
 our Int multi P5emul::Str::p5chomp ( Str *@strings = ($+_) is rw )
Related to p5chop, only removes trailing chars that match /\n/. In either case, it returns the number of chars removed.
chomp
 our Str method Str::chomp ( Str $string: )
Returns string with newline removed from the end. An arbitrary terminator can be removed if the input filehandle has marked the string for where the "newline" begins. (Presumably this is stored as a property of the string.) Otherwise a standard newline is removed.Note: Most users should just let their I/O handles autochomp instead. (Autochomping is the default.)
index
Needs to be in terms of StrPos, not Int.
pack
pos
quotemeta
rindex
Needs to be in terms of StrPos, not Int.
sprintf
unpack
vec
Should replace vec with declared arrays of bit, uint2, uint4, etc.
words
 our CardinalArray multi Str::words ( Rule $matcher = /\S+/,  Str $input = $+_, Int $limit = inf )
 our CardinalArray multi Str::words ( Str $input : Rule $matcher = /\S+/, Int $limit = inf )


parrot