PostGIS  2.1.10dev-r@@SVN_REVISION@@
static char * rtpg_strreplace ( const char *  str,
const char *  oldstr,
const char *  newstr,
int *  count 
)
static

Definition at line 685 of file rt_pg.c.

References result.

Referenced by RASTER_colorMap(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_nMapAlgebraExpr(), and rtpg_removespaces().

689  {
690  const char *tmp = str;
691  char *result;
692  int found = 0;
693  int length, reslen;
694  int oldlen = strlen(oldstr);
695  int newlen = strlen(newstr);
696  int limit = (count != NULL && *count > 0) ? *count : -1;
697 
698  tmp = str;
699  while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
700  found++, tmp += oldlen;
701 
702  length = strlen(str) + found * (newlen - oldlen);
703  if ((result = (char *) palloc(length + 1)) == NULL) {
704  fprintf(stderr, "Not enough memory\n");
705  found = -1;
706  }
707  else {
708  tmp = str;
709  limit = found; /* Countdown */
710  reslen = 0; /* length of current result */
711 
712  /* Replace each old string found with new string */
713  while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
714  length = (tmp - str); /* Number of chars to keep intouched */
715  strncpy(result + reslen, str, length); /* Original part keeped */
716  strcpy(result + (reslen += length), newstr); /* Insert new string */
717 
718  reslen += newlen;
719  tmp += oldlen;
720  str = tmp;
721  }
722  strcpy(result + reslen, str); /* Copies last part and ending null char */
723  }
724 
725  if (count != NULL) *count = found;
726  return result;
727 }
char ** result
Definition: liblwgeom.h:218
int count
Definition: genraster.py:57

Here is the caller graph for this function: