TITLE ^

Str - Perl 6 Str class and related functions

DESCRIPTION ^

This file sets up the Perl6Str PMC type (from src/pmc/perl6str.pmc) as the Perl 6 Str class.

Methods ^

perl()

Returns a Perl representation of the Str.

sprintf( *@args )

WHICH()

Returns the identify value.

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 List multi Str::split ( Str $delimiter ,  Str $input = $+_, Int $limit = inf )
 our List multi Str::split ( Rule $delimiter = /\s+/,  Str $input = $+_, Int $limit = inf )
 our List multi Str::split ( Str $input :  Str $delimiter          , Int $limit = inf )
 our List 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

chop

 our Str method Str::chop ( Str  $string: )
Returns string with one Char removed from the end.

infix:===

Overridden for Str.

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

length

This word is banned in Perl 6. You must specify units.

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 List multi Str::words ( Rule $matcher = /\S+/,  Str $input = $+_, Int $limit = inf )
 our List multi Str::words ( Str $input : Rule $matcher = /\S+/, Int $limit = inf )


parrot