mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 17:23:20 +00:00
Add helper lib for strings and vectors
This commit is contained in:
parent
6ef9740db9
commit
2bb7fcfcc6
10 changed files with 168 additions and 123 deletions
|
@ -6,39 +6,9 @@
|
|||
|
||||
#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);
|
||||
namespace mirai {
|
||||
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