* Improve trimming of quotation marks.
This commit is contained in:
parent
875f0e2351
commit
84d4a0f3f1
32
utils.c
32
utils.c
@ -69,16 +69,32 @@ ends_with(const char * haystack, const char * needle)
|
|||||||
char *
|
char *
|
||||||
trim(char *str)
|
trim(char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
int i;
|
||||||
return(NULL);
|
int len;
|
||||||
int i;
|
|
||||||
for (i=0; i <= strlen(str) && (isspace(str[i]) || str[i] == '"'); i++) {
|
if (!str)
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
|
len = strlen(str);
|
||||||
|
for (i=len-1; i >= 0 && isspace(str[i]); i--)
|
||||||
|
{
|
||||||
|
str[i] = '\0';
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
while (isspace(*str))
|
||||||
|
{
|
||||||
|
str++;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str[0] == '"' && str[len-1] == '"')
|
||||||
|
{
|
||||||
|
str[0] = '\0';
|
||||||
|
str[len-1] = '\0';
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
for (i=(strlen(str)-1); i >= 0 && (isspace(str[i]) || str[i] == '"'); i--) {
|
|
||||||
str[i] = '\0';
|
return str;
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the first occurrence of p in s, where s is terminated by t */
|
/* Find the first occurrence of p in s, where s is terminated by t */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user