PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ chartrim()

static char* chartrim ( const char *  input,
char *  remove 
)
static

Definition at line 294 of file raster2pgsql.c.

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

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

294  {
295  char *rtn = NULL;
296  char *ptr = NULL;
297  uint32_t offset = 0;
298  size_t len = 0;
299 
300  if (!input)
301  return NULL;
302  else if (!*input)
303  return (char *) input;
304 
305  /* trim left */
306  while (strchr(remove, *input) != NULL)
307  input++;
308 
309  /* trim right */
310  ptr = ((char *) input) + strlen(input);
311  while (strchr(remove, *--ptr) != NULL)
312  offset++;
313 
314  len = strlen(input) - offset + 1;
315  rtn = rtalloc(sizeof(char) * len);
316  if (NULL == rtn) {
317  rterror(_("chartrim: Not enough memory"));
318  return NULL;
319  }
320  strncpy(rtn, input, len);
321  rtn[strlen(input) - offset] = '\0';
322 
323  return rtn;
324 }
#define _(String)
Definition: shpcommon.h:24
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
unsigned int uint32_t
Definition: uthash.h:78
Here is the call graph for this function:
Here is the caller graph for this function: