diff options
-rw-r--r-- | doc/string.n | 33 | ||||
-rw-r--r-- | generic/tclCmdMZ.c | 6 | ||||
-rw-r--r-- | tests/string.test | 11 |
3 files changed, 30 insertions, 20 deletions
diff --git a/doc/string.n b/doc/string.n index 17bf186..07ab0a7 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.8 1999/05/06 20:13:23 stanton Exp $ +'\" RCS: @(#) $Id: string.n,v 1.9 1999/05/06 22:50:02 stanton Exp $ '\" .so man.macros .TH string n 8.1 Tcl "Tcl Built-In Commands" @@ -32,19 +32,19 @@ the byte length are rare. In almost all cases, you should use the \fBstring length\fB operation. Refer to the \fBTcl_NumUtfChars\fR manual entry for more details on the UTF-8 representation. .TP -\fBstring compare ?\fI-nocase\fR? ?\fI-length int\fR? \fIstring1 string2\fR +\fBstring compare ?\fB-nocase\fR? ?\fB-length int\fR? \fIstring1 string2\fR .VE 8.1 Perform a character-by-character comparison of strings \fIstring1\fR and \fIstring2\fR in the same way as the C \fBstrcmp\fR procedure. Return \-1, 0, or 1, depending on whether \fIstring1\fR is lexicographically less than, equal to, or greater than \fIstring2\fR. .VS 8.1 -If \fI-length\fR is specified, it works like C \fBstrncmp\fR, -comparing only to the specified length. If \fI-length\fR is negative, -it is ignored. If \fI-nocase\fR is specified, then the strings are +If \fB-length\fR is specified, it works like C \fBstrncmp\fR, +comparing only to the specified length. If \fB-length\fR is negative, +it is ignored. If \fB-nocase\fR is specified, then the strings are compared in a case-insensitive manner. .TP -\fBstring equal ?\fI-nocase\fR? ?\fI-length int\fR? \fIstring1 string2\fR +\fBstring equal ?\fB-nocase\fR? ?\fB-length int\fR? \fIstring1 string2\fR .VE 8.1 Like the \fBcompare\fR method, but returns 1 when the strings are equal, or 0 when not. @@ -78,10 +78,10 @@ returned. .RE .VS 8.1 .TP -\fBstring is \fIclass\fR ?\fI-strict\fR? ?\fI-failindex varname\fR? \fIstring\fR +\fBstring is \fIclass\fR ?\fB-strict\fR? ?\fB-failindex \fIvarname\fR? \fIstring\fR See if \fIstring\fR is a valid form of the specified class. If -\fI-strict\fR is specified, then an empty string returns 0, otherwise and -empty string will return 1 on any class. If \fI-failindex\fR is specified, +\fB-strict\fR is specified, then an empty string returns 0, otherwise and +empty string will return 1 on any class. If \fB-failindex\fR is specified, then if the function returns 0, the index in the string where the class was no longer valid will be stored in the variable named \fIvarname\fR. The \fIvarname\fR will not be set if the function returns 1. The following @@ -137,16 +137,17 @@ Returns a decimal string giving the number of characters in number of bytes used to store the string. .VS 8.1 .TP -\fBstring map ?\fIoptions\fR? \fIcharMap string\fR +\fBstring map ?\fB-nocase\fR? \fIcharMap string\fR Replaces characters in \fIstring\fR based on the key-value pairs in \fIcharMap\fR. \fIcharMap\fR is a list of key value key value ... as in the form returned by \fBarray get\fR. Each instance of a key in -the string will be replace with its corresponding value. Both key and -value may be multiple characters. This is done -in an ordered manner, so the key appearing first in the list will be -checked first, and so on. \fIstring\fR is only iterated over once, -so earlier key replacements will have no affect for later key matches. -For example, +the string will be replace with its corresponding value. If +\fB-nocase\fR is specified, then matching is done without regard to +case differences. Both key and value may be multiple characters. This +is done in an ordered manner, so the key appearing first in the list +will be checked first, and so on. \fIstring\fR is only iterated over +once, so earlier key replacements will have no affect for later key +matches. For example, .RS .CS \fBstring map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc\fR diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index dddad59..dc5607c 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -13,7 +13,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.7 1999/05/06 19:21:11 stanton Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.8 1999/05/06 22:50:03 stanton Exp $ */ #include "tclInt.h" @@ -879,7 +879,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) * Anything matches at 0 chars, right? */ match = 0; - } else if (nocase || ((reqlength > 0) && (reqlength < length))) { + } else if (nocase || ((reqlength > 0) && (reqlength <= length))) { /* * with -nocase or -length we have to check true char length * as it could be smaller than expected @@ -901,7 +901,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) match = Tcl_UtfNcmp(string1, string2, (unsigned) length); } - if ((match == 0) && (reqlength >= length)) { + if ((match == 0) && (reqlength > length)) { match = length1 - length2; } } else { diff --git a/tests/string.test b/tests/string.test index cd396c2..71f83be 100644 --- a/tests/string.test +++ b/tests/string.test @@ -11,7 +11,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.test,v 1.8 1999/05/06 18:46:43 stanton Exp $ +# RCS: @(#) $Id: string.test,v 1.9 1999/05/06 22:50:04 stanton Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -95,6 +95,12 @@ test string-2.20 {string compare -len unicode} { test string-2.21 {string compare -nocase with special index} { list [catch {string compare -nocase -length end-3 Abcde abxyz} msg] $msg } {1 {expected integer but got "end-3"}} +test string-2.22 {string equal with length, unequal strings} { + string compare -length 2 abc abde +} 0 +test string-2.22 {string equal with length, unequal strings} { + string compare -length 2 ab abde +} 0 # only need a few tests on equal, since it uses the same code as # string compare, but just modifies the return output @@ -119,6 +125,9 @@ test string-3.6 {string equal -nocase} { test string-3.7 {string equal -nocase} { string equal -nocase abcde abcde } 1 +test string-3.8 {string equal with length, unequal strings} { + string equal -length 2 abc abde +} 1 test string-4.1 {string first} { list [catch {string first a} msg] $msg |