add remove_extra_whitespace() to libpbd

This commit is contained in:
Paul Davis 2022-09-07 16:59:50 -06:00
parent bd9fe31778
commit 5563117a1b
2 changed files with 10 additions and 1 deletions

View File

@ -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__

View File

@ -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 <algorithm>
#include <ctype.h>
#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<string>(output), [](char a,char b){ return isspace(a) && isspace(b);});
}
} // namespace PBD