summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorericm <ericm>2000-02-03 17:29:57 (GMT)
committerericm <ericm>2000-02-03 17:29:57 (GMT)
commit32c58211007ce985f1da733cc7426626692dedf9 (patch)
treed35b33d981f526a9c48267ba77e17467e04d0736
parent3064162d9d6b976b8f052635cab3bf5def643b4b (diff)
downloadtk-32c58211007ce985f1da733cc7426626692dedf9.zip
tk-32c58211007ce985f1da733cc7426626692dedf9.tar.gz
tk-32c58211007ce985f1da733cc7426626692dedf9.tar.bz2
* tests/text.test:
* generic/tkText.c (DumpLine/DumpSegment): Changed DumpSegment to take a TkTextIndex instead of two integer offsets, so that it could use TkTextPrintIndex to format the offsets into an index, which makes it UTF smart (bug #2582).
-rw-r--r--ChangeLog8
-rw-r--r--generic/tkText.c38
-rw-r--r--tests/text.test16
3 files changed, 46 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index f054b89..cc89b5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2000-02-03 Eric Melski <ericm@scriptics.com>
+
+ * tests/text.test:
+ * generic/tkText.c (DumpLine/DumpSegment): Changed DumpSegment to
+ take a TkTextIndex instead of two integer offsets, so that it
+ could use TkTextPrintIndex to format the offsets into an index,
+ which makes it UTF smart (bug #2582).
+
2000-02-01 Eric Melski <ericm@scriptics.com>
* library/tk.tcl:
diff --git a/generic/tkText.c b/generic/tkText.c
index fb51ed4..d92363b 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -14,7 +14,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkText.c,v 1.13 2000/01/21 17:25:43 ericm Exp $
+ * RCS: @(#) $Id: tkText.c,v 1.14 2000/02/03 17:29:57 ericm Exp $
*/
#include "default.h"
@@ -302,7 +302,7 @@ static void DumpLine _ANSI_ARGS_((Tcl_Interp *interp,
TkText *textPtr, int what, TkTextLine *linePtr,
int start, int end, int lineno, char *command));
static int DumpSegment _ANSI_ARGS_((Tcl_Interp *interp, char *key,
- char *value, char * command, int lineno, int offset,
+ char *value, char * command, TkTextIndex *index,
int what));
/*
@@ -2222,7 +2222,7 @@ TextDumpCmd(textPtr, interp, argc, argv)
if (TkTextGetIndex(interp, textPtr, argv[arg], &index1) != TCL_OK) {
return TCL_ERROR;
}
- lineno = TkBTreeLineIndex(index1.linePtr) + 1;
+ lineno = TkBTreeLineIndex(index1.linePtr);
arg++;
atEnd = 0;
if (argc == arg) {
@@ -2290,6 +2290,7 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command)
{
int offset;
TkTextSegment *segPtr;
+ TkTextIndex index;
/*
* Must loop through line looking at its segments.
* character
@@ -2298,6 +2299,7 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command)
* image
* window
*/
+
for (offset = 0, segPtr = linePtr->segPtr ;
(offset < endByte) && (segPtr != (TkTextSegment *)NULL) ;
offset += segPtr->size, segPtr = segPtr->nextPtr) {
@@ -2314,31 +2316,37 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command)
}
savedChar = segPtr->body.chars[last];
segPtr->body.chars[last] = '\0';
+
+ TkTextMakeByteIndex(textPtr->tree, lineno, offset + first, &index);
DumpSegment(interp, "text", segPtr->body.chars + first,
- command, lineno, offset + first, what);
+ command, &index, what);
segPtr->body.chars[last] = savedChar;
} else if ((offset >= startByte)) {
if ((what & TK_DUMP_MARK) && (segPtr->typePtr->name[0] == 'm')) {
TkTextMark *markPtr = (TkTextMark *)&segPtr->body;
char *name = Tcl_GetHashKey(&textPtr->markTable, markPtr->hPtr);
- DumpSegment(interp, "mark", name,
- command, lineno, offset, what);
+
+ TkTextMakeByteIndex(textPtr->tree, lineno, offset, &index);
+ DumpSegment(interp, "mark", name, command, &index, what);
} else if ((what & TK_DUMP_TAG) &&
(segPtr->typePtr == &tkTextToggleOnType)) {
+ TkTextMakeByteIndex(textPtr->tree, lineno, offset, &index);
DumpSegment(interp, "tagon",
segPtr->body.toggle.tagPtr->name,
- command, lineno, offset, what);
+ command, &index, what);
} else if ((what & TK_DUMP_TAG) &&
(segPtr->typePtr == &tkTextToggleOffType)) {
+ TkTextMakeByteIndex(textPtr->tree, lineno, offset, &index);
DumpSegment(interp, "tagoff",
segPtr->body.toggle.tagPtr->name,
- command, lineno, offset, what);
+ command, &index, what);
} else if ((what & TK_DUMP_IMG) &&
(segPtr->typePtr->name[0] == 'i')) {
TkTextEmbImage *eiPtr = (TkTextEmbImage *)&segPtr->body;
char *name = (eiPtr->name == NULL) ? "" : eiPtr->name;
+ TkTextMakeByteIndex(textPtr->tree, lineno, offset, &index);
DumpSegment(interp, "image", name,
- command, lineno, offset, what);
+ command, &index, what);
} else if ((what & TK_DUMP_WIN) &&
(segPtr->typePtr->name[0] == 'w')) {
TkTextEmbWindow *ewPtr = (TkTextEmbWindow *)&segPtr->body;
@@ -2348,8 +2356,9 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command)
} else {
pathname = Tk_PathName(ewPtr->tkwin);
}
+ TkTextMakeByteIndex(textPtr->tree, lineno, offset, &index);
DumpSegment(interp, "window", pathname,
- command, lineno, offset, what);
+ command, &index, what);
}
}
}
@@ -2367,17 +2376,16 @@ DumpLine(interp, textPtr, what, linePtr, startByte, endByte, lineno, command)
* Either evals the callback or appends elements to the result string.
*/
static int
-DumpSegment(interp, key, value, command, lineno, offset, what)
+DumpSegment(interp, key, value, command, index, what)
Tcl_Interp *interp;
char *key; /* Segment type key */
char *value; /* Segment value */
char *command; /* Script callback */
- int lineno; /* Line number for indices dump */
- int offset; /* Byte position */
+ TkTextIndex *index; /* index with line/byte position info */
int what; /* Look for TK_DUMP_INDEX bit */
{
- char buffer[30];
- sprintf(buffer, "%d.%d", lineno, offset);
+ char buffer[TCL_INTEGER_SPACE*2];
+ TkTextPrintIndex(index, buffer);
if (command == (char *) NULL) {
Tcl_AppendElement(interp, key);
Tcl_AppendElement(interp, value);
diff --git a/tests/text.test b/tests/text.test
index d7b4210..651e7d8 100644
--- a/tests/text.test
+++ b/tests/text.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: text.test,v 1.9 2000/01/21 17:25:43 ericm Exp $
+# RCS: @(#) $Id: text.test,v 1.10 2000/02/03 17:29:58 ericm Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
source [file join [pwd] [file dirname [info script]] defs.tcl]
@@ -1274,6 +1274,20 @@ test text-22.24 {TextDumpCmd procedure, command script} {
set x
} {mark 1.0 current mark 1.0 insert mark 2.4 m}
catch {unset x}
+test text-22.25 {TextDumpCmd procedure, unicode characters} {
+ catch {destroy .t}
+ text .t
+ .t delete 1.0 end
+ .t insert 1.0 \xb1\xb1\xb1
+ .t dump -all 1.0 2.0
+} "text \xb1\xb1\xb1 1.0 mark insert 1.3 mark current 1.3 text {\n} 1.3"
+test text-22.26 {TextDumpCmd procedure, unicode characters} {
+ catch {destroy .t}
+ text .t
+ .t delete 1.0 end
+ .t insert 1.0 abc\xb1\xb1\xb1
+ .t dump -all 1.0 2.0
+} "text abc\xb1\xb1\xb1 1.0 mark insert 1.6 mark current 1.6 text {\n} 1.6"
set l [interp hidden]
eval destroy [winfo children .]