changed to use ctype.h functions
This commit is contained in:
parent
f399807d54
commit
d6142085f7
@ -445,8 +445,8 @@ char* strsrep(char* str, const char* search, const char* replace) {
|
|||||||
char* strtrim(char* p) {
|
char* strtrim(char* p) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i=strlen(p)-1; (i >= 0) and ('!' > p[i]); i--) {}
|
for(i = strlen(p) - 1; (i >= 0) and (isspace(p[i]) or iscntrl(p[i])); i--) {}
|
||||||
p[i+1] = NUL;
|
p[i + 1] = NUL;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,8 +455,13 @@ std::string& strtrim(std::string& p) {
|
|||||||
|
|
||||||
if(not p.empty()) {
|
if(not p.empty()) {
|
||||||
std::string::iterator trail = p.end();
|
std::string::iterator trail = p.end();
|
||||||
while(trail != p.begin() and *(--trail) < '!') {}
|
while(trail != p.begin()) {
|
||||||
if(*trail > ' ') trail++;
|
--trail;
|
||||||
|
if(not isspace(*trail) and not iscntrl(*trail)) {
|
||||||
|
++trail;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
p.erase(trail, p.end());
|
p.erase(trail, p.end());
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
@ -472,7 +477,7 @@ char* strltrim(char* str) {
|
|||||||
char* q;
|
char* q;
|
||||||
|
|
||||||
p = q = str;
|
p = q = str;
|
||||||
while(*p and isspace(*p))
|
while(*p and (isspace(*p) or iscntrl(*p)))
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
if(p != q) {
|
if(p != q) {
|
||||||
|
Reference in New Issue
Block a user