From c6bc600d803dbcb3b90be56c4653c52add4ba9b3 Mon Sep 17 00:00:00 2001 From: ericm Date: Tue, 25 Jul 2000 00:05:40 +0000 Subject: * tests/text.test: Added tests for -regexp -nocase searches with backslash character classes. * generic/tkText.c (TextSearchCmd): Text search did not work properly when -regexp and -nocase were used, in combination with backslash character classes represented by capital letters (ie, \W, \M); altered implementation of -regexp -nocase searches to use new regexp interfaces to fix this problem. [Bug: 5988]. --- ChangeLog | 11 +++++++++++ generic/tkText.c | 15 +++++++++++---- tests/text.test | 26 +++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d25081..bc15fd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2000-07-24 Eric Melski + + * tests/text.test: Added tests for -regexp -nocase searches with + backslash character classes. + + * generic/tkText.c (TextSearchCmd): Text search did not work + properly when -regexp and -nocase were used, in combination with + backslash character classes represented by capital letters (ie, + \W, \M); altered implementation of -regexp -nocase searches to use + new regexp interfaces to fix this problem. [Bug: 5988]. + 2000-07-21 Eric Melski * tests/text.test: Added tests for searching when text is elided. diff --git a/generic/tkText.c b/generic/tkText.c index cd5cac0..2ab2e2a 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.16 2000/07/21 23:44:11 ericm Exp $ + * RCS: @(#) $Id: tkText.c,v 1.17 2000/07/25 00:05:40 ericm Exp $ */ #include "default.h" @@ -1673,6 +1673,7 @@ TextSearchCmd(textPtr, interp, argc, argv) TkTextSegment *segPtr; TkTextLine *linePtr; TkTextIndex curIndex; + Tcl_Obj *patObj = NULL; Tcl_RegExp regexp = NULL; /* Initialization needed only to * prevent compiler warning. */ @@ -1748,7 +1749,7 @@ TextSearchCmd(textPtr, interp, argc, argv) * Convert the pattern to lower-case if we're supposed to ignore case. */ - if (noCase) { + if (noCase && exact) { Tcl_DStringInit(&patDString); Tcl_DStringAppend(&patDString, pattern, -1); pattern = Tcl_DStringValue(&patDString); @@ -1798,7 +1799,10 @@ TextSearchCmd(textPtr, interp, argc, argv) if (exact) { patLength = strlen(pattern); } else { - regexp = Tcl_RegExpCompile(interp, pattern); + patObj = Tcl_NewStringObj(pattern, -1); + Tcl_IncrRefCount(patObj); + regexp = Tcl_GetRegExpFromObj(interp, patObj, + (noCase ? TCL_REG_NOCASE : 0) | TCL_REG_ADVANCED); if (regexp == NULL) { code = TCL_ERROR; goto done; @@ -2031,9 +2035,12 @@ TextSearchCmd(textPtr, interp, argc, argv) } done: Tcl_DStringFree(&line); - if (noCase) { + if (noCase && exact) { Tcl_DStringFree(&patDString); } + if (patObj != NULL) { + Tcl_DecrRefCount(patObj); + } return code; } diff --git a/tests/text.test b/tests/text.test index 1d3a7bd..5e676dd 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.11 2000/07/21 23:44:12 ericm Exp $ +# RCS: @(#) $Id: text.test,v 1.12 2000/07/25 00:05:40 ericm Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -1139,6 +1139,30 @@ test text-20.69 {TextSearchCmd, hidden text does not affect match index} { .t2 search boo 1.0 } 3.3 +test text-20.70 {TextSearchCmd, -regexp -nocase searches} { + catch {destroy .t} + pack [text .t] + .t insert end "word1 word2" + set res [.t search -nocase -regexp {\mword.} 1.0 end] + destroy .t + set res +} 1.0 +test text-20.71 {TextSearchCmd, -regexp -nocase searches} { + catch {destroy .t} + pack [text .t] + .t insert end "word1 word2" + set res [.t search -nocase -regexp {word.\M} 1.0 end] + destroy .t + set res +} 1.0 +test text-20.72 {TextSearchCmd, -regexp -nocase searches} { + catch {destroy .t} + pack [text .t] + .t insert end "word1 word2" + set res [.t search -nocase -regexp {word.\W} 1.0 end] + destroy .t + set res +} 1.0 eval destroy [winfo child .] text .t2 -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100 -- cgit v0.12