2 * Copyright (c) 2008 Nicira Networks.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef DYNAMIC_STRING_H
18 #define DYNAMIC_STRING_H 1
30 char *string; /* Null-terminated string. */
31 size_t length; /* Bytes used, not including null terminator. */
32 size_t allocated; /* Bytes allocated, not including null terminator. */
35 #define DS_EMPTY_INITIALIZER { NULL, 0, 0 }
37 void ds_init(struct ds *);
38 void ds_clear(struct ds *);
39 void ds_truncate(struct ds *, size_t new_length);
40 void ds_reserve(struct ds *, size_t min_length);
41 char *ds_put_uninit(struct ds *, size_t n);
42 void ds_put_char(struct ds *, char);
43 void ds_put_char_multiple(struct ds *, char, size_t n);
44 void ds_put_buffer(struct ds *, const char *, size_t n);
45 void ds_put_cstr(struct ds *, const char *);
46 void ds_put_format(struct ds *, const char *, ...) PRINTF_FORMAT(2, 3);
47 void ds_put_format_valist(struct ds *, const char *, va_list)
49 void ds_put_printable(struct ds *, const char *, size_t);
50 void ds_put_strftime(struct ds *, const char *, const struct tm *)
52 void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size,
53 uintptr_t ofs, bool ascii);
54 int ds_get_line(struct ds *, FILE *);
56 char *ds_cstr(struct ds *);
57 void ds_destroy(struct ds *);
59 int ds_last(const struct ds *);
60 void ds_chomp(struct ds *, int c);
62 #endif /* dynamic-string.h */