PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwmessage_truncate()

char* lwmessage_truncate ( char *  str,
int  startpos,
int  endpos,
int  maxlength,
int  truncdirection 
)

Definition at line 294 of file lwutil.c.

References lwalloc().

Referenced by errorIfGeometryCollection().

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