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

Definition at line 264 of file lwutil.c.

References lwalloc().

Referenced by errorIfGeometryCollection().

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

Here is the call graph for this function:

Here is the caller graph for this function: