diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-04-13 21:05:27 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-04-13 21:05:27 -0400 |
commit | f108e0952615e08a304d4e8564789d3534233e69 (patch) | |
tree | 27d160f84d91e4c7963d93b2c4d4e4a0ce62d234 /dstring.h | |
parent | 185ae8494bfd82757dc25b0ad92ddd833415c0ad (diff) | |
download | bfs-f108e0952615e08a304d4e8564789d3534233e69.tar.xz |
dstring: Split out the dynamic string logic.
Diffstat (limited to 'dstring.h')
-rw-r--r-- | dstring.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/dstring.h b/dstring.h new file mode 100644 index 0000000..7e46da8 --- /dev/null +++ b/dstring.h @@ -0,0 +1,88 @@ +/********************************************************************* + * bfs * + * Copyright (C) 2016 Tavian Barnes <tavianator@tavianator.com> * + * * + * This program is free software. It comes without any warranty, to * + * the extent permitted by applicable law. You can redistribute it * + * and/or modify it under the terms of the Do What The Fuck You Want * + * To Public License, Version 2, as published by Sam Hocevar. See * + * the COPYING file or http://www.wtfpl.net/ for more details. * + *********************************************************************/ + +#ifndef BFS_DSTRING_H +#define BFS_DSTRING_H + +#include <stddef.h> + +/** + * Allocate a dynamic string. + * + * @param capacity + * The initial capacity of the string. + */ +char *dstralloc(size_t capacity); + +/** + * Get a dynamic string's length. + * + * @param dstr + * The string to measure. + * @return The length of dstr. + */ +size_t dstrlen(const char *dstr); + +/** + * Reserve some capacity in a dynamic string. + * + * @param dstr + * The dynamic string to preallocate. + * @param capacity + * The new capacity for the string. + * @return 0 on success, -1 on failure. + */ +int dstreserve(char **dstr, size_t capacity); + +/** + * Resize a dynamic string. + * + * @param dstr + * The dynamic string to resize. + * @param length + * The new length for the dynamic string. + * @return 0 on success, -1 on failure. + */ +int dstresize(char **dstr, size_t length); + +/** + * Append to a dynamic string. + * + * @param dest + * The destination dynamic string. + * @param src + * The string to append. + * @return 0 on success, -1 on failure. + */ +int dstrcat(char **dest, const char *src); + +/** + * Append to a dynamic string at a particular offset. + * + * @param dest + * The destination dynamic string. + * @param pos + * The offset at which to append. + * @param src + * The string to append. + * @return 0 on success, -1 on failure. + */ +int dstrcatat(char **dest, size_t pos, const char *src); + +/** + * Free a dynamic string. + * + * @param dstr + * The string to free. + */ +void dstrfree(char *dstr); + +#endif // BFS_DSTRING_H |