From ffd8329a24b35299d0efa9610743cc016203dc84 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 9 Nov 2006 15:37:55 +0000 Subject: Implemented [string reverse]. Finalizes basic TIP#272 implementation. --- ChangeLog | 6 ++++++ doc/string.n | 11 +++++++++-- generic/tclCmdMZ.c | 30 +++++++++++++++++++++++++----- tests/string.test | 20 ++++++++++++++------ tests/stringComp.test | 4 ++-- 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1af7060..f3770c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2006-11-09 Donal K. Fellows + TIP#272 IMPLEMENTATION + + * generic/tclCmdMZ.c (Tcl_StringObjCmd): Implementation of the + * tests/string.test, tests/stringComp.test: [string reverse] command + * doc/string.n: from TIP#272. + * generic/tclCmdIL.c (Tcl_LreverseObjCmd): Implementation of the * generic/tclBasic.c, generic/tclInt.h: [lreverse] command from * tests/cmdIL.test (cmdIL-7.*): TIP#272. diff --git a/doc/string.n b/doc/string.n index 8620b50..a54091d 100644 --- a/doc/string.n +++ b/doc/string.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: string.n,v 1.30 2006/04/26 04:41:10 dgp Exp $ +'\" RCS: @(#) $Id: string.n,v 1.31 2006/11/09 15:37:56 dkf Exp $ '\" .so man.macros .TH string n 8.1 Tcl "Tcl Built-In Commands" @@ -277,6 +277,12 @@ and if \fIlast\fR is greater than or equal to the length of the string then it is treated as if it were \fBend\fR. If \fIfirst\fR is greater than \fIlast\fR or the length of the initial string, or \fIlast\fR is less than 0, then the initial string is returned untouched. +.VS 8.5 +.TP +\fBstring reverse \fIstring\fR +Returns a string that is the same length as \fIstring\fR but with its +characters in the reverse order. +.VE 8.5 .TP \fBstring tolower \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? Returns a value equal to \fIstring\fR except that all upper (or title) @@ -353,7 +359,8 @@ if {$length == 0} { expr(n), list(n) .SH KEYWORDS -case conversion, compare, index, match, pattern, string, word, equal, ctype +case conversion, compare, index, match, pattern, string, word, equal, +ctype, character, reverse '\" Local Variables: '\" mode: nroff diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 4a47d0f..474f90f 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdMZ.c,v 1.138 2006/11/02 16:39:06 dkf Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.139 2006/11/09 15:37:55 dkf Exp $ */ #include "tclInt.h" @@ -1133,16 +1133,16 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) "bytelength", "compare", "equal", "first", "index", "is", "last", "length", "map", "match", "range", "repeat", - "replace", "tolower", "toupper", "totitle", - "trim", "trimleft", "trimright", + "replace", "reverse", "tolower", "toupper", + "totitle", "trim", "trimleft", "trimright", "wordend", "wordstart", NULL }; enum options { STR_BYTELENGTH, STR_COMPARE, STR_EQUAL, STR_FIRST, STR_INDEX, STR_IS, STR_LAST, STR_LENGTH, STR_MAP, STR_MATCH, STR_RANGE, STR_REPEAT, - STR_REPLACE, STR_TOLOWER, STR_TOUPPER, STR_TOTITLE, - STR_TRIM, STR_TRIMLEFT, STR_TRIMRIGHT, + STR_REPLACE, STR_REVERSE, STR_TOLOWER, STR_TOUPPER, + STR_TOTITLE, STR_TRIM, STR_TRIMLEFT, STR_TRIMRIGHT, STR_WORDEND, STR_WORDSTART }; @@ -2195,6 +2195,26 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) } break; } + case STR_REVERSE: { + Tcl_UniChar *ustring1, *ustring2; + int i, j; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "string"); + return TCL_ERROR; + } + + ustring1 = Tcl_GetUnicodeFromObj(objv[2], &length1); + ustring2 = (Tcl_UniChar *) + ckalloc(sizeof(Tcl_UniChar) * (unsigned)length1); + + for (i=0,j=length1-1 ; i