Change find_html_comments() API to return the results
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 22 Mar 2017 10:10:47 +0000 (11:10 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 22 Mar 2017 10:10:47 +0000 (11:10 +0100)
src/stringfunc.cpp
src/stringfunc.hxx
test/stringfunc.cpp

index 63424bc..043dda7 100644 (file)
@@ -895,8 +895,7 @@ string html_entities_to_console(std::string str)
 // 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);
 }
 
@@ -904,13 +903,15 @@ void remove_html_comments(string &str)
 // 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
 
@@ -951,6 +952,8 @@ void find_html_comments(const std::string &str, vector<CommentZone> &comments)
         comments.push_back(CommentZone(starts.back(), string::npos));
         starts.pop_back();
     }
+
+    return comments;
 }
 
 // remove all html comments foundby find_html_comments
index 5d3455c..2fec469 100644 (file)
@@ -300,7 +300,7 @@ std::string html_entities(std::string str);
 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);
 
index bec8782..e6554fe 100644 (file)
@@ -746,8 +746,7 @@ BOOST_AUTO_TEST_CASE(find_html_comments_test)
     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());