|
Boost Users : |
From: Dave DeLong (davedelong_at_[hidden])
Date: 2008-03-12 10:15:42
My platform is Mac OS X 10.5.2. I'm compiling and running via Xcode
3.0. Boost is version 1.34.1 (I installed it in the last two weeks).
It was compiled on this machine by running "sudo make install", which
installed it in /usr/local/include/boost. The library files are in /
usr/local/lib. In my project specification, I specify those paths in
my Library and Header search paths, and also add the linker option "-
lboost_regex".
The following code gets a EXC_BAD_ACCESS error and never executes the
catch blocks: (I realize that the pageSource doesn't actually have a
<script> tag; That's because I don't know if the pages I'll be
parsing will have one. However, the code still fails even if there is
a <script>TESTSCRIPT</script> tag in there.)
#include <iostream>
#include <boost/regex.hpp>
#include <string>
using namespace std;
int main (int argc, char * const argv[]) {
string * pageSource = new string("<html><head><title>Some title</
title></head><body>Hello, world!</body></html>");
try {
boost::regex tagRegex("(?:i)<script[^>]*>.*?</script[^>]*>");
string replaced = boost::regex_replace(*pageSource, tagRegex, " ",
boost::match_default);
delete pageSource;
pageSource = new string(replaced);
} catch (exception &e) {
cout << e.what() << endl;
} catch ( ... ) {
cout << "Unknown exception" << endl;
}
cout << *pageSource << endl;
delete pageSource;
return 0;
}
Any help would be greatly appreciated, as this project is due
tomorrow. =)
Thanks,
Dave
On 12 Mar, 2008, at 7:50 AM, John Maddock wrote:
> Dave DeLong wrote:
>>> Ah, you're right. That was one of my attempts to fix it (which you
>>> can guess didn't work).
>>>
>>> As for the inefficiency, this is my first stab at regex. =)
>>>
>>> Here's the complete function as it stands (or doesn't, since it
>>> still
>>> crashes):
>>>
>>> void Page::removeScriptTags() {
>>> boost::regex tagRegex("(?:i)<script[^>]*>.*?</script[^>]*>");
>>> string source(*pageSource);
>>> string replaced = boost::regex_replace(source, tagRegex, " ",
>>> boost::match_default);
>>> delete pageSource;
>>> pageSource = new string(replaced);
>>> }
>
> That looks fine as it stands, but unless you can reduce it to a
> complete
> test case that I can compile and run here it still doesn't help
> much. Also
> what compiler, platform and Boost version are you using? Also
> please check
> that there isn't some binary-compatibity issue going on: building
> your app
> with different options than Boost was built with, or linking to a
> library
> file that's from a different Boost version to the headers you're
> #including
> etc...
>
> John.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net