Archived
1
Fork 0
This repository has been archived on 2025-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
libxiv/include/string_utils.h

34 lines
874 B
C
Raw Normal View History

2022-03-15 15:33:57 -04:00
#pragma once
#include <algorithm>
std::vector<std::string> tokenize(const std::string_view string, const std::string_view& delimiters) {
std::vector<std::string> tokens;
const size_t length = string.length();
size_t lastPos = 0;
while(lastPos < length + 1) {
size_t pos = string.find_first_of(delimiters, lastPos);
if(pos == std::string_view::npos)
pos = length;
if(pos != lastPos)
tokens.emplace_back(string.data() + lastPos, pos - lastPos);
lastPos = pos + 1;
}
return tokens;
}
bool stringContains(const std::string_view a, const std::string_view b) {
return a.find(b) != std::string::npos;
}
std::string toLowercase(std::string str) {
std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c){ return std::tolower(c); });
return str;
}