summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2003-08-27 20:29:36 (GMT)
committerdgp <dgp@users.sourceforge.net>2003-08-27 20:29:36 (GMT)
commitc8cea779f14930d7be251801f4003224424f110d (patch)
tree26e0d90a1d891bec90388723abac70a342f51846 /generic
parent373d0139d5bf0bb40fe7fa5d28debbe32e27106c (diff)
downloadtcl-c8cea779f14930d7be251801f4003224424f110d.zip
tcl-c8cea779f14930d7be251801f4003224424f110d.tar.gz
tcl-c8cea779f14930d7be251801f4003224424f110d.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')
-rw-r--r--generic/tclUtil.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index fd58235..d939496 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.40 2003/08/27 19:55:50 dgp Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.41 2003/08/27 20:29:36 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;
}