Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 19-Nov-2007 23:29
User is offline View Users Profile Print this message


jason haury

Posts: 39
Joined: 20-Feb-2007

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
Report this to a Moderator Report this to a Moderator
 20-Nov-2007 07:45
User is offline View Users Profile Print this message


Eric Piallat

Posts: 33
Joined: 26-Jan-2004

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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.