mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 17:23:20 +00:00
first commit
This commit is contained in:
commit
3e7d8b4b70
43 changed files with 2681 additions and 0 deletions
44
src/core/utils.cpp
Normal file
44
src/core/utils.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue