[Utils] Safer isstring
This commit is contained in:
parent
5cd08907a8
commit
0fb882ef3b
@ -88,17 +88,23 @@ namespace Utils
|
|||||||
return (haystack.size() >= needle.size() && !strncmp(needle.data(), haystack.data(), needle.size()));
|
return (haystack.size() >= needle.size() && !strncmp(needle.data(), haystack.data(), needle.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IsSpace(int c)
|
||||||
|
{
|
||||||
|
if (c < -1) return 0;
|
||||||
|
return _isspace_l(c, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// trim from start
|
// trim from start
|
||||||
std::string <rim(std::string &s)
|
std::string <rim(std::string &s)
|
||||||
{
|
{
|
||||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(IsSpace))));
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim from end
|
// trim from end
|
||||||
std::string &RTrim(std::string &s)
|
std::string &RTrim(std::string &s)
|
||||||
{
|
{
|
||||||
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(IsSpace))).base(), s.end());
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ namespace Utils
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IsSpace(int c);
|
||||||
std::string ToLower(std::string input);
|
std::string ToLower(std::string input);
|
||||||
std::string ToUpper(std::string input);
|
std::string ToUpper(std::string input);
|
||||||
bool EndsWith(std::string haystack, std::string needle);
|
bool EndsWith(std::string haystack, std::string needle);
|
||||||
|
Loading…
Reference in New Issue
Block a user