Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/azatoth/minidlna.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Maggard <jmaggard@users.sourceforce.net>2011-11-19 12:59:32 +0400
committerJustin Maggard <jmaggard@users.sourceforce.net>2011-11-19 12:59:32 +0400
commite67e419bee1aa215214f5eb184d12eff231ea796 (patch)
treed319d1ea5e716b38151d7274bf8b9dac37ee3222
parent6c503a93792d259b97b583d502e8bd1fb6bec61b (diff)
* Improve trimming of quotation marks.
-rw-r--r--utils.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/utils.c b/utils.c
index 4156e6e..3c684d5 100644
--- a/utils.c
+++ b/utils.c
@@ -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 */