Seth Woolley's Man Viewer

Tcl_NumUtfChars(3) - Tcl_NumUtfChars, Tcl_UniChar, Tcl_UniCharAtIndex, Tcl_UniCharCaseMatch, Tcl_UniCharLen, Tcl_UniCharNcasecmp, Tcl_UniCharNcmp, Tcl_UniCharToUtf, Tcl_UniCharToUtfDString, Tcl_UtfAtIndex, Tcl_UtfBackslash, Tcl_UtfCharComplete, Tcl_UtfFindFirst, Tcl_UtfFindLast, Tcl_UtfNext, Tcl_UtfPrev, Tcl_UtfToUniChar, Tcl_UtfToUniCharDString - routines for manipulating UTF-8 strings - man 3 Tcl_NumUtfChars

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

Utf(3)                      Tcl Library Procedures                      Utf(3)



______________________________________________________________________________

NAME
       Tcl_UniChar,         Tcl_UniCharCaseMatch,         Tcl_UniCharNcasecmp,
       Tcl_UniCharToUtf,      Tcl_UtfToUniChar,       Tcl_UniCharToUtfDString,
       Tcl_UtfToUniCharDString,  Tcl_UniCharLen, Tcl_UniCharNcmp, Tcl_UtfChar-
       Complete,    Tcl_NumUtfChars,    Tcl_UtfFindFirst,     Tcl_UtfFindLast,
       Tcl_UtfNext,  Tcl_UtfPrev, Tcl_UniCharAtIndex, Tcl_UtfAtIndex, Tcl_Utf-
       Backslash - routines for manipulating UTF-8 strings.

SYNOPSIS
       #include <tcl.h>

       typedef ... Tcl_UniChar;

       int
       Tcl_UniCharToUtf(ch, buf)

       int
       Tcl_UtfToUniChar(src, chPtr)

       char *                                                                  |
       Tcl_UniCharToUtfDString(uniStr, numChars, dstPtr)                       |

       Tcl_UniChar *                                                           |
       Tcl_UtfToUniCharDString(src, len, dstPtr)                               |

       int
       Tcl_UniCharLen(uniStr)

       int
       Tcl_UniCharNcmp(uniStr, uniStr, num)

       int                                                                     |
       Tcl_UniCharNcasecmp(uniStr, uniStr, num)                                |

       int                                                                     |
       Tcl_UniCharCaseMatch(uniStr, uniPattern, nocase)                        |

       int
       Tcl_UtfNcmp(src, src, num)

       int
       Tcl_UtfNcasecmp(src, src, num)

       int
       Tcl_UtfCharComplete(src, len)

       int
       Tcl_NumUtfChars(src, len)

       CONST char *                                                            |
       Tcl_UtfFindFirst(src, ch)                                               |

       CONST char *                                                            |
       Tcl_UtfFindLast(src, ch)                                                |

       CONST char *                                                            |
       Tcl_UtfNext(src)                                                        |

       CONST char *                                                            |
       Tcl_UtfPrev(src, start)                                                 |

       Tcl_UniChar
       Tcl_UniCharAtIndex(src, index)

       CONST char *                                                            |
       Tcl_UtfAtIndex(src, index)                                              |

       int
       Tcl_UtfBackslash(src, readPtr, dst)

ARGUMENTS
       char                *buf       (out)     Buffer in(1,8) which the UTF-8 rep-
                                                resentation of the Tcl_UniChar
                                                is    stored.      At     most
                                                TCL_UTF_MAX  bytes  are stored
                                                in(1,8) the buffer.

       int                 ch         (in(1,8))      The  Tcl_UniChar  to  be  con-
                                                verted or examined.

       Tcl_UniChar         *chPtr     (out)     Filled  with  the  Tcl_UniChar
                                                represented by the head of the
                                                UTF-8 string.

       CONST char          *src       (in(1,8))      Pointer to a UTF-8 string.

       CONST Tcl_UniChar   *uniStr    (in(1,8))      A    null-terminated   Unicode
                                                string.

       CONST Tcl_UniChar   *uniPattern(in(1,8))      A   null-terminated    Unicode
                                                string.

       int                 len        (in(1,8))      The length of the UTF-8 string(3,n)
                                                in(1,8) bytes  (not  UTF-8  charac-
                                                ters).  If negative, all bytes
                                                up to the first null byte  are
                                                used.

       int                 numChars   (in(1,8))      The   length  of  the  Unicode
                                                string(3,n) in(1,8) characters.  Must be
                                                greater than or equal to 0.

       Tcl_DString         *dstPtr    (in(1,8)/out)  A pointer to a previously-ini-
                                                tialized Tcl_DString.

       unsigned long       num        (in(1,8))      The number  of  characters  to
                                                compare.

       CONST char          *start     (in(1,8))      Pointer  to the beginning of a
                                                UTF-8 string.

       int                 index      (in(1,8))      The index of a character  (not
                                                byte) in(1,8) the UTF-8 string.

       int                 *readPtr   (out)     If  non-NULL,  filled with the
                                                number of bytes in(1,8)  the  back-
                                                slash  sequence, including the
                                                backslash character.

       char                *dst       (out)     Buffer in(1,8) which the bytes rep-
                                                resented   by   the  backslash
                                                sequence are stored.  At  most
                                                TCL_UTF_MAX  bytes  are stored
                                                in(1,8) the buffer.                 |

       int                 nocase     (in(1,8))                                     ||
                                                Specifies  whether  the  match |
                                                should be done  case-sensitive |
                                                (0) or case-insensitive (1).
_________________________________________________________________


DESCRIPTION
       These  routines  convert  between  UTF-8  strings  and Tcl_UniChars.  A
       Tcl_UniChar is a Unicode character represented as an  unsigned,  fixed-
       size quantity.  A UTF-8 character is a Unicode character represented as
       a varying-length sequence of up  to  TCL_UTF_MAX  bytes.   A  multibyte
       UTF-8 sequence consists of a lead byte followed by some number of trail
       bytes.

       TCL_UTF_MAX is the maximum number of bytes that it takes  to  represent
       one Unicode character in(1,8) the UTF-8 representation.

       Tcl_UniCharToUtf  stores the Tcl_UniChar ch as a UTF-8 string(3,n) in(1,8) start-
       ing at buf.  The return value is the number of bytes stored in(1,8) buf.

       Tcl_UtfToUniChar reads one UTF-8 character starting at src  and  stores
       it as a Tcl_UniChar in(1,8) *chPtr.  The return value is the number of bytes
       read(2,n,1 builtins) from src..  The caller must ensure that the source buffer is  long
       enough  such that this routine does not run off the end and dereference
       non-existent or random(3,4,6) memory; if(3,n) the source  buffer  is  known  to  be
       null-terminated,  this  will not happen.  If the input is not in(1,8) proper
       UTF-8 format, Tcl_UtfToUniChar will store the  first  byte  of  src  in(1,8)
       *chPtr as a Tcl_UniChar between 0x0000 and 0x00ff and return 1.

       Tcl_UniCharToUtfDString  converts  the  given  Unicode string(3,n) to UTF-8,
       storing the result in(1,8) a previously-initialized Tcl_DString.   You  must
       specify  the length of the given Unicode string.  The return value is a
       pointer to the UTF-8 representation of the Unicode string.  Storage for
       the return value is appended to the end of the Tcl_DString.

       Tcl_UtfToUniCharDString  converts  the  given  UTF-8 string(3,n) to Unicode,
       storing the result in(1,8) the previously-initialized Tcl_DString.  you  may
       either  specify  the length of the given UTF-8 string(3,n) or "-1", in(1,8) which
       case Tcl_UtfToUniCharDString uses strlen to calculate the length.   The
       return  value  is  a pointer to the Unicode representation of the UTF-8
       string.  Storage for the return value is appended to  the  end  of  the
       Tcl_DString.   The  Unicode  string(3,n)  is  terminated with a Unicode null
       character.

       Tcl_UniCharLen  corresponds  to  strlen  for  Unicode  characters.   It
       accepts a null-terminated Unicode string(3,n) and returns the number of Uni-
       code characters (not bytes) in(1,8) that string.

       Tcl_UniCharNcmp and Tcl_UniCharNcasecmp correspond to strncmp and strn-
       casecmp,  respectively, for Unicode characters.  They accepts two null-
       terminated Unicode strings and the number  of  characters  to  compare.
       Both   strings  are  assumed  to  be  at  least  len  characters  long.
       Tcl_UniCharNcmp   compares  the  two   strings   character-by-character
       according  to  the  Unicode  character ordering.  It returns an integer
       greater than, equal to, or less(1,3) than 0 if(3,n) the first string(3,n)  is  greater
       than,   equal   to,  or  less(1,3)  than  the  second  string(3,n)  respectively.
       Tcl_UniCharNcasecmp is the Unicode case insensitive version.

       Tcl_UniCharCaseMatch is the Unicode equivalent to  Tcl_StringCaseMatch. |
       It  accepts  a null-terminated Unicode string(3,n), a Unicode pattern, and a |
       boolean value specifying whether the match should be case sensitive and |
       returns whether the string(3,n) matches the pattern.

       Tcl_UtfNcmp  corresponds  to  strncmp for UTF-8 strings. It accepts two
       null-terminated UTF-8 strings and the number of characters to  compare.
       (Both  strings  are  assumed  to  be  at  least  len  characters long.)
       Tcl_UtfNcmp compares the two strings  character-by-character  according
       to the Unicode character ordering.  It returns an integer greater than,
       equal to, or less(1,3) than 0 if(3,n) the first string(3,n) is greater than, equal to,
       or less(1,3) than the second string(3,n) respectively.

       Tcl_UtfNcasecmp  corresponds  to  strncasecmp for UTF-8 strings.  It is
       similar to Tcl_UtfNcmp except comparisons ignore  differences  in(1,8)  case
       when comparing upper, lower or title case characters.

       Tcl_UtfCharComplete  returns 1 if(3,n) the source UTF-8 string(3,n) src of length
       len bytes is long enough to be decoded by Tcl_UtfToUniChar, or 0 other-
       wise.   This function does not guarantee that the UTF-8 string(3,n) is prop-
       erly formed.  This routine is used by procedures that are operating  on
       a  byte at a time(1,2,n) and need to know if(3,n) a full Tcl_UniChar has been seen.

       Tcl_NumUtfChars corresponds to strlen for UTF-8  strings.   It  returns
       the  number  of  Tcl_UniChars  that are represented by the UTF-8 string(3,n)
       src.  The length of the source string(3,n) is len bytes.  If the  length  is
       negative, all bytes up to the first null byte are used.

       Tcl_UtfFindFirst corresponds to strchr for UTF-8 strings.  It returns a
       pointer to the first occurrence of the Tcl_UniChar ch in(1,8) the  null-ter-
       minated  UTF-8  string(3,n)  src.  The null terminator is considered part of
       the UTF-8 string.

       Tcl_UtfFindLast corresponds to strrchr for UTF-8 strings.  It returns a
       pointer to the last occurrence of the Tcl_UniChar ch in(1,8) the null-termi-
       nated UTF-8 string(3,n) src.  The null terminator is considered part of  the
       UTF-8 string.

       Given  src,  a  pointer to some location in(1,8) a UTF-8 string(3,n), Tcl_UtfNext
       returns a pointer to the next  UTF-8  character  in(1,8)  the  string.   The
       caller  must not ask for the next character after the last character in(1,8)
       the string(3,n) if(3,n) the string(3,n) is not terminated by a null character.

       Given src, a pointer to some location in(1,8) a UTF-8 string(3,n) (or to  a  null
       byte  immediately  following  such  a  string(3,n)),  Tcl_UtfPrev  returns a
       pointer to the closest preceding byte that starts  a  UTF-8  character.
       This function will not back up to a position before start, the start of
       the UTF-8 string.  If src was already at start, the return  value  will
       be start.

       Tcl_UniCharAtIndex  corresponds  to a C string(3,n) array dereference or the
       Pascal Ord() function.  It returns the Tcl_UniChar represented  at  the
       specified  character  (not  byte)  index  in(1,8) the UTF-8 string(3,n) src.  The
       source string(3,n) must contain at  least  index  characters.   Behavior  is
       undefined if(3,n) a negative index is given.

       Tcl_UtfAtIndex  returns a pointer to the specified character (not byte)
       index in(1,8) the UTF-8 string(3,n) src.  The source string(3,n) must contain at least
       index  characters.   This  is  equivalent  to calling Tcl_UtfNext index
       times.  If a negative index is given, the return pointer points to  the
       first character in(1,8) the source string.

       Tcl_UtfBackslash is a utility procedure used by several of the Tcl com-
       mands.  It parses a backslash sequence and stores the  properly  formed
       UTF-8  character  represented  by  the backslash sequence in(1,8) the output
       buffer dst.  At most  TCL_UTF_MAX  bytes  are  stored  in(1,8)  the  buffer.
       Tcl_UtfBackslash  modifies  *readPtr  to contain the number of bytes in(1,8)
       the backslash sequence, including the backslash character.  The  return
       value is the number of bytes stored in(1,8) the output buffer.

       See  the  Tcl  manual  entry  for  information  on  the valid backslash
       sequences.  All of the sequences described in(1,8) the Tcl manual entry  are
       supported by Tcl_UtfBackslash.


KEYWORDS
       utf, unicode, backslash



Tcl                                   8.1                               Utf(3)

References for this manual (incoming links)