PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwmessage_truncate()

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

Definition at line 268 of file lwutil.c.

269 {
270  char *output;
271  char *outstart;
272 
273  /* Allocate space for new string */
274  output = lwalloc(maxlength + 4);
275  output[0] = '\0';
276 
277  /* Start truncation */
278  if (truncdirection == 0)
279  {
280  /* Calculate the start position */
281  if (endpos - startpos < maxlength)
282  {
283  outstart = str + startpos;
284  strncat(output, outstart, endpos - startpos + 1);
285  }
286  else
287  {
288  if (maxlength >= 3)
289  {
290  /* Add "..." prefix */
291  outstart = str + endpos + 1 - maxlength + 3;
292  strncat(output, "...", 4);
293  strncat(output, outstart, maxlength - 3);
294  }
295  else
296  {
297  /* maxlength is too small; just output "..." */
298  strncat(output, "...", 4);
299  }
300  }
301  }
302 
303  /* End truncation */
304  if (truncdirection == 1)
305  {
306  /* Calculate the end 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 "..." suffix */
317  outstart = str + startpos;
318  strncat(output, outstart, maxlength - 3);
319  strncat(output, "...", 4);
320  }
321  else
322  {
323  /* maxlength is too small; just output "..." */
324  strncat(output, "...", 4);
325  }
326  }
327  }
328 
329  return output;
330 }
#define str(s)
void * lwalloc(size_t size)
Definition: lwutil.c:227

References lwalloc(), and str.

Here is the call graph for this function: