summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2003-08-27 20:09:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2003-08-27 20:09:49 (GMT)
commit758447b224c0281798e3ea384b40d6deaa74902b (patch)
tree0dda0b6ece91b722a579df0137cac2e479c987b3 /generic/tclUtil.c
parentd5b3a83348608a67789570a2a477e0f204681bfd (diff)
downloadtcl-758447b224c0281798e3ea384b40d6deaa74902b.zip
tcl-758447b224c0281798e3ea384b40d6deaa74902b.tar.gz
tcl-758447b224c0281798e3ea384b40d6deaa74902b.tar.bz2
* generic/tclUtil.c: Corrected [Bug 411825] and other bugs in
TclNeedSpace() where non-breaking space (\u00A0) and backslash-escaped spaces were handled incorrectly. * tests/util.test: Added new tests util-8.[2-6].
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index cb15ffd..fb86a03 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -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: tclUtil.c,v 1.36.2.2 2003/07/16 21:25:07 hobbs Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.36.2.3 2003/08/27 20:09:49 dgp Exp $
*/
#include "tclInt.h"
@@ -2001,42 +2001,53 @@ TclNeedSpace(start, end)
CONST char *end; /* End of string (place where space will
* be added, if appropriate). */
{
- Tcl_UniChar ch;
-
/*
* A space is needed unless either
* (a) we're at the start of the string, or
- * (b) the trailing characters of the string consist of one or more
- * open curly braces preceded by a space or extending back to
- * the beginning of the string.
- * (c) the trailing characters of the string consist of a space
- * preceded by a character other than backslash.
*/
-
if (end == start) {
return 0;
}
+
+ /*
+ * (b) we're at the start of a nested list-element, quoted with an
+ * open curly brace; we can be nested arbitrarily deep, so long
+ * as the first curly brace starts an element, so backtrack over
+ * open curly braces that are trailing characters of the string; and
+ */
+
end = Tcl_UtfPrev(end, start);
- if (*end != '{') {
- Tcl_UtfToUniChar(end, &ch);
- /*
- * Direct char comparison on next line is safe as it is with
- * a character in the ASCII subset, and so single-byte in UTF8.
- */
- if (Tcl_UniCharIsSpace(ch) && ((end == start) || (end[-1] != '\\'))) {
- return 0;
- }
- return 1;
- }
- do {
+ while (*end == '{') {
if (end == start) {
return 0;
}
end = Tcl_UtfPrev(end, start);
- } while (*end == '{');
- Tcl_UtfToUniChar(end, &ch);
- if (Tcl_UniCharIsSpace(ch)) {
- return 0;
+ }
+
+ /*
+ * (c) the trailing character of the string is already a list-element
+ * separator (according to TclFindElement); that is, one of these
+ * characters:
+ * \u0009 \t TAB
+ * \u000A \n NEWLINE
+ * \u000B \v VERTICAL TAB
+ * \u000C \f FORM FEED
+ * \u000D \r CARRIAGE RETURN
+ * \u0020 SPACE
+ * with the condition that the penultimate character is not a
+ * backslash.
+ */
+
+ switch (*end) {
+ case ' ':
+ case '\f':
+ case '\n':
+ case '\r':
+ case '\t':
+ case '\v':
+ if ((end == start) || (end[-1] != '\\')) {
+ return 0;
+ }
}
return 1;
}