From 46dd132155647d371a68cc0af4b1aedbdbb43bfd Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 22 Mar 2017 11:10:47 +0100 Subject: [PATCH] Change find_html_comments() API to return the results --- src/stringfunc.cpp | 9 ++++++--- src/stringfunc.hxx | 2 +- test/stringfunc.cpp | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index 63424bc..043dda7 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -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 comments; - find_html_comments(str, comments); + vector 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 ""; static const string::size_type START_LEN = START.length(); static const string::size_type CLOSE_LEN = CLOSE.length(); + vector comments; + // in order to find nested comments, need either recursion or a stack vector starts; // stack of start tags @@ -951,6 +952,8 @@ void find_html_comments(const std::string &str, vector &comments) comments.push_back(CommentZone(starts.back(), string::npos)); starts.pop_back(); } + + return comments; } // remove all html comments foundby find_html_comments diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index 5d3455c..2fec469 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -300,7 +300,7 @@ std::string html_entities(std::string str); std::string html_entities_to_console(std::string str); typedef std::pair CommentZone; -void find_html_comments(const std::string &str, std::vector &result); +std::vector find_html_comments(const std::string &str); void remove_html_comments(std::string &str); void remove_html_comments(std::string &str, const std::vector &comments); diff --git a/test/stringfunc.cpp b/test/stringfunc.cpp index bec8782..e6554fe 100644 --- a/test/stringfunc.cpp +++ b/test/stringfunc.cpp @@ -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 result; - find_html_comments(text, result); + vector 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()); -- 1.7.1