summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdMZ.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2006-11-09 15:37:55 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2006-11-09 15:37:55 (GMT)
commitffd8329a24b35299d0efa9610743cc016203dc84 (patch)
treed6c5a2fd27dcc828aa5438bc1aeee3fd1af501d0 /generic/tclCmdMZ.c
parentb07bb89f2a73a18a69b6666c3484f3e2271f53bf (diff)
downloadtcl-ffd8329a24b35299d0efa9610743cc016203dc84.zip
tcl-ffd8329a24b35299d0efa9610743cc016203dc84.tar.gz
tcl-ffd8329a24b35299d0efa9610743cc016203dc84.tar.bz2
Implemented [string reverse].
Finalizes basic TIP#272 implementation.
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r--generic/tclCmdMZ.c30
1 files changed, 25 insertions, 5 deletions
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<length1 ; i++,j--) {
+ ustring2[j] = ustring1[i];
+ }
+ Tcl_SetObjResult(interp, Tcl_NewUnicodeObj(ustring2, length1));
+ ckfree((char *) ustring2);
+ break;
+ }
case STR_TOLOWER:
case STR_TOUPPER:
case STR_TOTITLE: