PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwmessage_truncate()

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

Definition at line 261 of file lwutil.c.

References lwalloc().

Referenced by errorIfGeometryCollection().

262 {
263  char *output;
264  char *outstart;
265 
266  /* Allocate space for new string */
267  output = lwalloc(maxlength + 4);
268  output[0] = '\0';
269 
270  /* Start truncation */
271  if (truncdirection == 0)
272  {
273  /* Calculate the start position */
274  if (endpos - startpos < maxlength)
275  {
276  outstart = str + startpos;
277  strncat(output, outstart, endpos - startpos + 1);
278  }
279  else
280  {
281  if (maxlength >= 3)
282  {
283  /* Add "..." prefix */
284  outstart = str + endpos + 1 - maxlength + 3;
285  strncat(output, "...", 3);
286  strncat(output, outstart, maxlength - 3);
287  }
288  else
289  {
290  /* maxlength is too small; just output "..." */
291  strncat(output, "...", 3);
292  }
293  }
294  }
295 
296  /* End truncation */
297  if (truncdirection == 1)
298  {
299  /* Calculate the end position */
300  if (endpos - startpos < maxlength)
301  {
302  outstart = str + startpos;
303  strncat(output, outstart, endpos - startpos + 1);
304  }
305  else
306  {
307  if (maxlength >= 3)
308  {
309  /* Add "..." suffix */
310  outstart = str + startpos;
311  strncat(output, outstart, maxlength - 3);
312  strncat(output, "...", 3);
313  }
314  else
315  {
316  /* maxlength is too small; just output "..." */
317  strncat(output, "...", 3);
318  }
319  }
320  }
321 
322  return output;
323 }
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: