mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +00:00
45 lines
967 B
C++
45 lines
967 B
C++
|
/*
|
||
|
* Mirai. Copyright (C) 2024 Vyn
|
||
|
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||
|
*/
|
||
|
|
||
|
#include "utils.h"
|
||
|
|
||
|
void ltrim(std::string& s) {
|
||
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||
|
return !std::isspace(ch);
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
void rtrim(std::string& s) {
|
||
|
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||
|
return !std::isspace(ch);
|
||
|
}).base(), s.end());
|
||
|
}
|
||
|
|
||
|
void trim(std::string& s) {
|
||
|
rtrim(s);
|
||
|
ltrim(s);
|
||
|
}
|
||
|
|
||
|
std::string ltrim_copy(std::string s) {
|
||
|
ltrim(s);
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
std::string rtrim_copy(std::string s) {
|
||
|
rtrim(s);
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
std::string trim_copy(std::string s) {
|
||
|
trim(s);
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
bool isDate(const std::string& dateStr) {
|
||
|
std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}");
|
||
|
return std::regex_match(dateStr, regex);
|
||
|
}
|