summaryrefslogtreecommitdiffstats
path: root/generic/tclTest.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-04-15 19:38:00 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-04-15 19:38:00 (GMT)
commit2ca7fe6104b48f174bf68f4b3179b19f660fc0ab (patch)
tree49da7bab05e07f335ee3b629d86c5cf9996d94df /generic/tclTest.c
parent6422781fdc73ec84db06ad3611a4a1676b4cb2eb (diff)
parentf480c2471b8d644bb8cf256efcd0f99507fb4d10 (diff)
downloadtcl-2ca7fe6104b48f174bf68f4b3179b19f660fc0ab.zip
tcl-2ca7fe6104b48f174bf68f4b3179b19f660fc0ab.tar.gz
tcl-2ca7fe6104b48f174bf68f4b3179b19f660fc0ab.tar.bz2
Merge 8.5
Diffstat (limited to 'generic/tclTest.c')
-rw-r--r--generic/tclTest.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 2a43d91..d721787 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -315,6 +315,7 @@ static Tcl_FSListVolumesProc SimpleListVolumes;
static Tcl_FSPathInFilesystemProc SimplePathInFilesystem;
static Tcl_Obj * SimpleRedirect(Tcl_Obj *pathPtr);
static Tcl_FSMatchInDirectoryProc SimpleMatchInDirectory;
+static Tcl_ObjCmdProc TestUtfNextCmd;
static Tcl_ObjCmdProc TestUtfPrevCmd;
static Tcl_ObjCmdProc TestNumUtfCharsCmd;
static Tcl_ObjCmdProc TestFindFirstCmd;
@@ -572,8 +573,10 @@ Tcltest_Init(
NULL, NULL);
Tcl_CreateObjCommand(interp, "testsetobjerrorcode",
TestsetobjerrorcodeCmd, NULL, NULL);
+ Tcl_CreateObjCommand(interp, "testutfnext",
+ TestUtfNextCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "testutfprev",
- TestUtfPrevCmd, (ClientData) 0, NULL);
+ TestUtfPrevCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "testnumutfchars",
TestNumUtfCharsCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "testfindfirst",
@@ -6724,6 +6727,52 @@ SimpleListVolumes(void)
}
/*
+ * Used to check operations of Tcl_UtfNext.
+ *
+ * Usage: testutfnext $bytes $offset
+ */
+
+static int
+TestUtfNextCmd(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *const objv[])
+{
+ int numBytes, offset = 0;
+ char *bytes;
+ const char *result;
+ Tcl_Obj *copy;
+
+ if (objc < 2 || objc > 3) {
+ Tcl_WrongNumArgs(interp, 1, objv, "bytes ?offset?");
+ return TCL_ERROR;
+ }
+
+ bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &numBytes);
+
+ if (objc == 3) {
+ if (TCL_OK != TclGetIntForIndex(interp, objv[2], numBytes, &offset)) {
+ return TCL_ERROR;
+ }
+ if (offset < 0) {
+ offset = 0;
+ }
+ if (offset > numBytes) {
+ offset = numBytes;
+ }
+ }
+ copy = Tcl_DuplicateObj(objv[1]);
+ bytes = (char *) Tcl_SetByteArrayLength(copy, numBytes+1);
+ bytes[numBytes] = '\0';
+
+ result = Tcl_UtfNext(bytes + offset);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(result - bytes));
+
+ Tcl_DecrRefCount(copy);
+ return TCL_OK;
+}
+/*
* Used to check operations of Tcl_UtfPrev.
*
* Usage: testutfprev $bytes $offset
@@ -6740,16 +6789,16 @@ TestUtfPrevCmd(
char *bytes;
const char *result;
Tcl_Obj *copy;
-
+
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "bytes ?offset?");
return TCL_ERROR;
}
bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &numBytes);
-
+
if (objc == 3) {
- if (TCL_OK != Tcl_GetIntFromObj(interp, objv[2], &offset)) {
+ if (TCL_OK != TclGetIntForIndex(interp, objv[2], numBytes, &offset)) {
return TCL_ERROR;
}
if (offset < 0) {
@@ -6766,9 +6815,9 @@ TestUtfPrevCmd(
bytes[numBytes] = '\0';
result = Tcl_UtfPrev(bytes + offset, bytes);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(result - bytes));
Tcl_DecrRefCount(copy);
- Tcl_SetObjResult(interp, Tcl_NewIntObj(result - bytes));
return TCL_OK;
}