⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringobj.3

📁 tcl是工具命令语言
💻 3
字号:
'\"'\" 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 2002/10/22 12:16:53 dkf Exp $'\" .so man.macros.TH Tcl_StringObj 3 8.1 Tcl "Tcl Library Procedures".BS.SH NAMETcl_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.spTcl_Obj *\fBTcl_NewStringObj\fR(\fIbytes, length\fR).spTcl_Obj *\fBTcl_NewUnicodeObj\fR(\fIunicode, numChars\fR).spvoid\fBTcl_SetStringObj\fR(\fIobjPtr, bytes, length\fR).spvoid\fBTcl_SetUnicodeObj\fR(\fIobjPtr, unicode, numChars\fR).spchar *\fBTcl_GetStringFromObj\fR(\fIobjPtr, lengthPtr\fR).spchar *\fBTcl_GetString\fR(\fIobjPtr\fR).spTcl_UniChar *\fBTcl_GetUnicodeFromObj\fR(\fIobjPtr, lengthPtr\fR).spTcl_UniChar *\fBTcl_GetUnicode\fR(\fIobjPtr\fR).spTcl_UniChar\fBTcl_GetUniChar\fR(\fIobjPtr, index\fR).spint\fBTcl_GetCharLength\fR(\fIobjPtr\fR).spTcl_Obj *\fBTcl_GetRange\fR(\fIobjPtr, first, last\fR).spvoid\fBTcl_AppendToObj\fR(\fIobjPtr, bytes, length\fR).spvoid\fBTcl_AppendUnicodeToObj\fR(\fIobjPtr, unicode, numChars\fR).spvoid\fBTcl_AppendObjToObj\fR(\fIobjPtr, appendObjPtr\fR).spvoid\fBTcl_AppendStringsToObj\fR(\fIobjPtr, string, string, ... \fB(char *) NULL\fR).spvoid\fBTcl_AppendStringsToObjVA\fR(\fIobjPtr, argList\fR).spvoid\fBTcl_SetObjLength\fR(\fIobjPtr, newLength\fR).spint\fBTcl_AttemptSetObjLength\fR(\fIobjPtr, newLength\fR).spTcl_Obj *\fBTcl_ConcatObj\fR(\fIobjc, objv\fR).SH ARGUMENTS.AS "CONST Tcl_UniChar" *appendObjPtr in/out.AP "CONST char" *bytes in.VS 8.1Points to the first byte of an array of UTF-8-encoded bytesused to set or append to a string object.This byte array should not contain embedded null bytesunless \fIlength\fR is negative.  (Applications needing null bytesshould represent them as the two-byte sequence \fI\\700\\600\fR, use\fBTcl_ExternalToUtf\fR to convert, or \fBTcl_NewByteArrayObj\fR ifthe string is a collection of uninterpreted bytes.).VE 8.1.AP int length inThe number of bytes to copy from \fIbytes\fR wheninitializing, setting, or appending to a string object.If negative, all bytes up to the first null are used..AP "CONST Tcl_UniChar" *unicode inPoints to the first byte of an array of Unicode charactersused to set or append to a string object.This byte array may contain embedded null charactersunless \fInumChars\fR is negative..AP int numChars inThe number of Unicode characters to copy from \fIunicode\fR wheninitializing, setting, or appending to a string object.If negative, all characters up to the first null character are used..AP int index inThe index of the Unicode character to return..AP int first inThe index of the first Unicode character in the Unicode range to bereturned as a new object..AP int last inThe index of the last Unicode character in the Unicode range to bereturned as a new object..AP Tcl_Obj *objPtr in/outPoints to an object to manipulate..AP Tcl_Obj *appendObjPtr inThe object to append to \fIobjPtr\fR in \fBTcl_AppendObjToObj\fR..AP int *lengthPtr outIf non-NULL, the location where \fBTcl_GetStringFromObj\fR will storethe the length of an object's string representation..AP "CONST char" *string inNull-terminated string value to append to \fIobjPtr\fR..AP va_list argList inAn argument list which must have been initialised using\fBTCL_VARARGS_START\fR, and cleared using \fBva_end\fR..AP int newLength inNew length for the string value of \fIobjPtr\fR, not including thefinal NULL character..AP int objc inThe number of elements to concatenate..AP Tcl_Obj *objv[] inThe array of objects to concatenate..BE.SH DESCRIPTION.PPThe procedures described in this manual entry allow Tcl objects tobe manipulated as string values.  They use the internal representationof the object to store additional information to make the stringmanipulations more efficient.  In particular, they make a series ofappend operations efficient by allocating extra storage space for thestring so that it doesn't have to be copied for each append.Also, indexing and length computations are optimized because theUnicode string representation is calculated and cached as needed.When using the \fBTcl_Append*\fR family of functions where theinterpreter's result is the object being appended to, it is importantto call Tcl_ResetResult first to ensure you are not unintentionallyappending to existing data in the result object..PP\fBTcl_NewStringObj\fR and \fBTcl_SetStringObj\fR create a new objector modify an existing object to hold a copy of the string given by\fIbytes\fR and \fIlength\fR.  \fBTcl_NewUnicodeObj\fR and\fBTcl_SetUnicodeObj\fR create a new object or modify an existingobject to hold a copy of the Unicode string given by \fIunicode\fR and\fInumChars\fR.  \fBTcl_NewStringObj\fR and \fBTcl_NewUnicodeObj\fRreturn a pointer to a newly created object with reference count zero.All four procedures set the object to hold a copy of the specifiedstring.  \fBTcl_SetStringObj\fR and \fBTcl_SetUnicodeObj\fR free anyold string representation as well as any old internal representationof the object..PP\fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR return an object'sstring representation.  This is given by the returned byte pointer and(for \fBTcl_GetStringFromObj\fR) length, which is stored in\fIlengthPtr\fR if it is non-NULL.  If the object's UTF stringrepresentation is invalid (its byte pointer is NULL), the stringrepresentation is regenerated from the object's internalrepresentation.  The storage referenced by the returned byte pointeris owned by the object manager.  It is passed back as a writablepointer so that extension author creating their own \fBTcl_ObjType\fRwill be able to modify the string representation within the\fBTcl_UpdateStringProc\fR of their \fBTcl_ObjType\fR.  Except for thatlimited purpose, the pointer returned by \fBTcl_GetStringFromObj\fRor \fBTcl_GetString\fR should be treated as read-only.  It isrecommended that this pointer be assigned to a (CONST char *) variable.Even in the limited situations where writing to this pointer isacceptable, one should take care to respect the copy-on-writesemantics required by \fBTcl_Obj\fR's, with appropriate callsto \fBTcl_IsShared\fR and \fBTcl_DuplicateObj\fR prior to anyin-place modification of the string representation.The procedure \fBTcl_GetString\fR is used in the common casewhere the caller does not need the length of the stringrepresentation..PP\fBTcl_GetUnicodeFromObj\fR and \fBTcl_GetUnicode\fR return an object'svalue as a Unicode string.  This is given by the returned pointer and(for \fBTcl_GetUnicodeFromObj\fR) length, which is stored in\fIlengthPtr\fR if it is non-NULL.  The storage referenced by the returnedbyte pointer is owned by the object manager and should not be modified bythe caller.  The procedure \fBTcl_GetUnicode\fR is used in the common casewhere the caller does not need the length of the unicode stringrepresentation..PP\fBTcl_GetUniChar\fR returns the \fIindex\fR'th character in theobject's Unicode representation..PP\fBTcl_GetRange\fR returns a newly created object comprised of thecharacters between \fIfirst\fR and \fIlast\fR (inclusive) in theobject's Unicode representation.  If the object's Unicoderepresentation is invalid, the Unicode representation is regeneratedfrom the object's string representation..PP\fBTcl_GetCharLength\fR returns the number of characters (as opposedto bytes) in the string object..PP\fBTcl_AppendToObj\fR appends the data given by \fIbytes\fR and\fIlength\fR to the string representation of the object specified by\fIobjPtr\fR.  If the object has an invalid string representation,then an attempt is made to convert \fIbytes\fR is to the Unicodeformat.  If the conversion is successful, then the converted form of\fIbytes\fR is appended to the object's Unicode representation.Otherwise, the object's Unicode representation is invalidated andconverted to the UTF format, and \fIbytes\fR is appended to theobject's new string representation..PP\fBTcl_AppendUnicodeToObj\fR appends the Unicode string given by\fIunicode\fR and \fInumChars\fR to the object specified by\fIobjPtr\fR.  If the object has an invalid Unicode representation,then \fIunicode\fR is converted to the UTF format and appended to theobject's string representation.  Appends are optimized to handlerepeated appends relatively efficiently (it overallocates the stringor Unicode space to avoid repeated reallocations and copies ofobject's string value)..PP\fBTcl_AppendObjToObj\fR is similar to \fBTcl_AppendToObj\fR, but itappends the string or Unicode value (whichever exists and is bestsuited to be appended to \fIobjPtr\fR) of \fIappendObjPtr\fR to\fIobjPtr\fR..PP\fBTcl_AppendStringsToObj\fR is similar to \fBTcl_AppendToObj\fRexcept that it can be passed more than one value to append andeach value must be a null-terminated string (i.e. none of thevalues may contain internal null characters).  Any number of\fIstring\fR arguments may be provided, but the last argumentmust be a NULL pointer to indicate the end of the list..PP\fBTcl_AppendStringsToObjVA\fR is the same as \fBTcl_AppendStringsToObj\fRexcept that instead of taking a variable number of arguments it takes anargument list..PPThe \fBTcl_SetObjLength\fR procedure changes the length of thestring value of its \fIobjPtr\fR argument.  If the \fInewLength\fRargument is greater than the space allocated for the object'sstring, then the string space is reallocated and the old valueis copied to the new space; the bytes between the old length ofthe string and the new length may have arbitrary values.If the \fInewLength\fR argument is less than the current lengthof the object's string, with \fIobjPtr->length\fR is reduced withoutreallocating the string space; the original allocated size for thestring is recorded in the object, so that the string length can beenlarged in a subsequent call to \fBTcl_SetObjLength\fR withoutreallocating storage.  In all cases \fBTcl_SetObjLength\fR leavesa null character at \fIobjPtr->bytes[newLength]\fR..PP\fBTcl_AttemptSetObjLength\fR is identical in function to\fBTcl_SetObjLength\fR except that if sufficient memory to satisfy therequest cannot be allocated, it does not cause the Tcl interpreter to\fBpanic\fR.  Thus, if \fInewLength\fR is greater than the spaceallocated for the object's string, and there is not enough memoryavailable to satisfy the request, \fBTcl_AttemptSetObjLength\fR will takeno action and return 0 to indicate failure.  If there is enough memoryto satisfy the request, \fBTcl_AttemptSetObjLength\fR behaves just like\fBTcl_SetObjLength\fR and returns 1 to indicate success..PPThe \fBTcl_ConcatObj\fR function returns a new string object whosevalue is the space-separated concatenation of the stringrepresentations of all of the objects in the \fIobjv\fRarray. \fBTcl_ConcatObj\fR eliminates leading and trailing white spaceas it copies the string representations of the \fIobjv\fR array to theresult. If an element of the \fIobjv\fR array consists of nothing butwhite space, then that object is ignored entirely. This white-spaceremoval was added to make the output of the \fBconcat\fR commandcleaner-looking. \fBTcl_ConcatObj\fR returns a pointer to anewly-created object whose ref count is zero..SH "SEE ALSO"Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount.SH KEYWORDSappend, internal representation, object, object type, string object,string type, string representation, concat, concatenate, unicode

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -