StringObj.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:12k
- '"
- '" Copyright (c) 1994-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: StringObj.3,v 1.13.2.1 2003/07/18 16:56:24 dgp Exp $
- '"
- .so man.macros
- .TH Tcl_StringObj 3 8.1 Tcl "Tcl Library Procedures"
- .BS
- .SH NAME
- Tcl_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
- .SH SYNOPSIS
- .nf
- fB#include <tcl.h>fR
- .sp
- Tcl_Obj *
- fBTcl_NewStringObjfR(fIbytes, lengthfR)
- .sp
- Tcl_Obj *
- fBTcl_NewUnicodeObjfR(fIunicode, numCharsfR)
- .sp
- void
- fBTcl_SetStringObjfR(fIobjPtr, bytes, lengthfR)
- .sp
- void
- fBTcl_SetUnicodeObjfR(fIobjPtr, unicode, numCharsfR)
- .sp
- char *
- fBTcl_GetStringFromObjfR(fIobjPtr, lengthPtrfR)
- .sp
- char *
- fBTcl_GetStringfR(fIobjPtrfR)
- .sp
- Tcl_UniChar *
- fBTcl_GetUnicodeFromObjfR(fIobjPtr, lengthPtrfR)
- .sp
- Tcl_UniChar *
- fBTcl_GetUnicodefR(fIobjPtrfR)
- .sp
- Tcl_UniChar
- fBTcl_GetUniCharfR(fIobjPtr, indexfR)
- .sp
- int
- fBTcl_GetCharLengthfR(fIobjPtrfR)
- .sp
- Tcl_Obj *
- fBTcl_GetRangefR(fIobjPtr, first, lastfR)
- .sp
- void
- fBTcl_AppendToObjfR(fIobjPtr, bytes, lengthfR)
- .sp
- void
- fBTcl_AppendUnicodeToObjfR(fIobjPtr, unicode, numCharsfR)
- .sp
- void
- fBTcl_AppendObjToObjfR(fIobjPtr, appendObjPtrfR)
- .sp
- void
- fBTcl_AppendStringsToObjfR(fIobjPtr, string, string, ... fB(char *) NULLfR)
- .sp
- void
- fBTcl_AppendStringsToObjVAfR(fIobjPtr, argListfR)
- .sp
- void
- fBTcl_SetObjLengthfR(fIobjPtr, newLengthfR)
- .sp
- int
- fBTcl_AttemptSetObjLengthfR(fIobjPtr, newLengthfR)
- .sp
- Tcl_Obj *
- fBTcl_ConcatObjfR(fIobjc, objvfR)
- .SH ARGUMENTS
- .AS "CONST Tcl_UniChar" *appendObjPtr in/out
- .AP "CONST char" *bytes in
- .VS 8.1
- Points to the first byte of an array of UTF-8-encoded bytes
- used to set or append to a string object.
- This byte array should not contain embedded null bytes
- unless fIlengthfR is negative. (Applications needing null bytes
- should represent them as the two-byte sequence fI\700\600fR, use
- fBTcl_ExternalToUtffR to convert, or fBTcl_NewByteArrayObjfR if
- the string is a collection of uninterpreted bytes.)
- .VE 8.1
- .AP int length in
- The number of bytes to copy from fIbytesfR when
- initializing, setting, or appending to a string object.
- If negative, all bytes up to the first null are used.
- .AP "CONST Tcl_UniChar" *unicode in
- Points to the first byte of an array of Unicode characters
- used to set or append to a string object.
- This byte array may contain embedded null characters
- unless fInumCharsfR is negative.
- .AP int numChars in
- The number of Unicode characters to copy from fIunicodefR when
- initializing, setting, or appending to a string object.
- If negative, all characters up to the first null character are used.
- .AP int index in
- The index of the Unicode character to return.
- .AP int first in
- The index of the first Unicode character in the Unicode range to be
- returned as a new object.
- .AP int last in
- The index of the last Unicode character in the Unicode range to be
- returned as a new object.
- .AP Tcl_Obj *objPtr in/out
- Points to an object to manipulate.
- .AP Tcl_Obj *appendObjPtr in
- The object to append to fIobjPtrfR in fBTcl_AppendObjToObjfR.
- .AP int *lengthPtr out
- If non-NULL, the location where fBTcl_GetStringFromObjfR will store
- the the length of an object's string representation.
- .AP "CONST char" *string in
- Null-terminated string value to append to fIobjPtrfR.
- .AP va_list argList in
- An argument list which must have been initialised using
- fBTCL_VARARGS_STARTfR, and cleared using fBva_endfR.
- .AP int newLength in
- New length for the string value of fIobjPtrfR, not including the
- final null character.
- .AP int objc in
- The number of elements to concatenate.
- .AP Tcl_Obj *objv[] in
- The array of objects to concatenate.
- .BE
- .SH DESCRIPTION
- .PP
- 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.
- Also, indexing and length computations are optimized because the
- Unicode string representation is calculated and cached as needed.
- When using the fBTcl_Append*fR family of functions where the
- interpreter's result is the object being appended to, it is important
- to call Tcl_ResetResult first to ensure you are not unintentionally
- appending to existing data in the result object.
- .PP
- fBTcl_NewStringObjfR and fBTcl_SetStringObjfR create a new object
- or modify an existing object to hold a copy of the string given by
- fIbytesfR and fIlengthfR. fBTcl_NewUnicodeObjfR and
- fBTcl_SetUnicodeObjfR create a new object or modify an existing
- object to hold a copy of the Unicode string given by fIunicodefR and
- fInumCharsfR. fBTcl_NewStringObjfR and fBTcl_NewUnicodeObjfR
- return a pointer to a newly created object with reference count zero.
- All four procedures set the object to hold a copy of the specified
- string. fBTcl_SetStringObjfR and fBTcl_SetUnicodeObjfR free any
- old string representation as well as any old internal representation
- of the object.
- .PP
- fBTcl_GetStringFromObjfR and fBTcl_GetStringfR return an object's
- string representation. This is given by the returned byte pointer and
- (for fBTcl_GetStringFromObjfR) length, which is stored in
- fIlengthPtrfR if it is non-NULL. If the object's UTF 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. It is passed back as a writable
- pointer so that extension author creating their own fBTcl_ObjTypefR
- will be able to modify the string representation within the
- fBTcl_UpdateStringProcfR of their fBTcl_ObjTypefR. Except for that
- limited purpose, the pointer returned by fBTcl_GetStringFromObjfR
- or fBTcl_GetStringfR should be treated as read-only. It is
- recommended that this pointer be assigned to a (CONST char *) variable.
- Even in the limited situations where writing to this pointer is
- acceptable, one should take care to respect the copy-on-write
- semantics required by fBTcl_ObjfR's, with appropriate calls
- to fBTcl_IsSharedfR and fBTcl_DuplicateObjfR prior to any
- in-place modification of the string representation.
- The procedure fBTcl_GetStringfR is used in the common case
- where the caller does not need the length of the string
- representation.
- .PP
- fBTcl_GetUnicodeFromObjfR and fBTcl_GetUnicodefR return an object's
- value as a Unicode string. This is given by the returned pointer and
- (for fBTcl_GetUnicodeFromObjfR) length, which is stored in
- fIlengthPtrfR if it is non-NULL. The storage referenced by the returned
- byte pointer is owned by the object manager and should not be modified by
- the caller. The procedure fBTcl_GetUnicodefR is used in the common case
- where the caller does not need the length of the unicode string
- representation.
- .PP
- fBTcl_GetUniCharfR returns the fIindexfR'th character in the
- object's Unicode representation.
- .PP
- fBTcl_GetRangefR returns a newly created object comprised of the
- characters between fIfirstfR and fIlastfR (inclusive) in the
- object's Unicode representation. If the object's Unicode
- representation is invalid, the Unicode representation is regenerated
- from the object's string representation.
- .PP
- fBTcl_GetCharLengthfR returns the number of characters (as opposed
- to bytes) in the string object.
- .PP
- fBTcl_AppendToObjfR appends the data given by fIbytesfR and
- fIlengthfR to the string representation of the object specified by
- fIobjPtrfR. If the object has an invalid string representation,
- then an attempt is made to convert fIbytesfR is to the Unicode
- format. If the conversion is successful, then the converted form of
- fIbytesfR is appended to the object's Unicode representation.
- Otherwise, the object's Unicode representation is invalidated and
- converted to the UTF format, and fIbytesfR is appended to the
- object's new string representation.
- .PP
- fBTcl_AppendUnicodeToObjfR appends the Unicode string given by
- fIunicodefR and fInumCharsfR to the object specified by
- fIobjPtrfR. If the object has an invalid Unicode representation,
- then fIunicodefR is converted to the UTF format and appended to the
- object's string representation. Appends are optimized to handle
- repeated appends relatively efficiently (it overallocates the string
- or Unicode space to avoid repeated reallocations and copies of
- object's string value).
- .PP
- fBTcl_AppendObjToObjfR is similar to fBTcl_AppendToObjfR, but it
- appends the string or Unicode value (whichever exists and is best
- suited to be appended to fIobjPtrfR) of fIappendObjPtrfR to
- fIobjPtrfR.
- .PP
- fBTcl_AppendStringsToObjfR is similar to fBTcl_AppendToObjfR
- 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
- fIstringfR arguments may be provided, but the last argument
- must be a NULL pointer to indicate the end of the list.
- .PP
- fBTcl_AppendStringsToObjVAfR is the same as fBTcl_AppendStringsToObjfR
- except that instead of taking a variable number of arguments it takes an
- argument list.
- .PP
- The fBTcl_SetObjLengthfR procedure changes the length of the
- string value of its fIobjPtrfR argument. If the fInewLengthfR
- 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 fInewLengthfR argument is less than the current length
- of the object's string, with fIobjPtr->lengthfR 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 fBTcl_SetObjLengthfR without
- reallocating storage. In all cases fBTcl_SetObjLengthfR leaves
- a null character at fIobjPtr->bytes[newLength]fR.
- .PP
- fBTcl_AttemptSetObjLengthfR is identical in function to
- fBTcl_SetObjLengthfR except that if sufficient memory to satisfy the
- request cannot be allocated, it does not cause the Tcl interpreter to
- fBpanicfR. Thus, if fInewLengthfR is greater than the space
- allocated for the object's string, and there is not enough memory
- available to satisfy the request, fBTcl_AttemptSetObjLengthfR will take
- no action and return 0 to indicate failure. If there is enough memory
- to satisfy the request, fBTcl_AttemptSetObjLengthfR behaves just like
- fBTcl_SetObjLengthfR and returns 1 to indicate success.
- .PP
- The fBTcl_ConcatObjfR function returns a new string object whose
- value is the space-separated concatenation of the string
- representations of all of the objects in the fIobjvfR
- array. fBTcl_ConcatObjfR eliminates leading and trailing white space
- as it copies the string representations of the fIobjvfR array to the
- result. If an element of the fIobjvfR 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 fBconcatfR command
- cleaner-looking. fBTcl_ConcatObjfR returns a pointer to a
- newly-created object whose ref count is zero.
- .SH "SEE ALSO"
- Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount
- .SH KEYWORDS
- append, internal representation, object, object type, string object,
- string type, string representation, concat, concatenate, unicode