summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-02-03 13:13:06 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-02-03 13:13:06 (GMT)
commit62f5155cc809b84cc59bc06780d309edaa2b59f0 (patch)
treef698c37ed975da4c6a49976ecc6821ae7ef2883c
parent99678d70f78441ead651c6b62e7af986648deaeb (diff)
downloadtcl-62f5155cc809b84cc59bc06780d309edaa2b59f0.zip
tcl-62f5155cc809b84cc59bc06780d309edaa2b59f0.tar.gz
tcl-62f5155cc809b84cc59bc06780d309edaa2b59f0.tar.bz2
TIP #617: Tcl_WCharLen/Tcl_Char16Len
-rw-r--r--doc/Utf.316
-rw-r--r--generic/tcl.decls10
-rw-r--r--generic/tclDecls.h43
-rw-r--r--generic/tclStubInit.c10
-rw-r--r--generic/tclUtf.c33
5 files changed, 102 insertions, 10 deletions
diff --git a/doc/Utf.3 b/doc/Utf.3
index f1aca4c..b0c7f64 100644
--- a/doc/Utf.3
+++ b/doc/Utf.3
@@ -8,7 +8,7 @@
.so man.macros
.BS
.SH NAME
-Tcl_UniChar, Tcl_UniCharToUtf, Tcl_UtfToUniChar, Tcl_UtfToChar16, Tcl_UtfToWChar, Tcl_UniCharToUtfDString, Tcl_UtfToUniCharDString, Tcl_Char16ToUtfDString, Tcl_UtfToWCharDString, Tcl_UtfToChar16DString, Tcl_UniCharLen, Tcl_UniCharNcmp, Tcl_UniCharNcasecmp, Tcl_UniCharCaseMatch, Tcl_UtfNcmp, Tcl_UtfNcasecmp, Tcl_UtfCharComplete, Tcl_NumUtfChars, Tcl_UtfFindFirst, Tcl_UtfFindLast, Tcl_UtfNext, Tcl_UtfPrev, Tcl_UniCharAtIndex, Tcl_UtfAtIndex, Tcl_UtfBackslash \- routines for manipulating UTF-8 strings
+Tcl_UniChar, Tcl_UniCharToUtf, Tcl_UtfToUniChar, Tcl_UtfToChar16, Tcl_UtfToWChar, Tcl_UniCharToUtfDString, Tcl_UtfToUniCharDString, Tcl_Char16ToUtfDString, Tcl_UtfToWCharDString, Tcl_UtfToChar16DString, Tcl_WCharLen, Tcl_Char16Len, Tcl_UniCharLen, Tcl_UniCharNcmp, Tcl_UniCharNcasecmp, Tcl_UniCharCaseMatch, Tcl_UtfNcmp, Tcl_UtfNcasecmp, Tcl_UtfCharComplete, Tcl_NumUtfChars, Tcl_UtfFindFirst, Tcl_UtfFindLast, Tcl_UtfNext, Tcl_UtfPrev, Tcl_UniCharAtIndex, Tcl_UtfAtIndex, Tcl_UtfBackslash \- routines for manipulating UTF-8 strings
.SH SYNOPSIS
.nf
\fB#include <tcl.h>\fR
@@ -46,6 +46,12 @@ wchar_t *
\fBTcl_UtfToWCharDString\fR(\fIsrc, length, dsPtr\fR)
.sp
int
+\fBTcl_Char16Len\fR(\fIuniStr\fR)
+.sp
+int
+\fBTcl_WCharLen\fR(\fIuniStr\fR)
+.sp
+int
\fBTcl_UniCharLen\fR(\fIuniStr\fR)
.sp
int
@@ -198,6 +204,14 @@ representation of the UTF-8 string. Storage for the return value
is appended to the end of the \fBTcl_DString\fR. The Unicode string
is terminated with a Unicode null character.
.PP
+\fBTcl_Char16Len\fR corresponds to \fBstrlen\fR for UTF-16
+characters. It accepts a null-terminated Unicode string and returns
+the number of Unicode characters (not bytes) in that string.
+.PP
+\fBTcl_WCharLen\fR corresponds to \fBstrlen\fR for wchar_t
+characters. It accepts a null-terminated Unicode string and returns
+the number of Unicode characters (not bytes) in that string.
+.PP
\fBTcl_UniCharLen\fR corresponds to \fBstrlen\fR for Unicode
characters. It accepts a null-terminated Unicode string and returns
the number of Unicode characters (not bytes) in that string.
diff --git a/generic/tcl.decls b/generic/tcl.decls
index bd9800a..38dbe5a 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -1244,8 +1244,8 @@ declare 350 {
declare 351 {
int Tcl_UniCharIsWordChar(int ch)
}
-declare 352 {deprecated {Use Tcl_GetCharLength}} {
- int Tcl_UniCharLen(const Tcl_UniChar *uniStr)
+declare 352 {
+ int Tcl_Char16Len(const unsigned short *uniStr)
}
declare 353 {deprecated {Use Tcl_UtfNcmp}} {
int Tcl_UniCharNcmp(const Tcl_UniChar *ucs, const Tcl_UniChar *uct,
@@ -2442,6 +2442,12 @@ declare 660 {
int Tcl_AsyncMarkFromSignal(Tcl_AsyncHandler async, int sigNumber)
}
+# TIP #617
+declare 668 {
+ int Tcl_UniCharLen(const int *uniStr)
+}
+
+
# ----- BASELINE -- FOR -- 8.7.0 ----- #
##############################################################################
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index f1962b2..6400029 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1063,8 +1063,7 @@ EXTERN int Tcl_UniCharIsUpper(int ch);
/* 351 */
EXTERN int Tcl_UniCharIsWordChar(int ch);
/* 352 */
-TCL_DEPRECATED("Use Tcl_GetCharLength")
-int Tcl_UniCharLen(const Tcl_UniChar *uniStr);
+EXTERN int Tcl_Char16Len(const unsigned short *uniStr);
/* 353 */
TCL_DEPRECATED("Use Tcl_UtfNcmp")
int Tcl_UniCharNcmp(const Tcl_UniChar *ucs,
@@ -1948,6 +1947,15 @@ EXTERN int Tcl_UniCharIsUnicode(int ch);
/* 660 */
EXTERN int Tcl_AsyncMarkFromSignal(Tcl_AsyncHandler async,
int sigNumber);
+/* Slot 661 is reserved */
+/* Slot 662 is reserved */
+/* Slot 663 is reserved */
+/* Slot 664 is reserved */
+/* Slot 665 is reserved */
+/* Slot 666 is reserved */
+/* Slot 667 is reserved */
+/* 668 */
+EXTERN int Tcl_UniCharLen(const int *uniStr);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
@@ -2335,7 +2343,7 @@ typedef struct TclStubs {
int (*tcl_UniCharIsSpace) (int ch); /* 349 */
int (*tcl_UniCharIsUpper) (int ch); /* 350 */
int (*tcl_UniCharIsWordChar) (int ch); /* 351 */
- TCL_DEPRECATED_API("Use Tcl_GetCharLength") int (*tcl_UniCharLen) (const Tcl_UniChar *uniStr); /* 352 */
+ int (*tcl_Char16Len) (const unsigned short *uniStr); /* 352 */
TCL_DEPRECATED_API("Use Tcl_UtfNcmp") int (*tcl_UniCharNcmp) (const Tcl_UniChar *ucs, const Tcl_UniChar *uct, unsigned long numChars); /* 353 */
char * (*tcl_Char16ToUtfDString) (const unsigned short *uniStr, int uniLength, Tcl_DString *dsPtr); /* 354 */
unsigned short * (*tcl_UtfToChar16DString) (const char *src, int length, Tcl_DString *dsPtr); /* 355 */
@@ -2644,6 +2652,14 @@ typedef struct TclStubs {
void (*reserved658)(void);
void (*reserved659)(void);
int (*tcl_AsyncMarkFromSignal) (Tcl_AsyncHandler async, int sigNumber); /* 660 */
+ void (*reserved661)(void);
+ void (*reserved662)(void);
+ void (*reserved663)(void);
+ void (*reserved664)(void);
+ void (*reserved665)(void);
+ void (*reserved666)(void);
+ void (*reserved667)(void);
+ int (*tcl_UniCharLen) (const int *uniStr); /* 668 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
@@ -3378,8 +3394,8 @@ extern const TclStubs *tclStubsPtr;
(tclStubsPtr->tcl_UniCharIsUpper) /* 350 */
#define Tcl_UniCharIsWordChar \
(tclStubsPtr->tcl_UniCharIsWordChar) /* 351 */
-#define Tcl_UniCharLen \
- (tclStubsPtr->tcl_UniCharLen) /* 352 */
+#define Tcl_Char16Len \
+ (tclStubsPtr->tcl_Char16Len) /* 352 */
#define Tcl_UniCharNcmp \
(tclStubsPtr->tcl_UniCharNcmp) /* 353 */
#define Tcl_Char16ToUtfDString \
@@ -3994,6 +4010,15 @@ extern const TclStubs *tclStubsPtr;
/* Slot 659 is reserved */
#define Tcl_AsyncMarkFromSignal \
(tclStubsPtr->tcl_AsyncMarkFromSignal) /* 660 */
+/* Slot 661 is reserved */
+/* Slot 662 is reserved */
+/* Slot 663 is reserved */
+/* Slot 664 is reserved */
+/* Slot 665 is reserved */
+/* Slot 666 is reserved */
+/* Slot 667 is reserved */
+#define Tcl_UniCharLen \
+ (tclStubsPtr->tcl_UniCharLen) /* 668 */
#endif /* defined(USE_TCL_STUBS) */
@@ -4260,6 +4285,8 @@ extern const TclStubs *tclStubsPtr;
# define Tcl_UtfToUniCharDString Tcl_UtfToChar16DString
# undef Tcl_UtfToUniChar
# define Tcl_UtfToUniChar Tcl_UtfToChar16
+# undef Tcl_UniCharLen
+# define Tcl_UniCharLen Tcl_Char16Len
#endif
#if defined(USE_TCL_STUBS)
# define Tcl_WCharToUtfDString (sizeof(wchar_t) != sizeof(short) \
@@ -4271,6 +4298,9 @@ extern const TclStubs *tclStubsPtr;
# define Tcl_UtfToWChar (sizeof(wchar_t) != sizeof(short) \
? (int (*)(const char *, wchar_t *))tclStubsPtr->tcl_UtfToUniChar \
: (int (*)(const char *, wchar_t *))Tcl_UtfToChar16)
+# define Tcl_WCharLen (sizeof(wchar_t) != sizeof(short) \
+ ? (int (*)(wchar_t *))tclStubsPtr->tcl_UniCharLen \
+ : (int (*)(wchar_t *))Tcl_Char16Len)
#else
# define Tcl_WCharToUtfDString (sizeof(wchar_t) != sizeof(short) \
? (char *(*)(const wchar_t *, int, Tcl_DString *))Tcl_UniCharToUtfDString \
@@ -4281,6 +4311,9 @@ extern const TclStubs *tclStubsPtr;
# define Tcl_UtfToWChar (sizeof(wchar_t) != sizeof(short) \
? (int (*)(const char *, wchar_t *))Tcl_UtfToUniChar \
: (int (*)(const char *, wchar_t *))Tcl_UtfToChar16)
+# define Tcl_WCharLen (sizeof(wchar_t) != sizeof(short) \
+ ? (int (*)(wchar_t *))Tcl_UniCharLen \
+ : (int (*)(wchar_t *))Tcl_Char16Len)
#endif
/*
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index a1878c1..6374ab5 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -1635,7 +1635,7 @@ const TclStubs tclStubs = {
Tcl_UniCharIsSpace, /* 349 */
Tcl_UniCharIsUpper, /* 350 */
Tcl_UniCharIsWordChar, /* 351 */
- Tcl_UniCharLen, /* 352 */
+ Tcl_Char16Len, /* 352 */
Tcl_UniCharNcmp, /* 353 */
Tcl_Char16ToUtfDString, /* 354 */
Tcl_UtfToChar16DString, /* 355 */
@@ -1944,6 +1944,14 @@ const TclStubs tclStubs = {
0, /* 658 */
0, /* 659 */
Tcl_AsyncMarkFromSignal, /* 660 */
+ 0, /* 661 */
+ 0, /* 662 */
+ 0, /* 663 */
+ 0, /* 664 */
+ 0, /* 665 */
+ 0, /* 666 */
+ 0, /* 667 */
+ Tcl_UniCharLen, /* 668 */
};
/* !END!: Do not edit above this line. */
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index fcdf80a..fae6edd 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -1773,6 +1773,36 @@ Tcl_UniCharToTitle(
/*
*----------------------------------------------------------------------
*
+ * Tcl_Char16Len --
+ *
+ * Find the length of a UniChar string. The str input must be null
+ * terminated.
+ *
+ * Results:
+ * Returns the length of str in UniChars (not bytes).
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Tcl_Char16Len(
+ const unsigned short *uniStr) /* Unicode string to find length of. */
+{
+ int len = 0;
+
+ while (*uniStr != '\0') {
+ len++;
+ uniStr++;
+ }
+ return len;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_UniCharLen --
*
* Find the length of a UniChar string. The str input must be null
@@ -1787,9 +1817,10 @@ Tcl_UniCharToTitle(
*----------------------------------------------------------------------
*/
+#undef Tcl_UniCharLen
int
Tcl_UniCharLen(
- const Tcl_UniChar *uniStr) /* Unicode string to find length of. */
+ const int *uniStr) /* Unicode string to find length of. */
{
int len = 0;