mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-05 03:33:27 +01:00
add trim
This commit is contained in:
parent
0408f771b7
commit
8f44e09f32
@ -1,9 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <cctype>
|
||||
|
||||
namespace MM::std_utils {
|
||||
|
||||
inline std::string_view trim_prefix(std::string_view sv) {
|
||||
while (!sv.empty() && std::isspace(sv.front())) {
|
||||
sv.remove_prefix(1);
|
||||
}
|
||||
|
||||
return sv;
|
||||
}
|
||||
|
||||
inline std::string_view trim_suffix(std::string_view sv) {
|
||||
while (!sv.empty() && std::isspace(sv.back())) {
|
||||
sv.remove_suffix(1);
|
||||
}
|
||||
|
||||
return sv;
|
||||
}
|
||||
|
||||
inline std::string_view trim(std::string_view sv) {
|
||||
return trim_suffix(trim_prefix(sv));
|
||||
}
|
||||
|
||||
// src : https://marcoarena.wordpress.com/2017/01/03/string_view-odi-et-amo/
|
||||
inline std::vector<std::string_view> split(std::string_view str, const char* delims) {
|
||||
std::vector<std::string_view> ret;
|
||||
|
Loading…
Reference in New Issue
Block a user