mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-04-19 01:32:58 +02:00
add trim
This commit is contained in:
parent
0408f771b7
commit
8f44e09f32
@ -1,9 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
namespace MM::std_utils {
|
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/
|
// 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) {
|
inline std::vector<std::string_view> split(std::string_view str, const char* delims) {
|
||||||
std::vector<std::string_view> ret;
|
std::vector<std::string_view> ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user