Tcl_DString(3)
π NAME π
Tcl_DString(3) β straight outta the Tcl Library Procedures β is the whole manipulate dynamic strings situation, and it covers all these besties: Tcl_DStringInit, Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringStartSublist, Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue, Tcl_DStringSetLength, Tcl_DStringTrunc, Tcl_DStringFree, Tcl_DStringResult, Tcl_DStringGetResult.
β¨ SYNOPSIS β¨
#include <tcl.h>
Tcl_DStringInit(dsPtr)
char *
Tcl_DStringAppend(dsPtr, bytes, length)
char *
Tcl_DStringAppendElement(dsPtr, element)
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/out) β pointer to the structure that is used to manage a dynamic string.const char *bytes(in) β pointer to characters to append to the dynamic string.const char *element(in) β pointer to characters to append as a list element to the dynamic string.int length(in) β number of bytes frombytesto add to the dynamic string. If-1, add all characters up to the null terminating character.int newLength(in) β new length for the dynamic string, not including the null terminating character.Tcl_Interp *interp(in/out) β interpreter whose result is to be set from or moved to the dynamic string.
π¦ DESCRIPTION π¦
Okay so dynamic strings are literally the build-a-string workshop: they 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. The way that this just works is lowkey iconic π .
Tcl_DStringInitβ initializes a dynamic string to zero length. TheTcl_DStringstructure 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,Tcl_DStringFreeshould be called first to free up any memory allocated for the old string.Tcl_DStringAppendβ adds new information to a dynamic string, allocating more memory for the string if needed. Iflengthis less than zero then everything inbytesis appended to the dynamic string; otherwiselengthspecifies the number of bytes to append.Tcl_DStringAppendreturns a pointer to the characters of the new string. The string can also be retrieved from thestringfield of theTcl_DStringstructure. This one ate fr fr π₯.Tcl_DStringAppendElementβ similar toTcl_DStringAppendexcept that it does not take a length argument (it appends all ofelement) and it converts the string to a proper list element before appending.Tcl_DStringAppendElementadds 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{).Tcl_DStringAppendElementreturns a pointer to the characters of the new string.Tcl_DStringStartSublistandTcl_DStringEndSublistβ can be used to create nested lists. To append a list element that is itself a sublist, first callTcl_DStringStartSublist, then callTcl_DStringAppendElementfor each of the elements in the sublist, then callTcl_DStringEndSublistto end the sublist.Tcl_DStringStartSublistappends a space character if needed, followed by an open brace;Tcl_DStringEndSublistappends a close brace. Lists can be nested to any depth. Nested-list main character energy, no cap π«Ά.Tcl_DStringLengthβ is a macro that returns the current length of a dynamic string (not including the terminating null character).Tcl_DStringValueβ is a macro that returns a pointer to the current contents of a dynamic string. Cute little macro besties π.Tcl_DStringSetLengthβ changes the length of a dynamic string. IfnewLengthis less than the string's current length, then the string is truncated. IfnewLengthis 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,Tcl_DStringSetLengthwill not initialize the new space except to provide a terminating null character; it is up to the caller to fill in the new space.Tcl_DStringSetLengthdoes not free up the string's storage space even if the string is truncated to zero length, soTcl_DStringFreewill still need to be called. This is the highkey important one, bestie β do not skip the cleanup π.Tcl_DStringTruncβ changes the length of a dynamic string. This procedure is now deprecated.Tcl_DStringSetLengthshould be used instead. > π¨ Deprecated alert:Tcl_DStringTruncis giving retired icon β useTcl_DStringSetLengthinstead, periodt.Tcl_DStringFreeβ should be called when you are finished using the string. It frees up any memory that was allocated for the string and reinitializes the string's value to an empty string. Cleanup slay π§.Tcl_DStringResultβ sets the result ofinterpto the value of the dynamic string given bydsPtr. It does this by moving a pointer fromdsPtrto the interpreter's result. This saves the cost of allocating new memory and copying the string.Tcl_DStringResultalso reinitializes the dynamic string to an empty string. Literally the main character move π.Tcl_DStringGetResultβ does the opposite ofTcl_DStringResult. It sets the value ofdsPtrto the result ofinterpand it clearsinterp's result. If possible it does this by moving a pointer rather than by copying the string. Reverse uno card, obsessed π.
π KEYWORDS π
append, dynamic string, free, result β that's the keyword vibe check, iykyk π.
β¨ Tcl 7.4 β’ Tcl_DString(3) β’ no date on the footer β periodt β¨
π¦ where this page comes from
- alpine 3.22: tcl-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tcl-doc 8.6.17-r0 Β· TCL
- alpine 3.24: tcl-doc 8.6.17-r1 Β· TCL
- arch rolling: tcl 8.6.16-1 Β· TCL
- centos-stream 10: tcl-doc 1:8.6.13-4.el10 Β· TCL AND GPL-3.0-or-later WITH bison-exception-2.2 AND BSD-3-Clause
- centos-stream 9: tcl-doc 1:8.6.10-7.el9 Β· TCL
- opensuse-leap 16.0: tcl-devel 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl-devel 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl-devel 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl-devel 8.6.15-160000.2.2 Β· TCL
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms