Tcl_NewStringObj and Tcl_SetStringObj create a new object or modify an existing object to hold a copy of the string given by bytes and length. Tcl_NewStringObj returns a pointer to a newly created object with reference count zero. Both procedures set the object to hold a copy of the specified string. Tcl_SetStringObj frees any old string representation as well as any old internal representation of the object.
Tcl_GetStringFromObj and Tcl_GetString return an object's string representation. This is given by the returned byte pointer and (for Tcl_GetStringFromObj) length, which is stored in lengthPtr if it is non-NULL. If the object's string representation is invalid (its byte pointer is NULL), the string representation is regenerated from the object's internal representation. The storage referenced by the returned byte pointer is owned by the object manager and should not be modified by the caller. The procedure Tcl_GetString is used in the common case where the caller does not need the length of the string representation.
Tcl_AppendToObj appends the data given by bytes and length to the object specified by objPtr. It does this in a way that handles repeated calls relatively efficiently (it overallocates the string space to avoid repeated reallocations and copies of object's string value).
Tcl_AppendObjToObj is similar to Tcl_AppendToObj, but it appends the string value of appendObjPtr to objPtr.
Tcl_AppendStringsToObj is similar to Tcl_AppendToObj except that it can be passed more than one value to append and each value must be a null-terminated string (i.e. none of the values may contain internal null characters). Any number of string arguments may be provided, but the last argument must be a NULL pointer to indicate the end of the list.
The Tcl_SetObjLength procedure changes the length of the string value of its objPtr argument. If the newLength argument is greater than the space allocated for the object's string, then the string space is reallocated and the old value is copied to the new space; the bytes between the old length of the string and the new length may have arbitrary values. If the newLength argument is less than the current length of the object's string, with objPtr->length is reduced without reallocating the string space; the original allocated size for the string is recorded in the object, so that the string length can be enlarged in a subsequent call to Tcl_SetObjLength without reallocating storage. In all cases Tcl_SetObjLength leaves a null character at objPtr->bytes[newLength].
The Tcl_ConcatObj function returns a new string object whose value is the space-separated concatenation of the string representations of all of the objects in the objv array. Tcl_ConcatObj eliminates leading and trailing white space as it copies the string representations of the objv array to the result. If an element of the objv array consists of nothing but white space, then that object is ignored entirely. This white-space removal was added to make the output of the concat command cleaner-looking. Tcl_ConcatObj returns a pointer to a newly-created object whose ref count is zero.
Copyright © 1994-1997 Sun Microsystems, Inc. Copyright © 1995-1997 Roger E. Critchlow Jr.