Seth Woolley's Man Viewer

Tcl_DStringFree(3) - Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringEndSublist, Tcl_DStringFree, Tcl_DStringGetResult, Tcl_DStringInit, Tcl_DStringLength, Tcl_DStringResult, Tcl_DStringSetLength, Tcl_DStringStartSublist, Tcl_DStringTrunc, Tcl_DStringValue - manipulate dynamic strings - man 3 Tcl_DStringFree

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

Tcl_DString(3)              Tcl Library Procedures              Tcl_DString(3)



______________________________________________________________________________

NAME
       Tcl_DStringInit,      Tcl_DStringAppend,      Tcl_DStringAppendElement,
       Tcl_DStringStartSublist,   Tcl_DStringEndSublist,    Tcl_DStringLength,
       Tcl_DStringValue,        Tcl_DStringSetLength,        Tcl_DStringTrunc,
       Tcl_DStringFree, Tcl_DStringResult, Tcl_DStringGetResult  -  manipulate
       dynamic strings

SYNOPSIS
       #include <tcl.h>

       Tcl_DStringInit(dsPtr)

       char *
       Tcl_DStringAppend(dsPtr, string(3,n), length)

       char *
       Tcl_DStringAppendElement(dsPtr, string(3,n))

       Tcl_DStringStartSublist(dsPtr)

       Tcl_DStringEndSublist(dsPtr)

       int
       Tcl_DStringLength(dsPtr)

       char *
       Tcl_DStringValue(dsPtr)

       Tcl_DStringSetLength(dsPtr, newLength)

       Tcl_DStringTrunc(dsPtr, newLength)

       Tcl_DStringFree(dsPtr)

       Tcl_DStringResult(interp, dsPtr)

       Tcl_DStringGetResult(interp, dsPtr)

ARGUMENTS
       Tcl_DString   *dsPtr      (in(1,8)/out)  Pointer  to  structure that is used
                                           to manage a dynamic string.

       CONST char    *string(3,n)     (in(1,8))      Pointer to  characters  to  add  to
                                           dynamic string.

       int           length      (in(1,8))      Number of characters from string(3,n) to
                                           add to dynamic string.  If -1,  add
                                           all characters up to null terminat-
                                           ing character.

       int           newLength   (in(1,8))      New length for dynamic string(3,n),  not
                                           including  null terminating charac-
                                           ter.

       Tcl_Interp    *interp     (in(1,8)/out)  Interpreter whose result is  to  be
                                           set(7,n,1 builtins)  from  or  moved to the dynamic
                                           string.
_________________________________________________________________


DESCRIPTION
       Dynamic strings provide a mechanism for building  up  arbitrarily  long
       strings  by  gradually appending information.  If the dynamic string(3,n) is
       short then there will be no memory allocation overhead;  as the  string(3,n)
       gets(3,n) larger, additional space will be allocated as needed.

       Tcl_DStringInit  initializes  a  dynamic  string(3,n)  to  zero length.  The
       Tcl_DString structure must have  been  allocated  by  the  caller.   No
       assumptions are made about the current state of the structure; anything
       already in(1,8) it is discarded.  If the structure has been used previously,
       Tcl_DStringFree  should be called first to free up any memory allocated
       for the old string.

       Tcl_DStringAppend adds new information to a dynamic string(3,n),  allocating
       more memory for the string(3,n) if(3,n) needed.  If length is less(1,3) than zero then
       everything in(1,8) string(3,n) is appended  to  the  dynamic  string(3,n);   otherwise
       length  specifies  the  number  of  bytes to append.  Tcl_DStringAppend
       returns a pointer to the characters of the new string.  The string(3,n)  can
       also be retrieved from the string(3,n) field of the Tcl_DString structure.

       Tcl_DStringAppendElement is similar to Tcl_DStringAppend except that it
       doesn't take a length argument (it appends all of string(3,n)) and  it  con-
       verts   the   string(3,n)   to  a  proper  list  element  before  appending.
       Tcl_DStringAppendElement adds a separator space  before  the  new  list
       element  unless the new list element is the first in(1,8) a list or sub-list
       (i.e. either the current string(3,n) is empty, or  it  contains  the  single
       character  ``{'',  or the last two characters of the current string(3,n) are
       `` {'').  Tcl_DStringAppendElement returns a pointer to the  characters
       of the new string.

       Tcl_DStringStartSublist and Tcl_DStringEndSublist can be used to create
       nested lists.  To append a list element that is itself a sublist, first
       call  Tcl_DStringStartSublist,  then  call Tcl_DStringAppendElement for
       each of the elements in(1,8) the sublist, then call Tcl_DStringEndSublist to
       end  the sublist.  Tcl_DStringStartSublist appends a space character if(3,n)
       needed, followed by an open(2,3,n)  brace;   Tcl_DStringEndSublist  appends  a
       close(2,7,n) brace.  Lists can be nested to any depth.

       Tcl_DStringLength  is  a  macro  that  returns  the current length of a
       dynamic  string(3,n)  (not  including  the  terminating   null   character).
       Tcl_DStringValue is a  macro that returns a pointer to the current con-
       tents of a dynamic string.


       Tcl_DStringSetLength changes  the  length  of  a  dynamic  string.   If
       newLength  is less(1,3) than the string(3,n)'s current length, then the string(3,n) is
       truncated.  If newLength is greater than the string(3,n)'s  current  length,
       then  the string(3,n) will become longer and new space will be allocated for
       the string(3,n) if(3,n) needed.  However, Tcl_DStringSetLength will not  initial-
       ize  the  new space except to provide a terminating null character;  it
       is up to the caller to fill in(1,8)  the  new  space.   Tcl_DStringSetLength
       does not free up the string(3,n)'s storage space even if(3,n) the string(3,n) is trun-
       cated to zero length, so Tcl_DStringFree will still need to be  called.

       Tcl_DStringTrunc  changes  the length of a dynamic string.  This proce-
       dure is now deprecated.  Tcl_DStringSetLength  should be used  instead.

       Tcl_DStringFree should be called when you're finished using the string.
       It frees up any memory that was allocated for the string(3,n) and reinitial-
       izes the string(3,n)'s value to an empty string.

       Tcl_DStringResult sets the result of interp to the value of the dynamic
       string(3,n) given by dsPtr.  It does this by moving a pointer from dsPtr  to
       the interpreter's result.  This saves the cost of allocating new memory
       and copying  the  string.   Tcl_DStringResult  also  reinitializes  the
       dynamic string(3,n) to an empty string.

       Tcl_DStringGetResult  does  the opposite of Tcl_DStringResult.  It sets
       the value of dsPtr to the result  of  interp  and  it  clears  interp's
       result.   If  possible  it does this by moving a pointer rather than by
       copying the string.


KEYWORDS
       append, dynamic string(3,n), free, result



Tcl                                   7.4                       Tcl_DString(3)

References for this manual (incoming links)