Pegasus InfoCorp: Web site design and web software development company

Tcl_StringObj (3)

manipulate Tcl objects as strings

SYNOPSIS

    #include <tcl.h>
    Tcl_Obj *
    Tcl_NewStringObj(bytes, length)
    Tcl_SetStringObj(objPtr, bytes, length)
    char *
    Tcl_GetStringFromObj(objPtr, lengthPtr)
    Tcl_AppendToObj(objPtr, bytes, length)
    Tcl_AppendStringsToObj(objPtr, string, string, ... (char *) NULL)
    Tcl_SetObjLength(objPtr, newLength)
    Tcl_Obj *
    Tcl_ConcatObj(objc, objv)
    

ARGUMENTS

    Tcl_Interp *lengthPtr out char *bytes in Points to the first byte of an array of bytes used to set or append to a string object. This byte array may contain embedded null bytes unless length is negative. int length in The number of bytes to copy from bytes when initializing, setting, or appending to a string object. If negative, all bytes up to the first null are used. Tcl_Obj *objPtr in/out Points to an object to manipulate. int *lengthPtr out If non-NULL, the location where Tcl_GetStringFromObj will store the the length of an object's string representation. char *string in Null-terminated string value to append to objPtr. int newLength in New length for the string value of objPtr, not including the final NULL character. int objc in The number of elements to concatenate. Tcl_Obj *objv[] in The array of objects to concatenate.

DESCRIPTION

    The procedures described in this manual entry allow Tcl objects to be manipulated as string values. They use the internal representation of the object to store additional information to make the string manipulations more efficient. In particular, they make a series of append operations efficient by allocating extra storage space for the string so that it doesn't have to be copied for each append.

    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 returns an object's string representation. This is given by the returned byte pointer and 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.

    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_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.

SEE ALSO

    Tcl_NewObj Tcl_IncrRefCount Tcl_DecrRefCount

KEYWORDS

    append, internal representation, object, object type, string object, string type, string representation, concat, concatenate

    '\" '\" Copyright (c) 1995-1997 Sun Microsystems, Inc. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" RCS: @(#) $Id: Notifier.3,v 1.2 1998/09/14 18:39:49 stanton Exp $ '\" '\" The definitions below are for supplemental macros used in Tcl/Tk '\" manual entries. '\" '\" .AP type name in/out ?indent? '\" Start paragraph describing an argument to a library procedure. '\" type is type of argument (int, etc.), in/out is either "in", "out", '\" or "in/out" to describe whether procedure reads or modifies arg, '\" and indent is equivalent to second arg of .IP (shouldn't ever be '\" needed; use .AS below instead) '\" '\" .AS ?type? ?name? '\" Give maximum sizes of arguments for setting tab stops. Type and '\" name are examples of largest possible arguments that will be passed '\" to .AP later. If args are omitted, default tab stops are used. '\" '\" .BS '\" Start box enclosure. From here until next .BE, everything will be '\" enclosed in one large box. '\" '\" .BE '\" End of box enclosure. '\" '\" .CS '\" Begin code excerpt. '\" '\" .CE '\" End code excerpt. '\" '\" .VS ?version? ?br? '\" Begin vertical sidebar, for use in marking newly-changed parts '\" of man pages. The first argument is ignored and used for recording '\" the version when the .VS was added, so that the sidebars can be '\" found and removed when they reach a certain age. If another argument '\" is present, then a line break is forced before starting the sidebar. '\" '\" .VE '\" End of vertical sidebar. '\" '\" .DS '\" Begin an indented unfilled display. '\" '\" .DE '\" End of indented unfilled display. '\" '\" .SO '\" Start of list of standard options for a Tk widget. The '\" options follow on successive lines, in four columns separated '\" by tabs. '\" '\" .SE '\" End of list of standard options for a Tk widget. '\" '\" .OP cmdName dbName dbClass '\" Start of description of a specific option. cmdName gives the '\" option's name as specified in the class command, dbName gives '\" the option's name in the option database, and dbClass gives '\" the option's class in the option database. '\" '\" .UL arg1 arg2 '\" Print arg1 underlined, then print arg2 normally. '\" '\" RCS: @(#) $Id: man.macros,v 1.2 1998/09/14 18:39:54 stanton Exp $ '\" '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. t .wh -1.3i ^B ^l \n(.l b '\" # Start an argument description AP !"\\$4"" .TP \\$4 \{\ !"\\$2"" .TP \\n()Cu .TP 15