NAME ^

src/builtins/any-str.pir - Str-like functions and methods for Any

DESCRIPTION ^

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.

Methods ^

chars()
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.
chop
 our Str method Str::chop ( Str  $string: )
Returns string with one Char removed from the end.
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.
trim()
Remove leading and trailing whitespace from a string.
comb()
Partial implementation for now, returns a list of strings (instead of a list of match objects).
':d'()
 our Bool multi Str::':d' ( Str $filename )
Returns whether the file with the name indicated by the invocant is a directory.
':e'()
 our Bool multi Str::':e' ( Str $filename )
Returns whether the file with the name indicated by the invocant exists.
':f'()
 our Bool multi Str::':f' ( Str $filename )
Returns whether the file with the name indicated by the invocant is a plain file.
fmt
 our Str multi Any::fmt ( Str $format )
Returns the invocant formatted by an implicit call to sprintf.
index()
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.
match()
reverse
rindex()
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
substr()
trans()
  Implementation of transliteration
subst
 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.
ord()
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.
unpack
 our List multi Str::unpack ( Str $template, Str $packval )
Takes a string and expands it out into a list of values.


parrot