mirror of
https://github.com/clangen/musikcube.git
synced 2025-04-15 11:42:29 +00:00
isspace()
seems to cause problems on Windows in debug mode with
corrupted unicode characters; we don't need anything fancy, let's just do this ourselves.
This commit is contained in:
parent
39aff51dca
commit
e698f57f67
@ -57,7 +57,7 @@
|
||||
#endif
|
||||
|
||||
// given the #ifdef/#else above, the following is not required.
|
||||
// Nor it is the #if FreeBSD below.
|
||||
// Nor it is the #if FreeBSD below.
|
||||
#ifdef __OpenBSD__
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
@ -311,13 +311,30 @@ namespace musik { namespace core {
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool IsSpace(const char c) {
|
||||
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == '\f';
|
||||
}
|
||||
|
||||
std::string Trim(const std::string& str) {
|
||||
std::string s(str);
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
||||
return s;
|
||||
int start = 0;
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
if (!IsSpace(str[i])) {
|
||||
break;
|
||||
}
|
||||
++start;
|
||||
}
|
||||
int end = (int) str.length();
|
||||
for (size_t i = str.length() - 1; i >= 0; i--) {
|
||||
if (!IsSpace(str[i])) {
|
||||
break;
|
||||
}
|
||||
--end;
|
||||
}
|
||||
if (end > start) {
|
||||
std::string result = str.substr((size_t) start, (size_t) end - start);
|
||||
return result;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::vector<std::string> Split(
|
||||
|
@ -103,13 +103,30 @@ namespace str {
|
||||
return input;
|
||||
}
|
||||
|
||||
static inline std::string trim(const std::string& str) {
|
||||
std::string s(str);
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
||||
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
||||
return s;
|
||||
static inline bool isSpace(const char c) {
|
||||
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == '\f';
|
||||
}
|
||||
|
||||
std::string trim(const std::string& str) {
|
||||
int start = 0;
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
if (!isSpace(str[i])) {
|
||||
break;
|
||||
}
|
||||
++start;
|
||||
}
|
||||
int end = (int)str.length();
|
||||
for (size_t i = str.length() - 1; i >= 0; i--) {
|
||||
if (!isSpace(str[i])) {
|
||||
break;
|
||||
}
|
||||
--end;
|
||||
}
|
||||
if (end > start) {
|
||||
std::string result = str.substr((size_t)start, (size_t)end - start);
|
||||
return result;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(
|
||||
|
Loading…
x
Reference in New Issue
Block a user