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

📄 encoding.3

📁 tcl是工具命令语言
💻 3
📖 第 1 页 / 共 2 页
字号:
'\"'\" Copyright (c) 1997-1998 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: Encoding.3,v 1.11 2002/07/01 18:24:39 jenglish Exp $'\" .so man.macros.TH Tcl_GetEncoding 3 "8.1" Tcl "Tcl Library Procedures".BS.SH NAMETcl_GetEncoding, Tcl_FreeEncoding, Tcl_ExternalToUtfDString, Tcl_ExternalToUtf, Tcl_UtfToExternalDString, Tcl_UtfToExternal, Tcl_WinTCharToUtf, Tcl_WinUtfToTChar, Tcl_GetEncodingName, Tcl_SetSystemEncoding, Tcl_GetEncodingNames, Tcl_CreateEncoding, Tcl_GetDefaultEncodingDir, Tcl_SetDefaultEncodingDir \- procedures for creating and using encodings..SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spTcl_Encoding\fBTcl_GetEncoding\fR(\fIinterp, name\fR).spvoid\fBTcl_FreeEncoding\fR(\fIencoding\fR).spchar *\fBTcl_ExternalToUtfDString\fR(\fIencoding, src, srcLen, dstPtr\fR).spint\fBTcl_ExternalToUtf\fR(\fIinterp, encoding, src, srcLen, flags, statePtr, dst, dstLen, srcReadPtr, dstWrotePtr, 	dstCharsPtr\fR).spchar * \fBTcl_UtfToExternalDString\fR(\fIencoding, src, srcLen, dstPtr\fR).spint\fBTcl_UtfToExternal\fR(\fIinterp, encoding, src, srcLen, flags, statePtr, dst, dstLen, srcReadPtr, dstWrotePtr, 	dstCharsPtr\fR).spchar *\fBTcl_WinTCharToUtf\fR(\fItsrc, srcLen, dstPtr\fR).spTCHAR *\fBTcl_WinUtfToTChar\fR(\fIsrc, srcLen, dstPtr\fR).spCONST char *\fBTcl_GetEncodingName\fR(\fIencoding\fR).spint\fBTcl_SetSystemEncoding\fR(\fIinterp, name\fR).spvoid\fBTcl_GetEncodingNames\fR(\fIinterp\fR).spTcl_Encoding\fBTcl_CreateEncoding\fR(\fItypePtr\fR).spCONST char *\fBTcl_GetDefaultEncodingDir\fR(\fIvoid\fR).spvoid\fBTcl_SetDefaultEncodingDir\fR(\fIpath\fR).SH ARGUMENTS.AS Tcl_EncodingState *dstWrotePtr.AP Tcl_Interp *interp inInterpreter to use for error reporting, or NULL if no error reporting isdesired..AP "CONST char" *name inName of encoding to load..AP Tcl_Encoding encoding inThe encoding to query, free, or use for converting text.  If \fIencoding\fR is NULL, the current system encoding is used..AP "CONST char" *src inFor the \fBTcl_ExternalToUtf\fR functions, an array of bytes in thespecified encoding that are to be converted to UTF-8.  For the\fBTcl_UtfToExternal\fR and \fBTcl_WinUtfToTChar\fR functions, an array ofUTF-8 characters to be converted to the specified encoding.  .AP "CONST TCHAR" *tsrc inAn array of Windows TCHAR characters to convert to UTF-8..AP int srcLen in Length of \fIsrc\fR or \fItsrc\fR in bytes.  If the length is negative, the encoding-specific length of the string is used..AP Tcl_DString *dstPtr outPointer to an uninitialized or free \fBTcl_DString\fR in which the convertedresult will be stored..AP int flags inVarious flag bits OR-ed together.  TCL_ENCODING_START signifies that thesource buffer is the first block in a (potentially multi-block) inputstream, telling the conversion routine to reset to an initial state andperform any initialization that needs to occur before the first byte isconverted.  TCL_ENCODING_END signifies that the source buffer is the lastblock in a (potentially multi-block) input stream, telling the conversionroutine to perform any finalization that needs to occur after the lastbyte is converted and then to reset to an initial state.TCL_ENCODING_STOPONERROR signifies that the conversion routine shouldreturn immediately upon reading a source character that doesn't exist inthe target encoding; otherwise a default fallback character willautomatically be substituted.  .AP Tcl_EncodingState *statePtr in/outUsed when converting a (generally long or indefinite length) byte streamin a piece by piece fashion.  The conversion routine stores its currentstate in \fI*statePtr\fR after \fIsrc\fR (the buffer containing thecurrent piece) has been converted; that state information must be passedback when converting the next piece of the stream so the conversionroutine knows what state it was in when it left off at the end of thelast piece.  May be NULL, in which case the value specified for \fIflags\fR is ignored and the source buffer is assumed to contain the complete string toconvert..AP char *dst outBuffer in which the converted result will be stored.  No more than\fIdstLen\fR bytes will be stored in \fIdst\fR..AP int dstLen inThe maximum length of the output buffer \fIdst\fR in bytes..AP int *srcReadPtr outFilled with the number of bytes from \fIsrc\fR that were actuallyconverted.  This may be less than the original source length if there wasa problem converting some source characters.  May be NULL..AP int *dstWrotePtr outFilled with the number of bytes that were actually stored in the outputbuffer as a result of the conversion.  May be NULL..AP int *dstCharsPtr outFilled with the number of characters that correspond to the number of bytesstored in the output buffer.  May be NULL..AP Tcl_EncodingType *typePtr inStructure that defines a new type of encoding.  .AP "CONST char" *path inA path to the location of the encoding file.  .BE.SH INTRODUCTION.PPThese routines convert between Tcl's internal character representation,UTF-8, and character representations used by various operating systems orfile systems, such as Unicode, ASCII, or Shift-JIS.  When operating onstrings, such as such as obtaining the names of files or displayingcharacters using international fonts, the strings must be translated intoone or possibly multiple formats that the various system calls can use.  Forinstance, on a Japanese Unix workstation, a user might obtain a filenamerepresented in the EUC-JP file encoding and then translate the characters tothe jisx0208 font encoding in order to display the filename in a Tk widget.The purpose of the encoding package is to help bridge the translation gap.UTF-8 provides an intermediate staging ground for all the variousencodings.  In the example above, text would be translated into UTF-8 fromwhatever file encoding the operating system is using.  Then it would betranslated from UTF-8 into whatever font encoding the display routinesrequire..PPSome basic encodings are compiled into Tcl.  Others can be defined by theuser or dynamically loaded from encoding files in aplatform-independent manner..SH DESCRIPTION.PP\fBTcl_GetEncoding\fR finds an encoding given its \fIname\fR.  The name mayrefer to a builtin Tcl encoding, a user-defined encoding registered bycalling \fBTcl_CreateEncoding\fR, or a dynamically-loadable encodingfile.  The return value is a token that represents the encoding and can beused in subsequent calls to procedures such as \fBTcl_GetEncodingName\fR,\fBTcl_FreeEncoding\fR, and \fBTcl_UtfToExternal\fR.  If the name did notrefer to any known or loadable encoding, NULL is returned and an errormessage is returned in \fIinterp\fR..PPThe encoding package maintains a database of all encodings currently in use.The first time \fIname\fR is seen, \fBTcl_GetEncoding\fR returns anencoding with a reference count of 1.  If the same \fIname\fR is requestedfurther times, then the reference count for that encoding is incrementedwithout the overhead of allocating a new encoding and all its associateddata structures.  .PPWhen an \fIencoding\fR is no longer needed, \fBTcl_FreeEncoding\fRshould be called to release it.  When an \fIencoding\fR is no longer in useanywhere (i.e., it has been freed as many times as it has been gotten)\fBTcl_FreeEncoding\fR will release all storage the encoding was usingand delete it from the database. .PP\fBTcl_ExternalToUtfDString\fR converts a source buffer \fIsrc\fR from thespecified \fIencoding\fR into UTF-8.  The converted bytes are stored in \fIdstPtr\fR, which is then NULL terminated.  The caller should eventuallycall \fBTcl_DStringFree\fR to free any information stored in \fIdstPtr\fR.When converting, if any of the characters in the source buffer cannot berepresented in the target encoding, a default fallback character will beused.  The return value is a pointer to the value stored in the DString..PP\fBTcl_ExternalToUtf\fR converts a source buffer \fIsrc\fR from the specified\fIencoding\fR into UTF-8.  Up to \fIsrcLen\fR bytes are converted from thesource buffer and up to \fIdstLen\fR converted bytes are stored in \fIdst\fR.In all cases, \fI*srcReadPtr\fR is filled with the number of bytes that weresuccessfully converted from \fIsrc\fR and \fI*dstWrotePtr\fR is filled withthe corresponding number of bytes that were stored in \fIdst\fR.  The returnvalue is one of the following:.RS.IP \fBTCL_OK\fR 29All bytes of \fIsrc\fR were converted..IP \fBTCL_CONVERT_NOSPACE\fR 29The destination buffer was not large enough for all of the converted data; asmany characters as could fit were converted though..IP \fBTCL_CONVERT_MULTIBYTE\fR 29The last fews bytes in the source buffer were the beginning of a multibytesequence, but more bytes were needed to complete this sequence.  Asubsequent call to the conversion routine should pass a buffer containingthe unconverted bytes that remained in \fIsrc\fR plus some further bytesfrom the source stream to properly convert the formerly split-up multibytesequence.  .IP \fBTCL_CONVERT_SYNTAX\fR 29The source buffer contained an invalid character sequence.  This may occurif the input stream has been damaged or if the input encoding method wasmisidentified..IP \fBTCL_CONVERT_UNKNOWN\fR 29The source buffer contained a character that could not be represented inthe target encoding and TCL_ENCODING_STOPONERROR was specified.  .RE.LP\fBTcl_UtfToExternalDString\fR converts a source buffer \fIsrc\fR from UTF-8 into the specified \fIencoding\fR.  The converted bytes are stored in\fIdstPtr\fR, which is then terminated with the appropriate encoding-specificNULL.  The caller should eventually call \fBTcl_DStringFree\fR to free anyinformation stored in \fIdstPtr\fR.  When converting, if any of thecharacters in the source buffer cannot be represented in the targetencoding, a default fallback character will be used.  The return value isa pointer to the value stored in the DString..PP\fBTcl_UtfToExternal\fR converts a source buffer \fIsrc\fR from UTF-8 intothe specified \fIencoding\fR.  Up to \fIsrcLen\fR bytes are converted fromthe source buffer and up to \fIdstLen\fR converted bytes are stored in\fIdst\fR.  In all cases, \fI*srcReadPtr\fR is filled with the number ofbytes that were successfully converted from \fIsrc\fR and \fI*dstWrotePtr\fRis filled with the corresponding number of bytes that were stored in\fIdst\fR.  The return values are the same as the return values for\fBTcl_ExternalToUtf\fR..PP\fBTcl_WinUtfToTChar\fR and \fBTcl_WinTCharToUtf\fR areWindows-only conveniencefunctions for converting between UTF-8 and Windows strings.  On Windows 95(as with the Macintosh and Unix operating systems),all strings exchanged between Tcl and the operating system are "char"based.  On Windows NT, some strings exchanged between Tcl and theoperating system are "char" oriented while others are in Unicode.  Byconvention, in Windows a TCHAR is a character in the ANSI code pageon Windows 95 and a Unicode character on Windows NT..PPIf you planned to use the same "char" based interfaces on both Windows95 and Windows NT, you could use \fBTcl_UtfToExternal\fR and\fBTcl_ExternalToUtf\fR (or their \fBTcl_DString\fR equivalents) with anencoding of NULL (the current system encoding).  On the other hand,if you planned to use the Unicode interface when running on Windows NTand the "char" interfaces when running on Windows 95, you would haveto perform the following type of test over and over in your program(as represented in pseudo-code):.CSif (running NT) {    encoding <- Tcl_GetEncoding("unicode");    nativeBuffer <- Tcl_UtfToExternal(encoding, utfBuffer);    Tcl_FreeEncoding(encoding);} else {    nativeBuffer <- Tcl_UtfToExternal(NULL, utfBuffer);.CE\fBTcl_WinUtfToTChar\fR and \fBTcl_WinTCharToUtf\fR automaticallyhandle this test and use the proper encoding based on the currentoperating system.  \fBTcl_WinUtfToTChar\fR returns a pointer toa TCHAR string, and \fBTcl_WinTCharToUtf\fR expects a TCHAR stringpointer as the \fIsrc\fR string.  Otherwise, these functionsbehave identically to \fBTcl_UtfToExternalDString\fR and\fBTcl_ExternalToUtfDString\fR.

⌨️ 快捷键说明

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