PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
stringbuffer.h
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * PostGIS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PostGIS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18 *
19 **********************************************************************
20 *
21 * Copyright 2002 Thamer Alharbash
22 * Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
23 *
24 **********************************************************************/
25
26
27#ifndef _STRINGBUFFER_H
28#define _STRINGBUFFER_H 1
29
30#include "liblwgeom_internal.h"
31
32#include <stdlib.h>
33#include <stdarg.h>
34#include <string.h>
35#include <stdio.h>
36
37#define STRINGBUFFER_STARTSIZE 128
38
39typedef struct
40{
41 size_t capacity;
42 char *str_end;
43 char *str_start;
44}
46
52extern void stringbuffer_clear(stringbuffer_t *sb);
53void stringbuffer_set(stringbuffer_t *sb, const char *s);
55extern int stringbuffer_aprintf(stringbuffer_t *sb, const char *fmt, ...);
56extern const char *stringbuffer_getstring(stringbuffer_t *sb);
62
67static inline void
69{
70 size_t current_size = (s->str_end - s->str_start);
71 size_t capacity = s->capacity;
72 size_t required_size = current_size + size_to_add;
73
74 while (capacity < required_size)
75 capacity *= 2;
76
77 if (capacity > s->capacity)
78 {
79 s->str_start = lwrealloc(s->str_start, capacity);
80 s->capacity = capacity;
81 s->str_end = s->str_start + current_size;
82 }
83}
87inline static void
89{
90 int alen = strlen(a); /* Length of string to append */
91 int alen0 = alen + 1; /* Length including null terminator */
93 memcpy(s->str_end, a, alen0);
94 s->str_end += alen;
95}
96#endif /* _STRINGBUFFER_H */
char * s
Definition cu_in_wkt.c:23
void * lwrealloc(void *mem, size_t size)
Definition lwutil.c:235
int stringbuffer_getlength(stringbuffer_t *sb)
Returns the length of the current string, not including the null terminator (same behavior as strlen(...
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
void stringbuffer_release(stringbuffer_t *s)
static void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
int stringbuffer_aprintf(stringbuffer_t *sb, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
char stringbuffer_lastchar(stringbuffer_t *s)
Return the last character in the buffer.
int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
Trims zeroes off the end of the last number in the stringbuffer.
const char * stringbuffer_getstring(stringbuffer_t *sb)
Returns a reference to the internal string being managed by the stringbuffer.
void stringbuffer_destroy(stringbuffer_t *sb)
Free the stringbuffer_t and all memory managed within it.
void stringbuffer_init(stringbuffer_t *s)
static void stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
If necessary, expand the stringbuffer_t internal buffer to accommodate the specified additional size.
void stringbuffer_copy(stringbuffer_t *sb, stringbuffer_t *src)
Copy the contents of src into dst.
void stringbuffer_set(stringbuffer_t *sb, const char *s)
Clear the stringbuffer_t and re-start it with the specified string.
stringbuffer_t * stringbuffer_create_with_size(size_t size)
Allocate a new stringbuffer_t.
void stringbuffer_clear(stringbuffer_t *sb)
Reset the stringbuffer_t.
int stringbuffer_trim_trailing_white(stringbuffer_t *s)
Trims whitespace off the end of the stringbuffer.
char * stringbuffer_getstringcopy(stringbuffer_t *sb)
Returns a newly allocated string large enough to contain the current state of the string.