Manual Pages for UNIX Darwin command on man Tcl_DStringInit
MyWebUniversity

Manual Pages for UNIX Darwin command on man Tcl_DStringInit

TclDString(3) Tcl Library Procedures TclDString(3)

NAME

TclDStringInit, TclDStringAppend, TclDStringAppendElement, TclDStringStartSublist, TclDStringEndSublist, TclDStringLength, TclDStringValue, TclDStringSetLength, TclDStringTrunc,

TclDStringFree, TclDStringResult, TclDStringGetResult - manipulate

dynamic strings

SYNOPSIS

##iinncclluuddee <>

TTccllDDSSttrriinnggIInniitt(dsPtr) char * TTccllDDSSttrriinnggAAppppeenndd(dsPtr, string, length) char * TTccllDDSSttrriinnggAAppppeennddEElleemmeenntt(dsPtr, string) TTccllDDSSttrriinnggSSttaarrttSSuubblliisstt(dsPtr) TTccllDDSSttrriinnggEEnnddSSuubblliisstt(dsPtr) int TTccllDDSSttrriinnggLLeennggtthh(dsPtr) char * TTccllDDSSttrriinnggVVaalluuee(dsPtr) TTccllDDSSttrriinnggSSeettLLeennggtthh(dsPtr, newLength) TTccllDDSSttrriinnggTTrruunncc(dsPtr, newLength) TTccllDDSSttrriinnggFFrreeee(dsPtr) TTccllDDSSttrriinnggRReessuulltt(interp, dsPtr) TTccllDDSSttrriinnggGGeettRReessuulltt(interp, dsPtr) AARRGGUUMMEENNTTSS TclDString *dsPtr (in/out) Pointer to structure that is used to manage a dynamic string. CONST char *string (in) Pointer to characters to add to dynamic string. int length (in) Number of characters from string to

add to dynamic string. If -1, add

all characters up to null terminat-

ing character. int newLength (in) New length for dynamic string, not

including null terminating charac-

ter. TclInterp *interp (in/out) Interpreter whose result is to be set 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 is short then there will be no memory allocation overhead; as the string gets larger, additional space will be allocated as needed. TTccllDDSSttrriinnggIInniitt initializes a dynamic string to zero length. The TclDString structure must have been allocated by the caller. No assumptions are made about the current state of the structure; anything already in it is discarded. If the structure has been used previously, TTccllDDSSttrriinnggFFrreeee should be called first to free up any memory allocated for the old string. TTccllDDSSttrriinnggAAppppeenndd adds new information to a dynamic string, allocating more memory for the string if needed. If length is less than zero then everything in string is appended to the dynamic string; otherwise length specifies the number of bytes to append. TTccllDDSSttrriinnggAAppppeenndd returns a pointer to the characters of the new string. The string can also be retrieved from the string field of the TclDString structure. TTccllDDSSttrriinnggAAppppeennddEElleemmeenntt is similar to TTccllDDSSttrriinnggAAppppeenndd except that it

doesn't take a length argument (it appends all of string) and it con-

verts the string to a proper list element before appending. TTccllDDSSttrriinnggAAppppeennddEElleemmeenntt adds a separator space before the new list

element unless the new list element is the first in a list or sub-list

(i.e. either the current string is empty, or it contains the single character ``{'', or the last two characters of the current string are `` {''). TTccllDDSSttrriinnggAAppppeennddEElleemmeenntt returns a pointer to the characters of the new string. TTccllDDSSttrriinnggSSttaarrttSSuubblliisstt and TTccllDDSSttrriinnggEEnnddSSuubblliisstt can be used to create nested lists. To append a list element that is itself a sublist, first call TTccllDDSSttrriinnggSSttaarrttSSuubblliisstt, then call TTccllDDSSttrriinnggAAppppeennddEElleemmeenntt for each of the elements in the sublist, then call TTccllDDSSttrriinnggEEnnddSSuubblliisstt to end the sublist. TTccllDDSSttrriinnggSSttaarrttSSuubblliisstt appends a space character if needed, followed by an open brace; TTccllDDSSttrriinnggEEnnddSSuubblliisstt appends a close brace. Lists can be nested to any depth. TTccllDDSSttrriinnggLLeennggtthh is a macro that returns the current length of a dynamic string (not including the terminating null character).

TTccllDDSSttrriinnggVVaalluuee is a macro that returns a pointer to the current con-

tents of a dynamic string. TTccllDDSSttrriinnggSSeettLLeennggtthh changes the length of a dynamic string. If newLength is less than the string's current length, then the string is truncated. If newLength is greater than the string's current length, then the string will become longer and new space will be allocated for

the string if needed. However, TTccllDDSSttrriinnggSSeettLLeennggtthh will not initial-

ize the new space except to provide a terminating null character; it is up to the caller to fill in the new space. TTccllDDSSttrriinnggSSeettLLeennggtthh

does not free up the string's storage space even if the string is trun-

cated to zero length, so TTccllDDSSttrriinnggFFrreeee will still need to be called.

TTccllDDSSttrriinnggTTrruunncc changes the length of a dynamic string. This proce-

dure is now deprecated. TTccllDDSSttrriinnggSSeettLLeennggtthh should be used instead. TTccllDDSSttrriinnggFFrreeee should be called when you're finished using the string.

It frees up any memory that was allocated for the string and reinitial-

izes the string's value to an empty string. TTccllDDSSttrriinnggRReessuulltt sets the result of interp to the value of the dynamic string 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. TTccllDDSSttrriinnggRReessuulltt also reinitializes the dynamic string to an empty string. TTccllDDSSttrriinnggGGeettRReessuulltt does the opposite of TTccllDDSSttrriinnggRReessuulltt. 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. KKEEYYWWOORRDDSS append, dynamic string, free, result Tcl 7.4 TclDString(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™