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"><?xml version="1.0"
encoding="utf-
16"?>
<CurrentWeather>
<Location>Cairo Airport, Egypt (HECA) 30-08N 031-24E
74M</Location>
;
<Time>Aug 17, 2013 - 12:00 PM EDT / 2013.08.17 1600 UTC</Time>
<Wind> from the NNW (340 degrees) at 13 MPH (11 KT):0</Wind>
<Visibility> greater than 7 mile(s):0</Visibility>
<Temperature> 91 F (33 C)</Temperature>
<DewPoint> 69 F (21 C)</DewPoint>
<RelativeHumidity> 49%</RelativeHumidity>
<Pressure> 29.74 in. Hg (1007 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather></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"><?xml version="1.0"
encoding="utf-
16"?>
<CurrentWeather>
<Location>Cairo Airport, Egypt (HECA) 30-08N 031-24E
74M</Location>
;
<Time>Aug 17, 2013 - 12:00 PM EDT / 2013.08.17 1600 UTC</Time>
<Wind> from the NNW (340 degrees) at 13 MPH (11 KT):0</Wind>
<Visibility> greater than 7 mile(s):0</Visibility>
<Temperature> 91 F (33 C)</Temperature>
<DewPoint> 69 F (21 C)</DewPoint>
<RelativeHumidity> 49%</RelativeHumidity>
<Pressure> 29.74 in. Hg (1007 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather></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