Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / Tcl_AppendStringsToObjVA.3
CommitLineData
920dae64
AT
1'\"
2'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: StringObj.3,v 1.13.2.1 2003/07/18 16:56:24 dgp Exp $
8'\"
9'\" The definitions below are for supplemental macros used in Tcl/Tk
10'\" manual entries.
11'\"
12'\" .AP type name in/out ?indent?
13'\" Start paragraph describing an argument to a library procedure.
14'\" type is type of argument (int, etc.), in/out is either "in", "out",
15'\" or "in/out" to describe whether procedure reads or modifies arg,
16'\" and indent is equivalent to second arg of .IP (shouldn't ever be
17'\" needed; use .AS below instead)
18'\"
19'\" .AS ?type? ?name?
20'\" Give maximum sizes of arguments for setting tab stops. Type and
21'\" name are examples of largest possible arguments that will be passed
22'\" to .AP later. If args are omitted, default tab stops are used.
23'\"
24'\" .BS
25'\" Start box enclosure. From here until next .BE, everything will be
26'\" enclosed in one large box.
27'\"
28'\" .BE
29'\" End of box enclosure.
30'\"
31'\" .CS
32'\" Begin code excerpt.
33'\"
34'\" .CE
35'\" End code excerpt.
36'\"
37'\" .VS ?version? ?br?
38'\" Begin vertical sidebar, for use in marking newly-changed parts
39'\" of man pages. The first argument is ignored and used for recording
40'\" the version when the .VS was added, so that the sidebars can be
41'\" found and removed when they reach a certain age. If another argument
42'\" is present, then a line break is forced before starting the sidebar.
43'\"
44'\" .VE
45'\" End of vertical sidebar.
46'\"
47'\" .DS
48'\" Begin an indented unfilled display.
49'\"
50'\" .DE
51'\" End of indented unfilled display.
52'\"
53'\" .SO
54'\" Start of list of standard options for a Tk widget. The
55'\" options follow on successive lines, in four columns separated
56'\" by tabs.
57'\"
58'\" .SE
59'\" End of list of standard options for a Tk widget.
60'\"
61'\" .OP cmdName dbName dbClass
62'\" Start of description of a specific option. cmdName gives the
63'\" option's name as specified in the class command, dbName gives
64'\" the option's name in the option database, and dbClass gives
65'\" the option's class in the option database.
66'\"
67'\" .UL arg1 arg2
68'\" Print arg1 underlined, then print arg2 normally.
69'\"
70'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
71'\"
72'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
73.if t .wh -1.3i ^B
74.nr ^l \n(.l
75.ad b
76'\" # Start an argument description
77.de AP
78.ie !"\\$4"" .TP \\$4
79.el \{\
80. ie !"\\$2"" .TP \\n()Cu
81. el .TP 15
82.\}
83.ta \\n()Au \\n()Bu
84.ie !"\\$3"" \{\
85\&\\$1 \\fI\\$2\\fP (\\$3)
86.\".b
87.\}
88.el \{\
89.br
90.ie !"\\$2"" \{\
91\&\\$1 \\fI\\$2\\fP
92.\}
93.el \{\
94\&\\fI\\$1\\fP
95.\}
96.\}
97..
98'\" # define tabbing values for .AP
99.de AS
100.nr )A 10n
101.if !"\\$1"" .nr )A \\w'\\$1'u+3n
102.nr )B \\n()Au+15n
103.\"
104.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
105.nr )C \\n()Bu+\\w'(in/out)'u+2n
106..
107.AS Tcl_Interp Tcl_CreateInterp in/out
108'\" # BS - start boxed text
109'\" # ^y = starting y location
110'\" # ^b = 1
111.de BS
112.br
113.mk ^y
114.nr ^b 1u
115.if n .nf
116.if n .ti 0
117.if n \l'\\n(.lu\(ul'
118.if n .fi
119..
120'\" # BE - end boxed text (draw box now)
121.de BE
122.nf
123.ti 0
124.mk ^t
125.ie n \l'\\n(^lu\(ul'
126.el \{\
127.\" Draw four-sided box normally, but don't draw top of
128.\" box if the box started on an earlier page.
129.ie !\\n(^b-1 \{\
130\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
131.\}
132.el \}\
133\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134.\}
135.\}
136.fi
137.br
138.nr ^b 0
139..
140'\" # VS - start vertical sidebar
141'\" # ^Y = starting y location
142'\" # ^v = 1 (for troff; for nroff this doesn't matter)
143.de VS
144.if !"\\$2"" .br
145.mk ^Y
146.ie n 'mc \s12\(br\s0
147.el .nr ^v 1u
148..
149'\" # VE - end of vertical sidebar
150.de VE
151.ie n 'mc
152.el \{\
153.ev 2
154.nf
155.ti 0
156.mk ^t
157\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
158.sp -1
159.fi
160.ev
161.\}
162.nr ^v 0
163..
164'\" # Special macro to handle page bottom: finish off current
165'\" # box/sidebar if in box/sidebar mode, then invoked standard
166'\" # page bottom macro.
167.de ^B
168.ev 2
169'ti 0
170'nf
171.mk ^t
172.if \\n(^b \{\
173.\" Draw three-sided box if this is the box's first page,
174.\" draw two sides but no top otherwise.
175.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
176.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177.\}
178.if \\n(^v \{\
179.nr ^x \\n(^tu+1v-\\n(^Yu
180\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
181.\}
182.bp
183'fi
184.ev
185.if \\n(^b \{\
186.mk ^y
187.nr ^b 2
188.\}
189.if \\n(^v \{\
190.mk ^Y
191.\}
192..
193'\" # DS - begin display
194.de DS
195.RS
196.nf
197.sp
198..
199'\" # DE - end display
200.de DE
201.fi
202.RE
203.sp
204..
205'\" # SO - start of list of standard options
206.de SO
207.SH "STANDARD OPTIONS"
208.LP
209.nf
210.ta 5.5c 11c
211.ft B
212..
213'\" # SE - end of list of standard options
214.de SE
215.fi
216.ft R
217.LP
218See the \\fBoptions\\fR manual entry for details on the standard options.
219..
220'\" # OP - start of full description for a single option
221.de OP
222.LP
223.nf
224.ta 4c
225Command-Line Name: \\fB\\$1\\fR
226Database Name: \\fB\\$2\\fR
227Database Class: \\fB\\$3\\fR
228.fi
229.IP
230..
231'\" # CS - begin code excerpt
232.de CS
233.RS
234.nf
235.ta .25i .5i .75i 1i
236..
237'\" # CE - end code excerpt
238.de CE
239.fi
240.RE
241..
242.de UL
243\\$1\l'|0\(ul'\\$2
244..
245.TH Tcl_StringObj 3 8.1 Tcl "Tcl Library Procedures"
246.BS
247.SH NAME
248Tcl_NewStringObj, Tcl_NewUnicodeObj, Tcl_SetStringObj, Tcl_SetUnicodeObj, Tcl_GetStringFromObj, Tcl_GetString, Tcl_GetUnicodeFromObj, Tcl_GetUnicode, Tcl_GetUniChar, Tcl_GetCharLength, Tcl_GetRange, Tcl_AppendToObj, Tcl_AppendUnicodeToObj, Tcl_AppendStringsToObj, Tcl_AppendStringsToObjVA, Tcl_AppendObjToObj, Tcl_SetObjLength, Tcl_ConcatObj, Tcl_AttemptSetObjLength \- manipulate Tcl objects as strings
249.SH SYNOPSIS
250.nf
251\fB#include <tcl.h>\fR
252.sp
253Tcl_Obj *
254\fBTcl_NewStringObj\fR(\fIbytes, length\fR)
255.sp
256Tcl_Obj *
257\fBTcl_NewUnicodeObj\fR(\fIunicode, numChars\fR)
258.sp
259void
260\fBTcl_SetStringObj\fR(\fIobjPtr, bytes, length\fR)
261.sp
262void
263\fBTcl_SetUnicodeObj\fR(\fIobjPtr, unicode, numChars\fR)
264.sp
265char *
266\fBTcl_GetStringFromObj\fR(\fIobjPtr, lengthPtr\fR)
267.sp
268char *
269\fBTcl_GetString\fR(\fIobjPtr\fR)
270.sp
271Tcl_UniChar *
272\fBTcl_GetUnicodeFromObj\fR(\fIobjPtr, lengthPtr\fR)
273.sp
274Tcl_UniChar *
275\fBTcl_GetUnicode\fR(\fIobjPtr\fR)
276.sp
277Tcl_UniChar
278\fBTcl_GetUniChar\fR(\fIobjPtr, index\fR)
279.sp
280int
281\fBTcl_GetCharLength\fR(\fIobjPtr\fR)
282.sp
283Tcl_Obj *
284\fBTcl_GetRange\fR(\fIobjPtr, first, last\fR)
285.sp
286void
287\fBTcl_AppendToObj\fR(\fIobjPtr, bytes, length\fR)
288.sp
289void
290\fBTcl_AppendUnicodeToObj\fR(\fIobjPtr, unicode, numChars\fR)
291.sp
292void
293\fBTcl_AppendObjToObj\fR(\fIobjPtr, appendObjPtr\fR)
294.sp
295void
296\fBTcl_AppendStringsToObj\fR(\fIobjPtr, string, string, ... \fB(char *) NULL\fR)
297.sp
298void
299\fBTcl_AppendStringsToObjVA\fR(\fIobjPtr, argList\fR)
300.sp
301void
302\fBTcl_SetObjLength\fR(\fIobjPtr, newLength\fR)
303.sp
304int
305\fBTcl_AttemptSetObjLength\fR(\fIobjPtr, newLength\fR)
306.sp
307Tcl_Obj *
308\fBTcl_ConcatObj\fR(\fIobjc, objv\fR)
309.SH ARGUMENTS
310.AS "CONST Tcl_UniChar" *appendObjPtr in/out
311.AP "CONST char" *bytes in
312.VS 8.1
313Points to the first byte of an array of UTF-8-encoded bytes
314used to set or append to a string object.
315This byte array should not contain embedded null bytes
316unless \fIlength\fR is negative. (Applications needing null bytes
317should represent them as the two-byte sequence \fI\\700\\600\fR, use
318\fBTcl_ExternalToUtf\fR to convert, or \fBTcl_NewByteArrayObj\fR if
319the string is a collection of uninterpreted bytes.)
320.VE 8.1
321.AP int length in
322The number of bytes to copy from \fIbytes\fR when
323initializing, setting, or appending to a string object.
324If negative, all bytes up to the first null are used.
325.AP "CONST Tcl_UniChar" *unicode in
326Points to the first byte of an array of Unicode characters
327used to set or append to a string object.
328This byte array may contain embedded null characters
329unless \fInumChars\fR is negative.
330.AP int numChars in
331The number of Unicode characters to copy from \fIunicode\fR when
332initializing, setting, or appending to a string object.
333If negative, all characters up to the first null character are used.
334.AP int index in
335The index of the Unicode character to return.
336.AP int first in
337The index of the first Unicode character in the Unicode range to be
338returned as a new object.
339.AP int last in
340The index of the last Unicode character in the Unicode range to be
341returned as a new object.
342.AP Tcl_Obj *objPtr in/out
343Points to an object to manipulate.
344.AP Tcl_Obj *appendObjPtr in
345The object to append to \fIobjPtr\fR in \fBTcl_AppendObjToObj\fR.
346.AP int *lengthPtr out
347If non-NULL, the location where \fBTcl_GetStringFromObj\fR will store
348the the length of an object's string representation.
349.AP "CONST char" *string in
350Null-terminated string value to append to \fIobjPtr\fR.
351.AP va_list argList in
352An argument list which must have been initialised using
353\fBTCL_VARARGS_START\fR, and cleared using \fBva_end\fR.
354.AP int newLength in
355New length for the string value of \fIobjPtr\fR, not including the
356final null character.
357.AP int objc in
358The number of elements to concatenate.
359.AP Tcl_Obj *objv[] in
360The array of objects to concatenate.
361.BE
362
363.SH DESCRIPTION
364.PP
365The procedures described in this manual entry allow Tcl objects to
366be manipulated as string values. They use the internal representation
367of the object to store additional information to make the string
368manipulations more efficient. In particular, they make a series of
369append operations efficient by allocating extra storage space for the
370string so that it doesn't have to be copied for each append.
371Also, indexing and length computations are optimized because the
372Unicode string representation is calculated and cached as needed.
373When using the \fBTcl_Append*\fR family of functions where the
374interpreter's result is the object being appended to, it is important
375to call Tcl_ResetResult first to ensure you are not unintentionally
376appending to existing data in the result object.
377.PP
378\fBTcl_NewStringObj\fR and \fBTcl_SetStringObj\fR create a new object
379or modify an existing object to hold a copy of the string given by
380\fIbytes\fR and \fIlength\fR. \fBTcl_NewUnicodeObj\fR and
381\fBTcl_SetUnicodeObj\fR create a new object or modify an existing
382object to hold a copy of the Unicode string given by \fIunicode\fR and
383\fInumChars\fR. \fBTcl_NewStringObj\fR and \fBTcl_NewUnicodeObj\fR
384return a pointer to a newly created object with reference count zero.
385All four procedures set the object to hold a copy of the specified
386string. \fBTcl_SetStringObj\fR and \fBTcl_SetUnicodeObj\fR free any
387old string representation as well as any old internal representation
388of the object.
389.PP
390\fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR return an object's
391string representation. This is given by the returned byte pointer and
392(for \fBTcl_GetStringFromObj\fR) length, which is stored in
393\fIlengthPtr\fR if it is non-NULL. If the object's UTF string
394representation is invalid (its byte pointer is NULL), the string
395representation is regenerated from the object's internal
396representation. The storage referenced by the returned byte pointer
397is owned by the object manager. It is passed back as a writable
398pointer so that extension author creating their own \fBTcl_ObjType\fR
399will be able to modify the string representation within the
400\fBTcl_UpdateStringProc\fR of their \fBTcl_ObjType\fR. Except for that
401limited purpose, the pointer returned by \fBTcl_GetStringFromObj\fR
402or \fBTcl_GetString\fR should be treated as read-only. It is
403recommended that this pointer be assigned to a (CONST char *) variable.
404Even in the limited situations where writing to this pointer is
405acceptable, one should take care to respect the copy-on-write
406semantics required by \fBTcl_Obj\fR's, with appropriate calls
407to \fBTcl_IsShared\fR and \fBTcl_DuplicateObj\fR prior to any
408in-place modification of the string representation.
409The procedure \fBTcl_GetString\fR is used in the common case
410where the caller does not need the length of the string
411representation.
412.PP
413\fBTcl_GetUnicodeFromObj\fR and \fBTcl_GetUnicode\fR return an object's
414value as a Unicode string. This is given by the returned pointer and
415(for \fBTcl_GetUnicodeFromObj\fR) length, which is stored in
416\fIlengthPtr\fR if it is non-NULL. The storage referenced by the returned
417byte pointer is owned by the object manager and should not be modified by
418the caller. The procedure \fBTcl_GetUnicode\fR is used in the common case
419where the caller does not need the length of the unicode string
420representation.
421.PP
422\fBTcl_GetUniChar\fR returns the \fIindex\fR'th character in the
423object's Unicode representation.
424.PP
425\fBTcl_GetRange\fR returns a newly created object comprised of the
426characters between \fIfirst\fR and \fIlast\fR (inclusive) in the
427object's Unicode representation. If the object's Unicode
428representation is invalid, the Unicode representation is regenerated
429from the object's string representation.
430.PP
431\fBTcl_GetCharLength\fR returns the number of characters (as opposed
432to bytes) in the string object.
433.PP
434\fBTcl_AppendToObj\fR appends the data given by \fIbytes\fR and
435\fIlength\fR to the string representation of the object specified by
436\fIobjPtr\fR. If the object has an invalid string representation,
437then an attempt is made to convert \fIbytes\fR is to the Unicode
438format. If the conversion is successful, then the converted form of
439\fIbytes\fR is appended to the object's Unicode representation.
440Otherwise, the object's Unicode representation is invalidated and
441converted to the UTF format, and \fIbytes\fR is appended to the
442object's new string representation.
443.PP
444\fBTcl_AppendUnicodeToObj\fR appends the Unicode string given by
445\fIunicode\fR and \fInumChars\fR to the object specified by
446\fIobjPtr\fR. If the object has an invalid Unicode representation,
447then \fIunicode\fR is converted to the UTF format and appended to the
448object's string representation. Appends are optimized to handle
449repeated appends relatively efficiently (it overallocates the string
450or Unicode space to avoid repeated reallocations and copies of
451object's string value).
452.PP
453\fBTcl_AppendObjToObj\fR is similar to \fBTcl_AppendToObj\fR, but it
454appends the string or Unicode value (whichever exists and is best
455suited to be appended to \fIobjPtr\fR) of \fIappendObjPtr\fR to
456\fIobjPtr\fR.
457.PP
458\fBTcl_AppendStringsToObj\fR is similar to \fBTcl_AppendToObj\fR
459except that it can be passed more than one value to append and
460each value must be a null-terminated string (i.e. none of the
461values may contain internal null characters). Any number of
462\fIstring\fR arguments may be provided, but the last argument
463must be a NULL pointer to indicate the end of the list.
464.PP
465\fBTcl_AppendStringsToObjVA\fR is the same as \fBTcl_AppendStringsToObj\fR
466except that instead of taking a variable number of arguments it takes an
467argument list.
468.PP
469The \fBTcl_SetObjLength\fR procedure changes the length of the
470string value of its \fIobjPtr\fR argument. If the \fInewLength\fR
471argument is greater than the space allocated for the object's
472string, then the string space is reallocated and the old value
473is copied to the new space; the bytes between the old length of
474the string and the new length may have arbitrary values.
475If the \fInewLength\fR argument is less than the current length
476of the object's string, with \fIobjPtr->length\fR is reduced without
477reallocating the string space; the original allocated size for the
478string is recorded in the object, so that the string length can be
479enlarged in a subsequent call to \fBTcl_SetObjLength\fR without
480reallocating storage. In all cases \fBTcl_SetObjLength\fR leaves
481a null character at \fIobjPtr->bytes[newLength]\fR.
482.PP
483\fBTcl_AttemptSetObjLength\fR is identical in function to
484\fBTcl_SetObjLength\fR except that if sufficient memory to satisfy the
485request cannot be allocated, it does not cause the Tcl interpreter to
486\fBpanic\fR. Thus, if \fInewLength\fR is greater than the space
487allocated for the object's string, and there is not enough memory
488available to satisfy the request, \fBTcl_AttemptSetObjLength\fR will take
489no action and return 0 to indicate failure. If there is enough memory
490to satisfy the request, \fBTcl_AttemptSetObjLength\fR behaves just like
491\fBTcl_SetObjLength\fR and returns 1 to indicate success.
492.PP
493The \fBTcl_ConcatObj\fR function returns a new string object whose
494value is the space-separated concatenation of the string
495representations of all of the objects in the \fIobjv\fR
496array. \fBTcl_ConcatObj\fR eliminates leading and trailing white space
497as it copies the string representations of the \fIobjv\fR array to the
498result. If an element of the \fIobjv\fR array consists of nothing but
499white space, then that object is ignored entirely. This white-space
500removal was added to make the output of the \fBconcat\fR command
501cleaner-looking. \fBTcl_ConcatObj\fR returns a pointer to a
502newly-created object whose ref count is zero.
503
504.SH "SEE ALSO"
505Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount
506
507.SH KEYWORDS
508append, internal representation, object, object type, string object,
509string type, string representation, concat, concatenate, unicode