feat: add challenge code
This commit is contained in:
commit
5634d1bb39
22 files changed
+925
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#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);
|
||||
}
|
||||
Reference in new issue
Block a user