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

◆ stringbuffer_trim_trailing_zeroes()

int stringbuffer_trim_trailing_zeroes ( stringbuffer_t s)
extern

Trims zeroes off the end of the last number in the stringbuffer.

The number has to be the very last thing in the buffer. Only the last number will be trimmed. Returns the number of characters trimmed.

eg: 1.22000 -> 1.22 1.0 -> 1 0.0 -> 0

Definition at line 305 of file stringbuffer.c.

306{
307 char *ptr = s->str_end;
308 char *decimal_ptr = NULL;
309 int dist;
310
311 if ( s->str_end - s->str_start < 2)
312 return 0;
313
314 /* Roll backwards to find the decimal for this number */
315 while( ptr > s->str_start )
316 {
317 ptr--;
318 if ( *ptr == '.' )
319 {
320 decimal_ptr = ptr;
321 break;
322 }
323 if ( (*ptr >= '0') && (*ptr <= '9' ) )
324 continue;
325 else
326 break;
327 }
328
329 /* No decimal? Nothing to trim! */
330 if ( ! decimal_ptr )
331 return 0;
332
333 ptr = s->str_end;
334
335 /* Roll backwards again, with the decimal as stop point, trimming contiguous zeroes */
336 while( ptr >= decimal_ptr )
337 {
338 ptr--;
339 if ( *ptr == '0' )
340 continue;
341 else
342 break;
343 }
344
345 /* Huh, we get anywhere. Must not have trimmed anything. */
346 if ( ptr == s->str_end )
347 return 0;
348
349 /* If we stopped at the decimal, we want to null that out.
350 It we stopped on a numeral, we want to preserve that, so push the
351 pointer forward one space. */
352 if ( *ptr != '.' )
353 ptr++;
354
355 /* Add null terminator re-set the end of the stringbuffer. */
356 *ptr = '\0';
357 dist = s->str_end - ptr;
358 s->str_end = ptr;
359 return dist;
360}
char * s
Definition cu_in_wkt.c:23

References s.