parrotcode: Parrot Strings | |
Contents | C |
src/string.c - Parrot Strings
This file implements the non-ICU parts of the Parrot string subsystem.
Note that bufstart
and buflen
are used by the memory subsystem The string functions may only use buflen
to determine,
if there is some space left beyond bufused
.
This is the only valid usage of these two data members,
beside setting bufstart
/buflen
for external strings.
static void Parrot_unmake_COW(Interp *interpreter, STRING *s)
static void copy_string_header(Interp *interpreter, String *dest, String *src)
static STRING *Parrot_make_COW_reference(Interp *interpreter, STRING *s)
static STRING *Parrot_reuse_COW_reference(Interp *interpreter, STRING *s, STRING *reuse)
static void Parrot_make_COW_reference_from_header(Interp *interpreter, STRING *s, STRING *d)
STRING *string_set(Interp *interpreter, STRING *dest, STRING *src)
Creation, enlargement, etc.
void string_init(Interp*)
void string_deinit(Interp*)
UINTVAL string_capacity(Interp *interpreter, STRING *s)
STRING *string_make_empty(Interp *interpreter, parrot_string_representation_t representation, UINTVAL capacity)
STRING *string_append(Interp *interpreter, STRING *a, STRING *b, UINTVAL Uflags)
STRING *string_from_cstring(Interp *interpreter, const void *buffer, UINTVAL len)
STRING *string_from_const_cstring(Interp *interpreter, const void *buffer, UINTVAL len)
const char *string_primary_encoding_for_representation(Interp *interpreter, parrot_string_representation_t representation)
STRING *const_string(Interp *interpreter, const char *buffer)
STRING *string_make(Interp *interpreter, const void *buffer, UINTVAL len, const char *charset, UINTVAL flags)
len
bytes of string data read from buffer
.charset
specifies the string's representation.
The currently recognised values are: 'iso-8859-1'
'ascii'
'binary'
charset
is unspecified the default charset 'iso-8859-1' will be used.flags
is optionally one or more PObj_*
flags OR
-ed together.STRING *string_grow(Interp *interpreter, STRING *s, INTVAL addlen)
UINTVAL string_length(Interp *interpreter, const STRING *s)
INTVAL string_index(Interp *interpreter, const STRING *s, UINTVAL idx)
INTVAL string_str_index(Interp *interpreter, const STRING *s, const STRING *s2, UINTVAL start)
start
. The return value is a (0 based) offset in characters, not bytes. If second string is not specified, then return -1.INTVAL string_ord(Interp *interpreter, const STRING *s, INTVAL idx)
STRING *string_chr(Interp *interpreter, UINTVAL character)
STRING *string_copy(Interp *interpreter, STRING *s)
INTVAL string_compute_strlen(Interp *interpreter, STRING *s)
INTVAL string_max_bytes(Interp *interpreter, STRING *s, INTVAL nchars)
STRING *string_concat(Interp *interpreter, STRING *a, STRING *b, UINTVAL Uflags)
NULL
, then a copy of the non-NULL
string is returned. If both strings are NULL
, then a new zero-length string is created and returned.STRING *string_repeat(Interp *interpreter, const STRING *s, UINTVAL num, STRING **d)
STRING *string_substr(Interp *interpreter, STRING *src, INTVAL offset, INTVAL length, STRING **d, int replace_dest)
length
from offset
from the specified Parrot string and stores it in **d
, allocating memory if necessary. The substring is also returned.STRING *string_replace(Interp *interpreter, STRING *src, INTVAL offset, INTVAL length, STRING *rep, STRING **d)
substr EXPR, OFFSET, LENGTH, REPLACEMENT
length
characters from offset
in the first Parrot string with the second Parrot string, returning what was replaced.STRING *string_chopn(Interp *interpreter, STRING *s, INTVAL n)
n
characters of the specified Parrot string. If n
is negative, cuts the string after +n
characters.INTVAL string_equal(Interp *interpreter, STRING *s1, STRING *s2)
static void make_writable(Interp *interpreter, STRING **s, const size_t len, parrot_string_representation_t representation)
len
. The representation
argument is required in case a new Parrot string has to be created.STRING *string_bitwise_and(Interp *interpreter, STRING *s1, STRING *s2, STRING **dest)
AND
on two Parrot string, performing type and encoding conversions if necessary. If the second string is not NULL
then it is reused, otherwise a new Parrot string is created.STRING *string_bitwise_or(Interp *interpreter, STRING *s1, STRING *s2, STRING **dest)
OR
on two Parrot string, performing type and encoding conversions if necessary. If the second string is not NULL
then it is reused, otherwise a new Parrot string is created.STRING *string_bitwise_xor(Interp *interpreter, STRING *s1, STRING *s2, STRING **dest)
XOR
on two Parrot strings, performing type and encoding conversions if necessary. If the second string is not NULL
then it is reused, otherwise a new Parrot string is created.STRING *string_bitwise_not(Interp *interpreter, STRING *s, STRING **dest)
NOT
on a Parrot string. If the second string is not NULL
then it is reused, otherwise a new Parrot string is created.INTVAL string_bool(Interp *interpreter, const STRING *s)
0
, ""
or "0"
.STRING *string_nprintf(Interp *interpreter, STRING *dest, INTVAL bytelen, const char *format, ...)
Parrot_snprintf()
except that it writes to and returns a Parrot string.bytelen
does not include space for a (non-existent) trailing '\0'
. dest
may be a NULL
pointer, in which case a new native string will be created. If bytelen
is 0, the behaviour becomes more sprintf
-ish than snprintf
-like. bytelen
is measured in the encoding of *dest
.STRING *string_printf(Interp *interpreter, const char *format, ...)
INTVAL string_to_int(Interp *interpreter, const STRING *s)
sign = '+' | '-'
digit = "Any code point considered a digit by the chartype"
indicator = 'e' | 'E'
digits = digit [digit]...
decimal-part = digits '.' [digits] | ['.'] digits
exponent-part = indicator [sign] digits
numeric-string = [sign] decimal-part [exponent-part]
FLOATVAL string_to_num(Interp *interpreter, const STRING *s)
string_to_int()
except that a floating-point value is returned.STRING *string_from_int(Interp *interpreter, INTVAL i)
STRING *string_from_num(Interp *interpreter, FLOATVAL f)
char *string_to_cstring(Interp *interpreter, STRING *s)
string_cstring_free()
to free the string. Failure to do this will result in a memory leak.void string_cstring_free(void *ptr)
string_to_cstring()
.void string_pin(Interp *interpreter, STRING *s)
void string_unpin(Interp *interpreter, STRING *s)
string_pin()
so that the string once again uses managed memory.size_t string_hash(Interp *interpreter, Hash *hash, STRING *s)
s-
hashval>.STRING *string_unescape_cstring(Interp *interpreter, char *cstring, char delimiter, char *charset)
\xhh 1..2 hex digits
\ooo 1..3 oct digits
\cX control char X
\x{h..h} 1..8 hex digits
\uhhhh 4 hex digits
\Uhhhhhhhh 8 hex digits
\a, \b, \t, \n, \v, \f, \r, \e, \?
STRING *string_upcase(Interp *interpreter, const STRING *s)
void string_upcase_inplace(Interp *interpreter, STRING *s)
STRING *string_downcase(Interp *interpreter, const STRING *s)
void string_downcase_inplace(Interp *interpreter, STRING *s)
STRING *string_titlecase(Interp *interpreter, const STRING *s)
void string_titlecase_inplace(Interp *interpreter, STRING *s)
STRING *string_increment(Interp *, const STRING *)
|