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
- size()
- concat() Adds given object to
- reverse() Returns a new CardinalString with the characters of
- reverse!() Returns the characters in
- downcase() Returns a copy of
- upcase() Returns a copy of
- capitalize()
- TODO: Read from the global record separator
- TODO: Read from the global record separator
- length()
- '[]'
- '[]=' Warning: Partial implementation. Look for TODO
- perl() Returns a Perl representation of the Str.
- to_s() Returns self
self
self
.
Returns self
self
in reverse order.
self
in reverse order.
Destructive update.
self
with all upper case letters converted to lower case
self
with all lower case letters converted to upper case
Returns a copy of C<self> with the first character converted to uppercase and the remainder to lowercase.
Return the number of characters in C<self>
subscript operator. Accepts [(-)? int], [(-)?int, (-)?int]
Functions
- lc()
- lcfirst()
- uc
- ucfirst
- capitalize
- split
- join Note: partial implementation only
- substr
- chop
our Str multi Str::lc ( Str $string )Returns the input string after converting each character to its lowercase form, if uppercase.
our Str multi Str::lcfirst ( Str $string )Like
lc
, but only affects the first character.
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".
our Str multi Str::ucfirst ( Str $string )Performs a Unicode "titlecase" operation on the first character of the string.
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.
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
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
our Str method Str::chop ( Str $string: )Returns string with one Char removed from the end.
TODO Functions
- p5chop
- p5chomp
- chomp
- 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 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.
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.
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.)
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 )