Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 1ab685968ccae9be60394dbc8cb2665528781b0e
Ticket: 218370ffffffffffffffffffffffffffffffffff
regexp -start, -lineanchor don't combine well
User & Date: nobody on 2000-10-26 00:56:47
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 4233 RFE
    Version: 8.3
    SubmitDate: '2000-02-23'
    LastModified: '2000-02-23'
    Severity: MED
    Status: Closed
    Submitter: techsupp
    ChangedBy: hobbs
    OS: All
    FixedDate: '2000-10-25'
    ClosedDate: '2000-02-23'
    
    
    Name:
    Vince Darley
    
    ReproducibleScript:
    This is correct:
    
    % regexp -start 1 -lineanchor {^[a-z]*} "a\naaa" found
    1
    % set found
    aaa
    
    However if we instead use '-start 2', the regexp fails:
    
    % regexp -start 2 -lineanchor {^[a-z]*} "a\naaa" found
    0
    
    even though position 2 is in fact a suitable position for ^ to match as a lineanchor.  The problem is that '-start' is implemented in too simplistic a way (and we could implement a similar '-end' with similar problems with $) -- it just passes 'string range $text $start end' to the regexp code, and turns off the ability of '^' to match the beginning of string.
    
    The best solution is to add proper support for -start (and -end IMHO) to Henry Spencer's regexp code.
    
    For a general workaround, consider: given a generic $pat, and a generic $text, if we wish to know the result of:
    
    regexp -start 2 -lineanchor -- $pat $text result
    
    Then possible workarounds need to examine whether 'string index $text 1' is a newline or not.  If it is not a newline, then I think everything should work ok.  If it is a newline, I think the best solution is to use: 'regexp -lineanchor -- $pat [string range $text 2 end] instead'.  I'm not sure whether that actually covers all possible problems...
    
    So perhaps: 
    
    if {$start > 0 && [regexp {[\r\n]} [string index $text $start]]} {
        regexp -lineanchor -- $pat [string range $text $start end] result
    } else {
        regexp -start $start -lineanchor -- $pat $text result
    }
    
    Of course if we actually want '-indices' we then have to adjust the indices in the results appropriately by the offset we are using...   So a general workaround is kind of a pain!
    
    Conclusion: perhaps this should be an RFE for a more complete implementation of -start (and -end).  An alternative fix would be for Tcl_RegexpObjCmd to check whether the character before the -start is a newline \r\n or not, and if it _is_, then don't turn off the ability of '^' to match the beginning of the string!
    
    I assume 'regsub' suffers from similar problems.
    
    
    
    The regexp -start doesn't do an implicit string range, it uses the
    facilities that HS provided for just such a feature.  The effect on
    '^' is documented, and due to limitations in the exposed interface. 
    -- 02/23/2000 hobbs
    
  4. foundin changed to: "obsolete: 8.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "43. Regexp"
  10. title changed to: "regexp -start, -lineanchor don't combine well"
  11. type changed to: "Bug"