![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: using [match n] with search(Rexexp re, buffer b, int start) Topic Summary: match, start and end are supposed to be relative to start, but match seems broken Created On: 19-Nov-2007 23:29 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
Hi All,
According to the DXL manual, one cause search a Buffer with a Regular Expression in one of two ways: concatenating a regexp with a buffer just as one would a string. Or use the search() function. Supposedly, match, end and start (regular expression functions) will return offsets relative to the start integer variable in seach(), and not the start Buffer. This seems to be true with start and end, but match seems to behave quite strangely. I was hoping someone can correct my code so that [match 1] will give me the proper values both times. My goal is to read a line from a text file which contains comma-separated values (CSV) into a Buffer. I then want to extract each CSV item from the string one at a time. I have a fucntion that does this if the line is in a string, but because it gets called thousands of times in a script I have, I need to reimplement it using buffers. In my original implementation, i set the passed line string to a local variable and then cut it down after pulling off each CSV item from the front. However, if i do this with a Buffer-based implementation, then it will chop my original Buffer down (they are passed by reference) unless I have some kind of temporary buffer. This function is in a library function file, so I can't easily make a global buffer and remember to delete it in my main script (or I'd prefer not to go that route). The preferred method would be to use the search() function, but as you can see from the attached code, the [match 1] regexp function doesn't work right. The code comments help to explain more. Any clues how to make [match n] work by returning the desired substring? Jason |
|
![]() |
|
![]() |
|
Hi,
I can't see the problem there: match n is defined as the start n:end n Range_ object. Thus, instead of printing print b [match 1] "\t" start(1) "\t" end(1) "\n" Try: print b [match 1] "\t" b[start 1] "\t" b[end 1] "\n" You will see that b[start 1] is the first character of b[match 1]. And no, AFAK there is no way to add an offset to a Range_ object, and neither can you get limits from a Range_ object. So you have to rebuild it, as you did with b[bufferIndex+start(1):bufferIndex+end(1)] ------------------------- E. Piallat CeBeNetwork |
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.