PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ option_list_parse()

void option_list_parse ( char *  input,
char **  olist 
)

option_list is a null-terminated list of strings, where every odd string is a key and every even string is a value.

To avoid lots of memory allocations, we use the input string as the backing store and fill in the olist with pointers to the start of the key and value strings, with keys in the even slots and values in the odd slots. The input needs to be writeable because we write a '\0' into the string at the break between token separators.

// array of char* char olist[OPTION_LIST_SIZE]; // zero out all the pointers so our list ends up null-terminated memset(olist, 0, sizeof(olist)); char input[OPTION_LIST_SIZE]; strcpy(input, "key1=value1 key2=value2"); // writeable option_list_parse(input, olist); char key = "key2"; const char* value = option_list_search(olist, key); printf("value of '%s' is '%s'\n", key, value);

Definition at line 86 of file optionlist.c.

87 {
88  const char *toksep = " ";
89  const char kvsep = '=';
90  char *key, *val;
91  if (!input) return;
92  size_t i = 0, sz;
93 
94  /* strtok nulls out the space between each token */
95  for (key = strtok(input, toksep); key; key = strtok(NULL, toksep)) {
96  if (i >= OPTION_LIST_SIZE) return;
97  olist[i] = key;
98  i += 2;
99  }
100 
101  sz = i;
102  /* keys are every second entry in the olist */
103  for (i = 0; i < sz; i += 2) {
104  if (i >= OPTION_LIST_SIZE) return;
105  key = olist[i];
106  /* find the key/value separator */
107  val = strchr(key, kvsep);
108  if (!val) {
109  lwerror("Option string entry '%s' lacks separator '%c'", key, kvsep);
110  }
111  /* null out the separator */
112  *val = '\0';
113  /* point value entry to just after separator */
114  olist[i+1] = ++val;
115  /* all keys forced to lower case */
117  }
118 }
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static void option_list_string_to_lower(char *key)
Definition: optionlist.c:32
#define OPTION_LIST_SIZE
Definition: optionlist.h:31

References lwerror(), OPTION_LIST_SIZE, and option_list_string_to_lower().

Referenced by lwgeom_make_valid_params(), rt_pg_vsi_check_options(), rt_util_gdal_open(), and test_optionlist().

Here is the call graph for this function:
Here is the caller graph for this function: