I have an app where I am searching a Tk::TextUndo widget for string literals (" and ') and formatting the text if found. The problem is I have accounted for the escape character (\) and everything works fine unless there is escaped quoted text using either single or double quotes on the same line as quoted text of another quote character (if " was used in escape then ' is the problem and vise versa).

Here is the code snippet:

my @quotes = qw(" '); foreach my $word (@quotes) { my ($line, @found, $char, $beg, $last, $escape); my $word_len = length $word; my $next = $start; while (my $from = $t->search(-regexp, "$word", $next, $end)) { $next = "$from + $word_len chars"; my ($good, $trash) = split(/\./, $from); my $comment = $t->search( -regexp => $Comment, "$from linestart" => "$from lineend"); my $comment2 = $t->search(-regexp => $Comment2, "$from linestart" => "$from lineend"); @found = split(//, $data[$good - 1]); $char = 0; $escape = 0; foreach my $chars (@found) { $escape = 1 if ($chars eq "\\"); $last = $good.".".($char + 1) if (($chars =~ /$word/) && ($be +g) && ($escape != 1)); $beg = $good.".".$char if (($chars =~ /$word/) && (!$beg) && + ($escape != 1)); $escape = 0 if (($escape == 1) && ($chars =~ /$word/) || ($ch +ars =~ /\w+/)); if (($beg) && ($last)) { unless($comment and $t->compare($comment, '<', $beg)) { unless($comment2 and $t->compare($comment2, '<', $beg)) + { unhighlight_range($t, $beg, $last); mark_word($t, $beg, $last, 'String'); } } undef $beg; undef $last; } $char++; } undef $beg; undef $last; } }
Using the above code the following examples can be seen.

Ex:

"some text" not quoted 'this is'

the above example works fine but the following has issues.

Ex:

"some \"text\"" 'this is suppose to be'

Now that example does not quote the single quoted text but the following does.

Ex:

"some \"text\"" This makes it ok 'this is suppose to be'

Any ideas from looking at the code? I know it has to do with the value of $escape and whether or not $last and $beg have a value and when they get undefined but I am having trouble pinpointing it.

Oh and yes I know I need to take into account the other quoting methods such as qw() and such but I need this worked out first.


www.perlskripts.com

In reply to Tk $widget->search() issues? by Elijah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.