mirror of
https://github.com/clangen/musikcube.git
synced 2025-04-15 20:42:33 +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
|
#endif
|
||||||
|
|
||||||
// given the #ifdef/#else above, the following is not required.
|
// 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__
|
#ifdef __OpenBSD__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/sysctl.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 Trim(const std::string& str) {
|
||||||
std::string s(str);
|
int start = 0;
|
||||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
if (!IsSpace(str[i])) {
|
||||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
break;
|
||||||
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
}
|
||||||
return s;
|
++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(
|
std::vector<std::string> Split(
|
||||||
|
@ -103,13 +103,30 @@ namespace str {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string trim(const std::string& str) {
|
static inline bool isSpace(const char c) {
|
||||||
std::string s(str);
|
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == '\f';
|
||||||
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::string trim(const std::string& str) {
|
||||||
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
int start = 0;
|
||||||
return s;
|
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(
|
static std::vector<std::string> split(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user