PostGIS  2.1.10dev-r@@SVN_REVISION@@
static char ** rtpg_strsplit ( const char *  str,
const char *  delimiter,
int *  n 
)
static

Definition at line 772 of file rt_pg.c.

Referenced by RASTER_colorMap(), RASTER_reclass(), and rtpg_assignHookGDALEnabledDrivers().

772  {
773  char *tmp = NULL;
774  char **rtn = NULL;
775  char *token = NULL;
776 
777  *n = 0;
778  if (!str)
779  return NULL;
780 
781  /* copy str to tmp as strtok will mangle the string */
782  tmp = palloc(sizeof(char) * (strlen(str) + 1));
783  if (NULL == tmp) {
784  fprintf(stderr, "Not enough memory\n");
785  return NULL;
786  }
787  strcpy(tmp, str);
788 
789  if (!strlen(tmp) || !delimiter || !strlen(delimiter)) {
790  *n = 1;
791  rtn = (char **) palloc(*n * sizeof(char *));
792  if (NULL == rtn) {
793  fprintf(stderr, "Not enough memory\n");
794  return NULL;
795  }
796  rtn[0] = (char *) palloc(sizeof(char) * (strlen(tmp) + 1));
797  if (NULL == rtn[0]) {
798  fprintf(stderr, "Not enough memory\n");
799  return NULL;
800  }
801  strcpy(rtn[0], tmp);
802  pfree(tmp);
803  return rtn;
804  }
805 
806  token = strtok(tmp, delimiter);
807  while (token != NULL) {
808  if (*n < 1) {
809  rtn = (char **) palloc(sizeof(char *));
810  }
811  else {
812  rtn = (char **) repalloc(rtn, (*n + 1) * sizeof(char *));
813  }
814  if (NULL == rtn) {
815  fprintf(stderr, "Not enough memory\n");
816  return NULL;
817  }
818 
819  rtn[*n] = NULL;
820  rtn[*n] = (char *) palloc(sizeof(char) * (strlen(token) + 1));
821  if (NULL == rtn[*n]) {
822  fprintf(stderr, "Not enough memory\n");
823  return NULL;
824  }
825 
826  strcpy(rtn[*n], token);
827  *n = *n + 1;
828 
829  token = strtok(NULL, delimiter);
830  }
831 
832  pfree(tmp);
833  return rtn;
834 }

Here is the caller graph for this function: