project-euler/common/strings.hpp
erick-alcachofa 185fcd058b
Initial big int implementation
Signed-off-by: erick-alcachofa <erick@artichoke.dev>
2025-09-07 00:14:38 -06:00

45 lines
869 B
C++

#pragma once
#include <cctype>
#include <functional>
#include <string_view>
static inline bool isSpace(char ch) {
return std::isspace(ch);
}
static std::string_view ltrim(std::string_view str,
std::function<bool(char)> filter = isSpace) {
auto it = str.begin();
while (it != str.end()) {
if (!filter(*it)) {
break;
}
++it;
}
return {it, str.end()};
}
static std::string_view rtrim(std::string_view str,
std::function<bool(char)> filter = isSpace) {
auto it = str.rbegin();
while (it != str.rend()) {
if (!filter(*it)) {
break;
}
++it;
}
return {str.begin(), it.base()};
}
static std::string_view trim(std::string_view str,
std::function<bool(char)> filter = isSpace) {
return ltrim(rtrim(str, filter), filter);
}