66f0203f3aa1b55db4179d8bd08aecdf72a0ac1d
tdreszer
  Wed Mar 23 14:51:55 2011 -0700
Added respect for quotes in a couple of places.
diff --git src/lib/common.c src/lib/common.c
index fede24b..9ba7c4d 100644
--- src/lib/common.c
+++ src/lib/common.c
@@ -739,37 +739,45 @@
     e = strchr(s, delimiter);
     if (e == NULL)
 	el = slNameNew(s);
     else
 	{
         el = slNameNewN(s, e-s);
 	e += 1;
 	}
     slAddHead(&list, el);
     s = e;
     }
 slReverse(&list);
 return list;
 }
 
-struct slName *slNameListOfUniqueWords(char *text)
+struct slName *slNameListOfUniqueWords(char *text,boolean respectQuotes)
 // Return list of unique words found by parsing string delimited by whitespace.
+// If respectQuotes then ["Lucy and Ricky" 'Fred and Ethyl'] are 2 words
 {
 struct slName *list = NULL;
 char *word = NULL;
-while ((word = nextWord(&text)) != NULL)
+while (text != NULL)
+    {
+    if (respectQuotes)
+        word = nextWordRespectingQuotes(&text);
+    else
+        word = nextWord(&text);
+    if (word)
     slNameStore(&list, word);
+    }
 
 slReverse(&list);
 return list;
 }
 
 struct slName *slNameListFromStringArray(char *stringArray[], int arraySize)
 /* Return list of slNames from an array of strings of length arraySize.
  * If a string in the array is NULL, the array will be treated as
  * NULL-terminated (shorter than arraySize). */
 {
 char *s;
 struct slName *list = NULL, *el;
 int i;
 if (stringArray == NULL)
     return NULL;
@@ -1967,30 +1975,59 @@
  * word. */
 {
 char *s = *pLine, *e;
 if (s == NULL || s[0] == 0)
     return NULL;
 s = skipLeadingSpaces(s);
 if (s[0] == 0)
     return NULL;
 e = skipToSpaces(s);
 if (e != NULL)
     *e++ = 0;
 *pLine = e;
 return s;
 }
 
+char *nextWordRespectingQuotes(char **pLine)
+// return next word but respects single or double quotes surrounding sets of words.
+{
+char *s = *pLine, *e;
+if (s == NULL || s[0] == 0)
+    return NULL;
+s = skipLeadingSpaces(s);
+if (s[0] == 0)
+    return NULL;
+if (s[0] == '"')
+    {
+    e = skipBeyondDelimit(s+1,'"');
+    if (e != NULL && !isspace(e[0]))
+        e = skipToSpaces(s);
+    }
+else if (s[0] == '\'')
+    {
+    e = skipBeyondDelimit(s+1,'\'');
+    if (e != NULL && !isspace(e[0]))
+        e = skipToSpaces(s);
+    }
+else
+    e = skipToSpaces(s);
+if (e != NULL)
+    *e++ = 0;
+*pLine = e;
+return s;
+}
+
 char *nextTabWord(char **pLine)
 /* Return next tab-separated word. */
 {
 char *s = *pLine;
 char *e;
 if (s == NULL || *s == '\n' || *s == 0)
     {
     *pLine = NULL;
     return NULL;
     }
 e = strchr(s, '\t');
 if (e == NULL)
     {
     e = strchr(s, '\n');
     if (e != NULL)