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

Definition at line 142 of file raster2pgsql.c.

References _, result, rtalloc(), and rterror().

Referenced by add_overview_constraints(), add_raster_constraints(), and insert_records().

146  {
147  const char *tmp = str;
148  char *result;
149  int found = 0;
150  int length, reslen;
151  int oldlen = strlen(oldstr);
152  int newlen = strlen(newstr);
153  int limit = (count != NULL && *count > 0) ? *count : -1;
154 
155  tmp = str;
156  while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
157  found++, tmp += oldlen;
158 
159  length = strlen(str) + found * (newlen - oldlen);
160  if ((result = (char *) rtalloc(length + 1)) == NULL) {
161  rterror(_("strreplace: Not enough memory"));
162  found = -1;
163  }
164  else {
165  tmp = str;
166  limit = found; /* Countdown */
167  reslen = 0; /* length of current result */
168 
169  /* Replace each old string found with new string */
170  while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
171  length = (tmp - str); /* Number of chars to keep intouched */
172  strncpy(result + reslen, str, length); /* Original part keeped */
173  strcpy(result + (reslen += length), newstr); /* Insert new string */
174 
175  reslen += newlen;
176  tmp += oldlen;
177  str = tmp;
178  }
179  strcpy(result + reslen, str); /* Copies last part and ending null char */
180  }
181 
182  if (count != NULL) *count = found;
183  return result;
184 }
#define _(String)
Definition: shpcommon.h:23
char ** result
Definition: liblwgeom.h:218
int count
Definition: genraster.py:57
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895

Here is the call graph for this function:

Here is the caller graph for this function: