src/pmc/stringhandle.pmc - StringHandle PMC


The StringHandle PMC performs I/O operations, but on an internal string rather than an external file. Commonly used as a mock FileHandle for testing.

Internal Functions

static int encoding_is_utf8(PARROT_INTERP, const STRING *s)
Helper function for internal usage. Return 1 if the string argument is not null and has utf8 encoding, 0 otherwise.

Vtable Functions

void init()
Initializes a newly created StringHandle object.
PMC *clone()
Create a copy of the stringhandle.
void mark()
Mark active stringhandle data as live.
INTVAL get_bool()
Returns whether the StringHandle has reached the end of the file.


METHOD open(STRING *filename :optional, STRING *mode :optional)
Opens a string handle with the given mode. The filename is not used, but is stored for mocking.
METHOD is_closed()
Check if the StringHandle is open.
METHOD readall(STRING *name);
Read the rest of the contents of the StringHandle into a Parrot string. On a StringHandle object that isn't opened yet, returns an empty string.To ensure readall semantics seek to position 0, which needs to be done in this case by checking is_closed() and reopening the StringHandle.
METHOD flush()
Clear the StringHandle by resetting it to a null value.
Print the passed in integer, number, string, or PMC to the stringhandle. (Integers, numbers, and strings are auto-boxed as PMCs.)
METHOD puts(STRING *value)
Print the string to the stringhandle.
METHOD buffer_type(STRING *new_type :optional)
Set or retrieve the buffering attribute for the stringhandle. This attribute is ignored, but stored for mocking.
METHOD buffer_size(INTVAL new_size :optional)
Returns the current size of the stringhandle.
METHOD mode()
Retrieve the read mode string for the stringhandle.
METHOD eof()
Check if the StringHandle is at end-of-file (if it has read to the end of the string data).
METHOD get_fd()
StringHandles do not use integer file descriptors, so always returns an error value.
METHOD close()
Close the handle.