34 lines
937 B
C++
34 lines
937 B
C++
#include "utils.hpp"
|
|
|
|
#include <string>
|
|
|
|
namespace {
|
|
constexpr char kSpace{' '};
|
|
} // namespace
|
|
|
|
auto trim_whitespaces(std::string_view text) noexcept -> std::string_view
|
|
{
|
|
auto leading_spaces = text.find_first_not_of(kSpace);
|
|
if (leading_spaces == std::string::npos) return {};
|
|
|
|
auto sub_view = text.substr(leading_spaces);
|
|
|
|
auto trailling_spaces = sub_view.find_last_not_of(kSpace);
|
|
if (trailling_spaces == std::string::npos) return sub_view;
|
|
|
|
return sub_view.substr(0, trailling_spaces + 1);
|
|
}
|
|
|
|
auto sanitize_text(std::string_view text) noexcept -> std::string_view
|
|
{
|
|
auto leading_spaces = text.find_first_not_of(kSpace);
|
|
if (leading_spaces == std::string::npos) return {};
|
|
|
|
auto sub_view = text.substr(leading_spaces);
|
|
|
|
auto trailling_spaces = sub_view.find_first_of(kSpace);
|
|
if (trailling_spaces == std::string::npos) return sub_view;
|
|
|
|
return sub_view.substr(0, trailling_spaces);
|
|
}
|