Tools: Add kiwix::trim() helper and unit tests

This commit is contained in:
pippotadde committed 2025-12-28 20:31:51 +01:00
1 parent a10f0f287f
commit 3cd8554733
3 files changed
+24 -1

No files matched your search

+10 -1
View File
@@ -29,7 +29,8 @@
#include <unicode/uniset.h>
#include <unicode/ustring.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <regex>
@@ -450,3 +451,11 @@ std::string kiwix::getSlugifiedFileName(const std::string& filename)
#endif
return std::regex_replace(filename, reservedCharsReg, "_");
}
std::string kiwix::trim(const std::string& s)
{
auto is_space = [](unsigned char c) { return std::isspace(c); };
auto start = std::find_if_not(s.begin(), s.end(), is_space);
auto end = std::find_if_not(s.rbegin(), s.rend(), is_space).base();
return (start < end) ? std::string(start, end) : std::string();
}