diff options
author | Justin Maggard <jmaggard@users.sourceforce.net> | 2011-11-19 12:59:32 +0400 |
---|---|---|
committer | Justin Maggard <jmaggard@users.sourceforce.net> | 2011-11-19 12:59:32 +0400 |
commit | e67e419bee1aa215214f5eb184d12eff231ea796 (patch) | |
tree | d319d1ea5e716b38151d7274bf8b9dac37ee3222 | |
parent | 6c503a93792d259b97b583d502e8bd1fb6bec61b (diff) |
* Improve trimming of quotation marks.
-rw-r--r-- | utils.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -69,16 +69,32 @@ ends_with(const char * haystack, const char * needle) char * trim(char *str) { - if (!str) - return(NULL); - int i; - for (i=0; i <= strlen(str) && (isspace(str[i]) || str[i] == '"'); i++) { + int i; + int len; + + 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--; } - for (i=(strlen(str)-1); i >= 0 && (isspace(str[i]) || str[i] == '"'); i--) { - str[i] = '\0'; - } - return str; + + if (str[0] == '"' && str[len-1] == '"') + { + str[0] = '\0'; + str[len-1] = '\0'; + str++; + } + + return str; } /* Find the first occurrence of p in s, where s is terminated by t */ |