Changeset d275eb2 for variable.c


Ignore:
Timestamp:
Jan 2, 2011, 3:31:58 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
2bc6ad35
Parents:
f640876
git-author:
David Benjamin <davidben@mit.edu> (12/15/10 13:18:34)
git-committer:
David Benjamin <davidben@mit.edu> (01/02/11 15:31:58)
Message:
Replace atokenize with glib's g_strsplit_set

Glib's had g_strsplit_set since forever, and it does exactly the same
thing as atokenize, modulo needing a pesky NULL check. We may as well
use it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • variable.c

    rbc14adc rd275eb2  
    952952  int nenums, val;
    953953  if (newval == NULL) return(0);
    954   enums = atokenize(v->validsettings, ",", &nenums);
    955   if (enums == NULL) return(0);
    956   atokenize_delete(enums, nenums);
     954  enums = g_strsplit_set(v->validsettings, ",", 0);
     955  nenums = g_strv_length(enums);
     956  g_strfreev(enums);
    957957  val = *(const int*)newval;
    958958  if (val < 0 || val >= nenums) {
     
    964964int owl_variable_enum_set_fromstring(owl_variable *v, const char *newval) {
    965965  char **enums;
    966   int nenums, i, val=-1;
     966  int i, val=-1;
    967967  if (newval == NULL) return(-1);
    968   enums = atokenize(v->validsettings, ",", &nenums);
    969   if (enums == NULL) return(-1);
    970   for (i=0; i<nenums; i++) {
     968  enums = g_strsplit_set(v->validsettings, ",", 0);
     969  for (i = 0; enums[i] != NULL; i++) {
    971970    if (0==strcmp(newval, enums[i])) {
    972971      val = i;
    973972    }
    974973  }
    975   atokenize_delete(enums, nenums);
     974  g_strfreev(enums);
    976975  if (val == -1) return(-1);
    977976  return (v->set_fn(v, &val));
     
    986985    return -1;
    987986  }
    988   enums = atokenize(v->validsettings, ",", &nenums);
     987  enums = g_strsplit_set(v->validsettings, ",", 0);
     988  nenums = g_strv_length(enums);
    989989  i = *(const int*)val;
    990990  if (i<0 || i>=nenums) {
    991991    snprintf(buf, bufsize, "<invalid:%d>",i);
    992     atokenize_delete(enums, nenums);
     992    g_strfreev(enums);
    993993    return(-1);
    994994  }
    995995  snprintf(buf, bufsize, "%s", enums[i]);
    996   atokenize_delete(enums, nenums);
     996  g_strfreev(enums);
    997997  return 0;
    998998}
Note: See TracChangeset for help on using the changeset viewer.