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: Best Parsing Practices To Follow
Topic Summary:
Created On: 6-Jun-2008 20:16
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.
 6-Jun-2008 20:16
User is offline View Users Profile Print this message


Pete Kowalski

Posts: 301
Joined: 7-Feb-2003

I took one of my old PERL programmers that parses a string of integers from a list of comma separated list of integers. When I attempted to convert this code into DXL I am running into some problems.

Here is some sample code I put together:


string x = "342,525,562662,6266,66223"
Regexp magic = regexp "^[0-9]*+(,[0-9]+)+$"
if (magic x)
{
print x[match 0] "\n"
}


Running this code (in DOORS 7.1) generates this error message.


-R-E- DXL: <Line:4> incorrect regular expression (re_search)
-I- DXL: execution halted


I'm not that concern about the error message at the moment but in general, should I be using strictly Buffers over Regular Expressions when parsing data? I once read somewhere that Regular Expressions are another memory leak.

For the example I have given the variable x has 6 different numbers. Is there a DXL command that will parse the complete string or Buffer value when you don't know beforehand the amount of items that the string or Buffer contains?

Thanks.

-------------------------
pete.kowalski(at)motorola.com
Report this to a Moderator Report this to a Moderator
 6-Jun-2008 20:26
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

I personally don't like regular expressions, probably 'cause I don't use them all that much. Here's what I do which prints the following:

342
525
562662
6266
66223

-------------------------
Scott Boisvert
Engineering Tools Administrator
L-3 Communications - Avionics Systems
scott.boisvert@l-3com.com

Edited: 6-Jun-2008 at 20:28 by Scott Boisvert
Report this to a Moderator Report this to a Moderator
 6-Jun-2008 21:24
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Yes, regular expressions are always very cryptic. Not to metion, each language implements them slightly different.

Basically, you don't need the plusses "+", and you need a way to loop through all the matches. The code below will print out each value.

Edit: You could make this function more useful by passing it the string. See cbTest2 below. Now you can have something like:

string x1 = "123,456,789,1011,1213"
string x2 = "1415,1617,1819,2021"
cbTest2(x1)
cbTest2(x2)

Edited: 6-Jun-2008 at 21:33 by David Jakad
Report this to a Moderator Report this to a Moderator
 7-Jun-2008 03:30
User is offline View Users Profile Print this message


Pete Kowalski

Posts: 301
Joined: 7-Feb-2003

Scott,

Thanks for your clean and easy to follow code. Never knew it was this easy. A million of thanks

-------------------------
pete.kowalski(at)motorola.com
Report this to a Moderator Report this to a Moderator
 7-Jun-2008 03:35
User is offline View Users Profile Print this message


Pete Kowalski

Posts: 301
Joined: 7-Feb-2003

David,

I used PERL extensively for years so I have learned to master the art of writing and understanding cryptic regular expressions. I learned recently that now there are interactive tools out there that makes this less of a burden on the end-user but personally I still enjoy just using notepad to write and debug my expressions.

I am taking time to look at your code. Thanks for the sample. It seems to me intially that you will know beforehand how many numbers are in "x1" or "x2" before you are able parse each number out. Wait, nevermind. I just ran the code and see how it works now. It's quite useful. Thanks for the education lesson.

-------------------------
pete.kowalski(at)motorola.com
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 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 1 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.