diff options
author | dgp <dgp@users.sourceforge.net> | 2020-04-25 16:46:14 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2020-04-25 16:46:14 (GMT) |
commit | 00be8f79390225af463f86ed4380d7441b7de0ac (patch) | |
tree | 9e843a16920c24c4b6ce16b773754ecccd3adef5 /generic/tclTest.c | |
parent | 4804a3fdec7c1461645097c4aff7561ff9b2d210 (diff) | |
parent | 6852f6d630fb0cbb7521dc006203efb9697bc815 (diff) | |
download | tcl-00be8f79390225af463f86ed4380d7441b7de0ac.zip tcl-00be8f79390225af463f86ed4380d7441b7de0ac.tar.gz tcl-00be8f79390225af463f86ed4380d7441b7de0ac.tar.bz2 |
Bring forward a collection of missing tests.
Diffstat (limited to 'generic/tclTest.c')
-rw-r--r-- | generic/tclTest.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c index 1676bae..322d6b4 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -6713,7 +6713,8 @@ TestUtfNextCmd( int objc, Tcl_Obj *const objv[]) { - int numBytes; + int numBytes; /* Number of bytes supplied in the test string */ + int offset; /* Number of bytes we are permitted to read */ char *bytes; const char *result, *first; char buffer[32]; @@ -6721,20 +6722,46 @@ TestUtfNextCmd( const char *p = tobetested; (void)dummy; - if (objc != 2) { - Tcl_WrongNumArgs(interp, 1, objv, "bytes"); + if (objc < 2 || objc > 3) { + Tcl_WrongNumArgs(interp, 1, objv, "bytes ?numBytes?"); return TCL_ERROR; } + bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &numBytes); + offset = numBytes +TCL_UTF_MAX -1; /* If no constraint is given, allow + * the terminating NUL to limit + * operations. */ + + if (objc == 3) { + if (TCL_OK != TclGetIntForIndex(interp, objv[2], numBytes, &offset)) { + return TCL_ERROR; + } + if (offset < 0) { + offset = 0; + } + if (offset > numBytes +TCL_UTF_MAX -1) { + offset = numBytes +TCL_UTF_MAX -1; + } + } + if (numBytes > (int)sizeof(buffer)-2) { - Tcl_AppendResult(interp, "\"testutfnext\" can only handle 30 bytes", NULL); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "\"testutfnext\" can only handle %d bytes", + (int)(sizeof(buffer) - 2))); return TCL_ERROR; } memcpy(buffer + 1, bytes, numBytes); buffer[0] = buffer[numBytes + 1] = '\x00'; + if (!Tcl_UtfCharComplete(buffer + 1, offset)) { + /* Cannot scan a complete sequence from the data */ + + Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + return TCL_OK; + } + first = TclUtfNext(buffer + 1); while ((buffer[0] = *p++) != '\0') { /* Run Tcl_UtfNext with many more possible bytes at src[-1], all should give the same result */ |