Saturday, 17 August 2013

boost::regex_replace does nothing

boost::regex_replace does nothing

I am trying to use boost::regex_replace to replace HTML entities. I looked
at this question about how to use regex_replace and I am doing what the
answer does but with iterators. As far as I can tell from the boost regex
examples , this should be correct.
Here is the regex definition:
const boost::regex HTML_ENTITIY_REGEX("(&) | (") | (<) |
(>) | (')", boost::regex::optimize);
Here is the format string definition:
const std::string HTML_ENTITIY_FMT("(?1&)(?2\")(?3<)(?4>)(?5')");
Here is the function that calls boost::regex_replace:
template <class MutableBidirItr>
void decode_html_entities(MutableBidirItr begin, MutableBidirItr end)
{
boost::regex_replace(std::ostream_iterator<char>(std::cout), begin,
end, HTML_ENTITIY_REGEX,
HTML_ENTITIY_FMT, boost::match_default |
boost::format_all);
}
begin and end params are std::array::begin and std::array::begin + offset
where offset is less than or equal std::distance(begin, end)
The original text is:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 751
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 17 Aug 2013 16:30:14 GMT
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">&lt;?xml version="1.0"
encoding="utf-
16"?&gt;
&lt;CurrentWeather&gt;
&lt;Location&gt;Cairo Airport, Egypt (HECA) 30-08N 031-24E
74M&lt;/Location&gt
;
&lt;Time&gt;Aug 17, 2013 - 12:00 PM EDT / 2013.08.17 1600 UTC&lt;/Time&gt;
&lt;Wind&gt; from the NNW (340 degrees) at 13 MPH (11 KT):0&lt;/Wind&gt;
&lt;Visibility&gt; greater than 7 mile(s):0&lt;/Visibility&gt;
&lt;Temperature&gt; 91 F (33 C)&lt;/Temperature&gt;
&lt;DewPoint&gt; 69 F (21 C)&lt;/DewPoint&gt;
&lt;RelativeHumidity&gt; 49%&lt;/RelativeHumidity&gt;
&lt;Pressure&gt; 29.74 in. Hg (1007 hPa)&lt;/Pressure&gt;
&lt;Status&gt;Success&lt;/Status&gt;
&lt;/CurrentWeather&gt;</string>
Output from boost::regex_replace:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 751
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 17 Aug 2013 16:30:14 GMT
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">&lt;?xml version="1.0"
encoding="utf-
16"?&gt;
&lt;CurrentWeather&gt;
&lt;Location&gt;Cairo Airport, Egypt (HECA) 30-08N 031-24E
74M&lt;/Location&gt
;
&lt;Time&gt;Aug 17, 2013 - 12:00 PM EDT / 2013.08.17 1600 UTC&lt;/Time&gt;
&lt;Wind&gt; from the NNW (340 degrees) at 13 MPH (11 KT):0&lt;/Wind&gt;
&lt;Visibility&gt; greater than 7 mile(s):0&lt;/Visibility&gt;
&lt;Temperature&gt; 91 F (33 C)&lt;/Temperature&gt;
&lt;DewPoint&gt; 69 F (21 C)&lt;/DewPoint&gt;
&lt;RelativeHumidity&gt; 49%&lt;/RelativeHumidity&gt;
&lt;Pressure&gt; 29.74 in. Hg (1007 hPa)&lt;/Pressure&gt;
&lt;Status&gt;Success&lt;/Status&gt;
&lt;/CurrentWeather&gt;</string>
I feel like its a problem with the fmt string, but as far as I can tell it
is correct.
What is the proper way of using boost::regex and boost::regex_replace ?
What am I doing wrong here ? Also is it correct that by default
boost::regex uses ECMAscript and the format string uses Boost-Extended
Format String Syntax ?

No comments:

Post a Comment