Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Any Boost Experts out there for Boost.Regex?

Reply
Thread Tools

Any Boost Experts out there for Boost.Regex?

 
 
Richard Latter
Guest
Posts: n/a
 
      05-17-2004
Hello All,

I am a newbie to the Boost library and I have a question about a simple
function. All I would like to do is to create a simple function that can
test strings using regular expressions. I've written this function which
appears to work on the first pass and then fails on the second with the
following message.

Unhandle exeption in Credit Card Example.exe (KERNEL32.DLL) 0x(Some
address): Microsoft C++ Exception.

My function is as follows....

bool TestStr (std::string szExpr, std::string szSearch)
{
bool bResult=false;

boost::regex *cExpr = new boost::regex(szExpr);

bResult = boost::regex_match(szSearch, *cExpr);

delete (cExpr);

return bResult;
}

Questions!

1. Why is this failing all the time?

2. Why in the example given in the RTL is a constant? This implies that
the the regex object cannot be changed at run-time, which is the opposite to
what I would like to do.

3. Are there any examples or tutorials outside of the main library tutorial
I could look at? Are there any newsgroups on this?

4. Can anyone give an example of a simple POSIX calls for string matching?

Please forgive me as I'm a newbie to all of this. Any help would be
gratefully appreciated.

Regards,

Richard


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-17-2004

"Richard Latter" <(E-Mail Removed)> wrote in message
news:c89oqb$16i$1$(E-Mail Removed)...
> Hello All,
>
> I am a newbie to the Boost library and I have a question about a simple
> function. All I would like to do is to create a simple function that can
> test strings using regular expressions. I've written this function which
> appears to work on the first pass and then fails on the second with the
> following message.
>
> Unhandle exeption in Credit Card Example.exe (KERNEL32.DLL) 0x(Some
> address): Microsoft C++ Exception.
>
> My function is as follows....
>
> bool TestStr (std::string szExpr, std::string szSearch)
> {
> bool bResult=false;
>
> boost::regex *cExpr = new boost::regex(szExpr);
>
> bResult = boost::regex_match(szSearch, *cExpr);
>
> delete (cExpr);
>
> return bResult;
> }


Why are you allocating memory dynamically?

bool TestStr (std::string szExpr, std::string szSearch)
{
return boost::regex_match(szSearch, boost::regex(szExpr));
}

The above is simpler and likely to be more efficient. Also you should use
const references for your strings

bool TestStr (const std::string& szExpr, const std::string& szSearch)
{
return boost::regex_match(szSearch, boost::regex(szExpr));
}

Again this is a likely efficiency gain at no cost.

>
> Questions!
>
> 1. Why is this failing all the time?
>


Who knows? It could be a bug in your code, it could be a bug in
boost::regex, it could be a bug in your compiler, it could be a bug in your
implementation of the standard library. One thing is sure just because it
fails on the second pass though boost does not mean that the bug is in the
boost library. The best thing is to post a complete compilable program that
shows the crash. Then people will be able to try it with their compilers and
at least eliminate some of the possibilities.


> 2. Why in the example given in the RTL is a constant? This implies that
> the the regex object cannot be changed at run-time, which is the opposite

to
> what I would like to do.


I don't think it implies that at all. It imples that in that piece of code
the author did not want to change the regex object.

john


 
Reply With Quote
 
 
 
 
Julie
Guest
Posts: n/a
 
      05-17-2004
Richard Latter wrote:
[snip boost-related stuff]

Your question would be more topical and you would probably get better answers
on the Boost newsgroup:

news://news.gmane.org/gmane.comp.lib.boost.devel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any weblogic 8 experts out there? laredotornado@zipmail.com Java 3 09-26-2007 10:30 PM
Any EE experts out there? hermes Wireless Networking 20 12-01-2005 06:15 AM
HTTPS SSLeay problems - any experts out there? Ira Lee Perl 0 06-29-2004 10:16 PM
Any DOS Experts Out There?? Sens Fan Happy In Ohio Computer Support 11 05-03-2004 01:41 AM
Any HP experts out there? Denise Computer Support 14 01-27-2004 03:07 PM



Advertisments