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: HELP! Need ReqExpr function
Topic Summary:
Created On: 4-Aug-2004 15:08
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.
Answer This question was answered by Antonio Norkus, on Wednesday, August 4, 2004 10:40 PM

Answer:
Hi Louie,

here's one. I've done a little testing and it seems to be OK. Let me know if you find anything that breaks it.

Cheers,
Antonio.
 4-Aug-2004 15:08
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Anybody write the attached function for me?

Thanks. - Louie
Report this to a Moderator Report this to a Moderator
 4-Aug-2004 15:25
User is offline View Users Profile Print this message


Antonio Norkus

Posts: 109
Joined: 28-Jun-2003

Answer Answer
Hi Louie,

here's one. I've done a little testing and it seems to be OK. Let me know if you find anything that breaks it.

Cheers,
Antonio.
Report this to a Moderator Report this to a Moderator
 4-Aug-2004 15:36
User is offline View Users Profile Print this message


Antonio Norkus

Posts: 109
Joined: 28-Jun-2003

Oh...use the following version if "WSTR-0" or "WSTR-01" etc. is illegal.
Report this to a Moderator Report this to a Moderator
 4-Aug-2004 22:57
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Sorry, but forgot to point out that the instring would START with the format, but may contain additional characters. Your function works for "WSTR_1234" but not for "WSTR_1234 xxxx". I notice we can overflow with a huge number DoIt("WSTR_12345678901234567890") and get "1" for the result.

I think the RegExpr needs a "and zero or more random characters" at the end. What's that look like?

- Louie
Report this to a Moderator Report this to a Moderator
 5-Aug-2004 09:26
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

Louie,

You really are going to have to get your head around regular expressions...

To do the extra bit you want, change:

Regexp wStr = regexp "(^WSTR[ _-])([0-9]+$)"

into:

Regexp wStr = regexp "(^WSTR[ _-])([0-9]+)([^0-9]|$)"

The '^' as the first character in square brackets [] negates the content. So [0-9] matches any digit, and [^0-9] matches anything except a digit. The following '+' means 'one or more' (a '*' means zero or more). If the '^' is at the start of the expression, it matches the start of the string, and the '$' at the end matches the end of the string. Surrounding lumps of the expression with parentheses makes them available to the 'match' perm after the expression has been applied. The parentheses also allow you to select alternatives, separated by '|' -- the new bit means 'match anything that is either not a digit or is the end of the string'. So in your expression, you use match 0 to get the whole match, match 1 to get the WSTR plus trailing character, match 2 to get the string of digits, and match 3 to get the character after the digits, or the end of the string if there is nothing after the digits.
And that completes the crash course in regular expressions. For more information (and confusion ), RTFM.

Maybe you should check the length of the string of digits before you try to convert it to an int? That would give you a clue as to whether it's going to be too big. What you do after that is up to you, of course...

Paul.

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 5-Aug-2004 12:28
User is offline View Users Profile Print this message


Alan Wong

Posts: 11
Joined: 2-Aug-2004

Also note that that test you used is a 20 digit number... that is slightly past the 32 bit int limit even if it was unsigned (2^32 being 4294967296 which is a tad shorter than 20 digits). In this case, I would just keep the number as a string and use string comparisons, unless you need to do math with it... in which case it would be a bit harder.

And Paul, your solution did not take into account the space that is required after the number (since WSTR_1324xxxx isn't supposed to work, but WSTR_1234 xxxx is). A slight modification would fix this:

Regexp wStr = regexp "(^WSTR[ _-])([0-9]+)( [^0-9]+|$)"

However this is a possibility that number may occur in the text string after that in which case I would use

Regexp wStr = regexp "(^WSTR[ _-])([0-9]+)( [\001-\177]+|$)"

Which would match any character between 001 and 177 ascii octal (why does DXL use octal?). Note this will also force "WSTR_1234 " to fail (just change the + to * if you want to keep it)

Edited: 5-Aug-2004 at 13:44 by Alan Wong
Report this to a Moderator Report this to a Moderator
 5-Aug-2004 15:24
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

That seemed to do it, thanks.

"You really are going to have to get your head around regular expressions... " Yup. But its one of those brain-dead quirks; I just don't get it. And I have RTFM (or RTBM for the Britts or RTDarnM for the Baptists), where "F" and "B" are the key words. But I do know how to pronounce "Worcestershire Sauce" and once beat the world record in elbow coin snatching. And while I cannot spell regular words nor remember people's names, I can spell their last names more often than most folks. Don't know why, but that's the way it is.

Limitations are not so bad if you acknowlege them.

Besides, I answer a lot of folks questions here and a lot of folks are eager to answer mine. And since I know you guys can do this there is no particular reason for me beat my head against the wall trying to figure it out.

- Louie
Report this to a Moderator Report this to a Moderator
 5-Aug-2004 20:25
User is offline View Users Profile Print this message


Alan Wong

Posts: 11
Joined: 2-Aug-2004

Regular expressions are pretty vital to know for many reasons... mainly that computer science uses them so much, and it would benefit any coder to know it. Since dxl regex is rather lacking (doesn't have ?, and there is only * and + and not variable repetition) you should try another language to play with regex. Perl would be a place to start, or if you are more comfortable with c you can try the perl regex for c library.

For any text manipulation, regex is necessary (since who really wants to use c style string functions and if ladders?).
Report this to a Moderator Report this to a Moderator
 6-Aug-2004 16:04
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

That may explain my dozens of string manipulation functions that I've written for my own use: fIsSubString, ifIsPrefix, fIsSuffix, fStripPrefix, fGetBaseName, fGetPathName, fIsInFolder, fReplaceChar, fReplaceString, yaddy yaddy. But ReqExpr just seems to be one of those black holes in my head.

I cannot figure out when to wear a coat and when not to, and cannot get a grip on ReqExp. But I can find Waldo in less than a minute and may be the paper-maze champion of the world. Or not.

- Louie
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 0 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 0 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.