ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/misc.C
(Generate patch)

Comparing rxvt-unicode/src/misc.C (file contents):
Revision 1.54 by root, Sat May 30 06:56:20 2009 UTC vs.
Revision 1.55 by sf-exg, Mon Jan 10 14:07:19 2011 UTC

263 263
264 return str; 264 return str;
265} 265}
266 266
267/* 267/*
268 * Split a comma-separated string into an array, stripping leading and 268 * Split a string into an array based on the given delimiter, stripping leading and
269 * trailing spaces from each entry. Empty strings are properly returned 269 * trailing spaces from each entry. Empty strings are properly returned
270 */ 270 */
271char ** 271char **
272rxvt_splitcommastring (const char *cs) NOTHROW 272rxvt_strsplit (char delim, const char *str) NOTHROW
273{ 273{
274 int l, n, p; 274 int l, n;
275 const char *s, *t; 275 char *s, *t;
276 char **ret; 276 char **ret;
277 277
278 if ((s = cs) == NULL) 278 s = strdup (str ? str : "");
279 s = "";
280 279
281 for (n = 1, t = s; *t; t++) 280 for (n = 1, t = s; *t; t++)
282 if (*t == ',') 281 if (*t == delim)
283 n++; 282 n++;
284 283
285 ret = (char **)malloc ((n + 1) * sizeof (char *)); 284 ret = (char **)malloc ((n + 1) * sizeof (char *));
286 ret[n] = NULL; 285 ret[n] = NULL;
287 286
288 for (l = 0, t = s; l < n; l++) 287 for (l = 0, t = s; l < n; l++)
289 { 288 {
290 for ( ; *t && *t != ','; t++) ; 289 for (; *t && *t != delim; t++)
291 p = t - s; 290 ;
292 ret[l] = (char *)malloc (p + 1); 291 *t = '\0';
293 memcpy (ret[l], s, p);
294 ret[l][p] = '\0'; 292 ret[l] = s;
295 rxvt_strtrim (ret[l]); 293 rxvt_strtrim (ret[l]);
296 s = ++t; 294 s = ++t;
297 } 295 }
298 296
299 return ret; 297 return ret;
300} 298}
301 299
302void
303rxvt_freecommastring (char **cs) NOTHROW
304{
305 for (int i = 0; cs[i]; ++i)
306 free (cs[i]);
307
308 free (cs);
309}
310
311void * 300void *
312rxvt_malloc (size_t size) 301rxvt_malloc (size_t size)
313{ 302{
314 void *p = malloc (size); 303 void *p = malloc (size);
315 304

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines