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

This commit is contained in:
pippotadde
2025-12-27 19:08:48 +01:00
parent a10f0f287f
commit 3cd8554733
3 changed files with 24 additions and 1 deletions

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();
}