PostGIS  2.3.7dev-r@@SVN_REVISION@@
char* lwmessage_truncate ( char *  str,
int  startpos,
int  endpos,
int  maxlength,
int  truncdirection 
)

Definition at line 292 of file lwutil.c.

References lwalloc().

Referenced by errorIfGeometryCollection().

293 {
294  char *output;
295  char *outstart;
296 
297  /* Allocate space for new string */
298  output = lwalloc(maxlength + 4);
299  output[0] = '\0';
300 
301  /* Start truncation */
302  if (truncdirection == 0)
303  {
304  /* Calculate the start position */
305  if (endpos - startpos < maxlength)
306  {
307  outstart = str + startpos;
308  strncat(output, outstart, endpos - startpos + 1);
309  }
310  else
311  {
312  if (maxlength >= 3)
313  {
314  /* Add "..." prefix */
315  outstart = str + endpos + 1 - maxlength + 3;
316  strncat(output, "...", 3);
317  strncat(output, outstart, maxlength - 3);
318  }
319  else
320  {
321  /* maxlength is too small; just output "..." */
322  strncat(output, "...", 3);
323  }
324  }
325  }
326 
327  /* End truncation */
328  if (truncdirection == 1)
329  {
330  /* Calculate the end position */
331  if (endpos - startpos < maxlength)
332  {
333  outstart = str + startpos;
334  strncat(output, outstart, endpos - startpos + 1);
335  }
336  else
337  {
338  if (maxlength >= 3)
339  {
340  /* Add "..." suffix */
341  outstart = str + startpos;
342  strncat(output, outstart, maxlength - 3);
343  strncat(output, "...", 3);
344  }
345  else
346  {
347  /* maxlength is too small; just output "..." */
348  strncat(output, "...", 3);
349  }
350  }
351  }
352 
353  return output;
354 }
void * lwalloc(size_t size)
Definition: lwutil.c:227

Here is the call graph for this function:

Here is the caller graph for this function: