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

Definition at line 240 of file lwutil.c.

References lwalloc().

Referenced by errorIfGeometryCollection().

241 {
242  char *output;
243  char *outstart;
244 
245  /* Allocate space for new string */
246  output = lwalloc(maxlength + 4);
247  output[0] = '\0';
248 
249  /* Start truncation */
250  if (truncdirection == 0)
251  {
252  /* Calculate the start position */
253  if (endpos - startpos < maxlength)
254  {
255  outstart = str + startpos;
256  strncat(output, outstart, endpos - startpos + 1);
257  }
258  else
259  {
260  if (maxlength >= 3)
261  {
262  /* Add "..." prefix */
263  outstart = str + endpos + 1 - maxlength + 3;
264  strncat(output, "...", 3);
265  strncat(output, outstart, maxlength - 3);
266  }
267  else
268  {
269  /* maxlength is too small; just output "..." */
270  strncat(output, "...", 3);
271  }
272  }
273  }
274 
275  /* End truncation */
276  if (truncdirection == 1)
277  {
278  /* Calculate the end position */
279  if (endpos - startpos < maxlength)
280  {
281  outstart = str + startpos;
282  strncat(output, outstart, endpos - startpos + 1);
283  }
284  else
285  {
286  if (maxlength >= 3)
287  {
288  /* Add "..." suffix */
289  outstart = str + startpos;
290  strncat(output, outstart, maxlength - 3);
291  strncat(output, "...", 3);
292  }
293  else
294  {
295  /* maxlength is too small; just output "..." */
296  strncat(output, "...", 3);
297  }
298  }
299  }
300 
301  return output;
302 }
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function:

Here is the caller graph for this function: