// find_html_comments + remove_html_comments(str, comments)
void remove_html_comments(string &str)
{
- vector<CommentZone> comments;
- find_html_comments(str, comments);
+ vector<CommentZone> comments = find_html_comments(str);
remove_html_comments(str, comments);
}
// If there are invalid comments ("-->" before "<!--" or different number of closing and opening tags),
// then the unknown index of corresponding start/end tag will be represented by a string::npos
// Indices are from start of start tag until first index after closing tag
-void find_html_comments(const std::string &str, vector<CommentZone> &comments)
+vector<CommentZone> find_html_comments(const std::string &str)
{
static const string START = "<!--";
static const string CLOSE = "-->";
static const string::size_type START_LEN = START.length();
static const string::size_type CLOSE_LEN = CLOSE.length();
+ vector<CommentZone> comments;
+
// in order to find nested comments, need either recursion or a stack
vector<string::size_type> starts; // stack of start tags
comments.push_back(CommentZone(starts.back(), string::npos));
starts.pop_back();
}
+
+ return comments;
}
// remove all html comments foundby find_html_comments
std::string html_entities_to_console(std::string str);
typedef std::pair<std::string::size_type, std::string::size_type> CommentZone;
-void find_html_comments(const std::string &str, std::vector<CommentZone> &result);
+std::vector<CommentZone> find_html_comments(const std::string &str);
void remove_html_comments(std::string &str);
void remove_html_comments(std::string &str, const std::vector<CommentZone> &comments);
expect.push_back(CommentZone(48, 55));
expect.push_back(CommentZone(55, string::npos));
expect.push_back(CommentZone(62, 72));
- vector<CommentZone> result;
- find_html_comments(text, result);
+ vector<CommentZone> result = find_html_comments(text);
//BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), not working, requires ...
// expect.begin(), expect.end()); ... operator<<(CommentZone)
BOOST_CHECK_EQUAL(result.size(), expect.size());