unquote.c (617B)
1 /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "util.h" 5 6 int 7 unquote(char *buf, char *toks[], int ntoks) { 8 char *s, *t; 9 bool inquote; 10 int n; 11 12 n = 0; 13 s = buf; 14 while(*s && n < ntoks) { 15 while(*s && utfrune(" \t\r\n", *s)) 16 s++; 17 inquote = false; 18 toks[n] = s; 19 t = s; 20 while(*s && (inquote || !utfrune(" \t\r\n", *s))) { 21 if(*s == '\'') { 22 if(inquote && s[1] == '\'') 23 *t++ = *s++; 24 else 25 inquote = !inquote; 26 } 27 else 28 *t++ = *s; 29 s++; 30 } 31 if(*s) 32 s++; 33 *t = '\0'; 34 if(s != toks[n]) 35 n++; 36 } 37 return n; 38 }