PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rtpg_trim()

char* rtpg_trim ( const char *  input)

Definition at line 226 of file rtpg_internal.c.

Referenced by _PG_init(), RASTER_asGDALRaster(), RASTER_asRaster(), RASTER_colorMap(), RASTER_GDALWarp(), RASTER_mapAlgebra2(), RASTER_nMapAlgebra(), and RASTER_nMapAlgebraExpr().

226  {
227  char *rtn;
228  char *ptr;
229  uint32_t offset = 0;
230  int inputlen = 0;
231 
232  if (!input)
233  return NULL;
234  else if (!*input)
235  return (char *) input;
236 
237  /* trim left */
238  while (isspace(*input) && *input != '\0')
239  input++;
240 
241  /* trim right */
242  inputlen = strlen(input);
243  if (inputlen) {
244  ptr = ((char *) input) + inputlen;
245  while (isspace(*--ptr))
246  offset++;
247  }
248 
249  rtn = palloc(sizeof(char) * (inputlen - offset + 1));
250  if (rtn == NULL) {
251  fprintf(stderr, "Not enough memory\n");
252  return NULL;
253  }
254  strncpy(rtn, input, inputlen - offset);
255  rtn[inputlen - offset] = '\0';
256 
257  return rtn;
258 }
unsigned int uint32_t
Definition: uthash.h:78
Here is the caller graph for this function: