From 5563117a1be8fd55b1e4a43587c1d25bdfe4561a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 7 Sep 2022 16:59:50 -0600 Subject: [PATCH] add remove_extra_whitespace() to libpbd --- libs/pbd/pbd/whitespace.h | 2 +- libs/pbd/whitespace.cc | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/pbd/pbd/whitespace.h b/libs/pbd/pbd/whitespace.h index f38c0d5409..064d73451e 100644 --- a/libs/pbd/pbd/whitespace.h +++ b/libs/pbd/pbd/whitespace.h @@ -29,7 +29,7 @@ namespace PBD { // returns the empty string if the entire string is whitespace // so check length after calling. LIBPBD_API extern void strip_whitespace_edges (std::string& str); - + LIBPBD_API extern void remove_extra_whitespace (std::string const & in, std::string out); } // namespace PBD #endif // __pbd_whitespace_h__ diff --git a/libs/pbd/whitespace.cc b/libs/pbd/whitespace.cc index 28be5fc442..631fad837f 100644 --- a/libs/pbd/whitespace.cc +++ b/libs/pbd/whitespace.cc @@ -16,6 +16,8 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include #include "pbd/whitespace.h" @@ -77,4 +79,11 @@ strip_whitespace_edges (string& str) } } +void +remove_extra_whitespace (string const & input, string & output) +{ + std::unique_copy (input.begin(), input.end(), std::back_insert_iterator(output), [](char a,char b){ return isspace(a) && isspace(b);}); +} + + } // namespace PBD