summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-23 20:35:29 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-23 20:35:29 (GMT)
commitfa1e5ce70ab2eb900b31b03f0fddf2cc8c5243e8 (patch)
tree005a7e0fb5c2f5728bf99d4f662f224b616bedfe
parent6c6a470c2bc258d42f224373a084ee2a4d61e9a6 (diff)
downloadtcl-fa1e5ce70ab2eb900b31b03f0fddf2cc8c5243e8.zip
tcl-fa1e5ce70ab2eb900b31b03f0fddf2cc8c5243e8.tar.gz
tcl-fa1e5ce70ab2eb900b31b03f0fddf2cc8c5243e8.tar.bz2
New Tcl_ExternalToUtfDStringEx/Tcl_UtfToExternalDStringEx functions. Not used yet
-rw-r--r--generic/tcl.decls10
-rw-r--r--generic/tclDecls.h14
-rw-r--r--generic/tclEncoding.c53
-rw-r--r--generic/tclStubInit.c2
4 files changed, 68 insertions, 11 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index c39847b..c2a4abd 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -2424,6 +2424,16 @@ declare 656 {
const char *Tcl_UtfPrev(const char *src, const char *start)
}
+declare 657 {
+ int Tcl_ExternalToUtfDStringEx(Tcl_Encoding encoding,
+ const char *src, int srcLen, Tcl_DString *dsPtr, int flags)
+}
+declare 658 {
+ int Tcl_UtfToExternalDStringEx(Tcl_Encoding encoding,
+ const char *src, int srcLen, Tcl_DString *dsPtr, int flags)
+}
+
+
# ----- BASELINE -- FOR -- 8.7.0 ----- #
##############################################################################
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index e509c2b..6ba39d5 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1937,6 +1937,14 @@ EXTERN int Tcl_UtfCharComplete(const char *src, int length);
EXTERN const char * Tcl_UtfNext(const char *src);
/* 656 */
EXTERN const char * Tcl_UtfPrev(const char *src, const char *start);
+/* 657 */
+EXTERN int Tcl_ExternalToUtfDStringEx(Tcl_Encoding encoding,
+ const char *src, int srcLen,
+ Tcl_DString *dsPtr, int flags);
+/* 658 */
+EXTERN int Tcl_UtfToExternalDStringEx(Tcl_Encoding encoding,
+ const char *src, int srcLen,
+ Tcl_DString *dsPtr, int flags);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
@@ -2629,6 +2637,8 @@ typedef struct TclStubs {
int (*tcl_UtfCharComplete) (const char *src, int length); /* 654 */
const char * (*tcl_UtfNext) (const char *src); /* 655 */
const char * (*tcl_UtfPrev) (const char *src, const char *start); /* 656 */
+ int (*tcl_ExternalToUtfDStringEx) (Tcl_Encoding encoding, const char *src, int srcLen, Tcl_DString *dsPtr, int flags); /* 657 */
+ int (*tcl_UtfToExternalDStringEx) (Tcl_Encoding encoding, const char *src, int srcLen, Tcl_DString *dsPtr, int flags); /* 658 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
@@ -3971,6 +3981,10 @@ extern const TclStubs *tclStubsPtr;
(tclStubsPtr->tcl_UtfNext) /* 655 */
#define Tcl_UtfPrev \
(tclStubsPtr->tcl_UtfPrev) /* 656 */
+#define Tcl_ExternalToUtfDStringEx \
+ (tclStubsPtr->tcl_ExternalToUtfDStringEx) /* 657 */
+#define Tcl_UtfToExternalDStringEx \
+ (tclStubsPtr->tcl_UtfToExternalDStringEx) /* 658 */
#endif /* defined(USE_TCL_STUBS) */
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 4eabbda..fd5c52b 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -1089,7 +1089,7 @@ Tcl_CreateEncoding(
/*
*-------------------------------------------------------------------------
*
- * Tcl_ExternalToUtfDString --
+ * Tcl_ExternalToUtfDString/Tcl_ExternalToUtfDStringEx --
*
* Convert a source buffer from the specified encoding into UTF-8. If any
* of the bytes in the source buffer are invalid or cannot be represented
@@ -1099,7 +1099,7 @@ Tcl_CreateEncoding(
* Results:
* The converted bytes are stored in the DString, which is then NULL
* terminated. The return value is a pointer to the value stored in the
- * DString.
+ * DString resp. an error code.
*
* Side effects:
* None.
@@ -1117,10 +1117,26 @@ Tcl_ExternalToUtfDString(
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
+ Tcl_ExternalToUtfDStringEx(encoding, src, srcLen, dstPtr, 0);
+ return Tcl_DStringValue(dstPtr);
+}
+
+
+int
+Tcl_ExternalToUtfDStringEx(
+ Tcl_Encoding encoding, /* The encoding for the source string, or NULL
+ * for the default system encoding. */
+ const char *src, /* Source string in specified encoding. */
+ int srcLen, /* Source string length in bytes, or < 0 for
+ * encoding-specific string length. */
+ Tcl_DString *dstPtr, /* Uninitialized or free DString in which the
+ * converted string is stored. */
+ int flags) /* Conversion control flags. */
+{
char *dst;
Tcl_EncodingState state;
const Encoding *encodingPtr;
- int flags, dstLen, result, soFar, srcRead, dstWrote, dstChars;
+ int dstLen, result, soFar, srcRead, dstWrote, dstChars;
Tcl_DStringInit(dstPtr);
dst = Tcl_DStringValue(dstPtr);
@@ -1137,7 +1153,7 @@ Tcl_ExternalToUtfDString(
srcLen = encodingPtr->lengthProc(src);
}
- flags = TCL_ENCODING_START | TCL_ENCODING_END;
+ flags |= TCL_ENCODING_START | TCL_ENCODING_END;
while (1) {
result = encodingPtr->toUtfProc(encodingPtr->clientData, src, srcLen,
@@ -1146,7 +1162,7 @@ Tcl_ExternalToUtfDString(
if (result != TCL_CONVERT_NOSPACE) {
Tcl_DStringSetLength(dstPtr, soFar);
- return Tcl_DStringValue(dstPtr);
+ return result;
}
flags &= ~TCL_ENCODING_START;
@@ -1279,7 +1295,7 @@ Tcl_ExternalToUtf(
/*
*-------------------------------------------------------------------------
*
- * Tcl_UtfToExternalDString --
+ * Tcl_UtfToExternalDString/Tcl_UtfToExternalDStringEx --
*
* Convert a source buffer from UTF-8 to the specified encoding. If any
* of the bytes in the source buffer are invalid or cannot be represented
@@ -1288,7 +1304,7 @@ Tcl_ExternalToUtf(
* Results:
* The converted bytes are stored in the DString, which is then NULL
* terminated in an encoding-specific manner. The return value is a
- * pointer to the value stored in the DString.
+ * pointer to the value stored in the DString resp. an error code.
*
* Side effects:
* None.
@@ -1306,10 +1322,25 @@ Tcl_UtfToExternalDString(
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
+ Tcl_UtfToExternalDStringEx(encoding, src, srcLen, dstPtr, 0);
+ return Tcl_DStringValue(dstPtr);
+}
+
+int
+Tcl_UtfToExternalDStringEx(
+ Tcl_Encoding encoding, /* The encoding for the converted string, or
+ * NULL for the default system encoding. */
+ const char *src, /* Source string in UTF-8. */
+ int srcLen, /* Source string length in bytes, or < 0 for
+ * strlen(). */
+ Tcl_DString *dstPtr, /* Uninitialized or free DString in which the
+ * converted string is stored. */
+ int flags) /* Conversion control flags. */
+{
char *dst;
Tcl_EncodingState state;
const Encoding *encodingPtr;
- int flags, dstLen, result, soFar, srcRead, dstWrote, dstChars;
+ int dstLen, result, soFar, srcRead, dstWrote, dstChars;
Tcl_DStringInit(dstPtr);
dst = Tcl_DStringValue(dstPtr);
@@ -1325,10 +1356,10 @@ Tcl_UtfToExternalDString(
} else if (srcLen < 0) {
srcLen = strlen(src);
}
- flags = TCL_ENCODING_START | TCL_ENCODING_END;
+ flags |= TCL_ENCODING_START | TCL_ENCODING_END | TCL_ENCODING_EXTERNAL;
while (1) {
result = encodingPtr->fromUtfProc(encodingPtr->clientData, src,
- srcLen, flags | TCL_ENCODING_EXTERNAL, &state, dst, dstLen,
+ srcLen, flags, &state, dst, dstLen,
&srcRead, &dstWrote, &dstChars);
soFar = dst + dstWrote - Tcl_DStringValue(dstPtr);
@@ -1337,7 +1368,7 @@ Tcl_UtfToExternalDString(
Tcl_DStringSetLength(dstPtr, soFar + 1);
}
Tcl_DStringSetLength(dstPtr, soFar);
- return Tcl_DStringValue(dstPtr);
+ return result;
}
flags &= ~TCL_ENCODING_START;
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index b66af58..0473bb1 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -1932,6 +1932,8 @@ const TclStubs tclStubs = {
Tcl_UtfCharComplete, /* 654 */
Tcl_UtfNext, /* 655 */
Tcl_UtfPrev, /* 656 */
+ Tcl_ExternalToUtfDStringEx, /* 657 */
+ Tcl_UtfToExternalDStringEx, /* 658 */
};
/* !END!: Do not edit above this line. */