PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ chartrim()

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

Definition at line 293 of file raster2pgsql.c.

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

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

293  {
294  char *rtn = NULL;
295  char *ptr = NULL;
296  uint32_t offset = 0;
297 
298  if (!input)
299  return NULL;
300  else if (!*input)
301  return (char *) input;
302 
303  /* trim left */
304  while (strchr(remove, *input) != NULL)
305  input++;
306 
307  /* trim right */
308  ptr = ((char *) input) + strlen(input);
309  while (strchr(remove, *--ptr) != NULL)
310  offset++;
311 
312  rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
313  if (NULL == rtn) {
314  rterror(_("chartrim: Not enough memory"));
315  return NULL;
316  }
317  strncpy(rtn, input, strlen(input) - offset);
318  rtn[strlen(input) - offset] = '\0';
319 
320  return rtn;
321 }
#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: