NAME

src/pmc/stringhandle.pmc - StringHandle PMC

DESCRIPTION

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.

Methods

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 close()
Reset some core data for the StringHandle, but don't delete the string data, as it may be wanted later (for capturing the results).
METHOD is_closed()
Check if the StringHandle is open.
METHOD read(INTVAL bytes)
Read the entire contents of the stringhandle and return it in a string. The bytes argument is currently ignored.
METHOD readline()
Read a line from the stringhandle and return it in a string. (Currently only responds to "\n" newlines.)
METHOD readall(STRING *name);
Read the entire contents of the StringHandle into a Parrot string. On a StringHandle object that isn't opened yet, returns an empty string.
METHOD flush()
Clear the StringHandle by resetting it to a null value.
METHOD print([INTVAL|FLOATVAL|STRING *|PMC*] 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 encoding(STRING *new_encoding)
Set or retrieve the encoding attribute (a string name of the selected encoding scheme) 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.