PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwmessage_truncate()

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

Definition at line 274 of file lwutil.c.

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

References lwalloc(), and str.

Here is the call graph for this function: