parrotcode: C<Str>-like functions and methods for C<Any> | |
Contents | Language Implementations | Perl6 |
src/builtins/any-str.pir - Str
-like functions and methods for Any
This file implements the methods and functions of Any
that are most closely associated with the Str
class or role.
We place them here instead of src/classes/Any.pir to keep the size of that file down and to emphasize their generic,
"built-in" nature.
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 Str method Str::chop ( Str $string: )Returns string with one Char removed from the end.
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.
our Bool multi Str::':d' ( Str $filename )Returns whether the file with the name indicated by the invocant is a directory.
our Bool multi Str::':e' ( Str $filename )Returns whether the file with the name indicated by the invocant exists.
our Bool multi Str::':f' ( Str $filename )Returns whether the file with the name indicated by the invocant is a plain file.
our Str multi Any::fmt ( Str $format )Returns the invocant formatted by an implicit call to
sprintf
.
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 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
Implementation of transliteration
our Str method Str::subst ( Any $string: Any $substring, Any $replacement ) our Str method Str::subst ( Any $string: Code $regexp, Any $replacement )Replaces the first occurrence of a given substring or a regular expression match with some other substring.Partial implementation. The :g modifier on regexps doesn't work, for example.
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 List multi Str::unpack ( Str $template, Str $packval )Takes a string and expands it out into a list of values.
|