PostGIS 3.0.6dev-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 268 of file stringbuffer.c.

269{
270 char *ptr = s->str_end;
271 char *decimal_ptr = NULL;
272 int dist;
273
274 if ( s->str_end - s->str_start < 2)
275 return 0;
276
277 /* Roll backwards to find the decimal for this number */
278 while( ptr > s->str_start )
279 {
280 ptr--;
281 if ( *ptr == '.' )
282 {
283 decimal_ptr = ptr;
284 break;
285 }
286 if ( (*ptr >= '0') && (*ptr <= '9' ) )
287 continue;
288 else
289 break;
290 }
291
292 /* No decimal? Nothing to trim! */
293 if ( ! decimal_ptr )
294 return 0;
295
296 ptr = s->str_end;
297
298 /* Roll backwards again, with the decimal as stop point, trimming contiguous zeroes */
299 while( ptr >= decimal_ptr )
300 {
301 ptr--;
302 if ( *ptr == '0' )
303 continue;
304 else
305 break;
306 }
307
308 /* Huh, we get anywhere. Must not have trimmed anything. */
309 if ( ptr == s->str_end )
310 return 0;
311
312 /* If we stopped at the decimal, we want to null that out.
313 It we stopped on a numeral, we want to preserve that, so push the
314 pointer forward one space. */
315 if ( *ptr != '.' )
316 ptr++;
317
318 /* Add null terminator re-set the end of the stringbuffer. */
319 *ptr = '\0';
320 dist = s->str_end - ptr;
321 s->str_end = ptr;
322 return dist;
323}
char * s
Definition cu_in_wkt.c:23

References s.

Referenced by ptarray_to_kml2_sb().

Here is the caller graph for this function: