1/* Copyright (C) 2007-2008 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10** GNU General Public License for more details.
11*/
12
13#ifndef _ANDROID_UTILS_STRALLOC_H
14#define _ANDROID_UTILS_STRALLOC_H
15
16#include <stddef.h>
17#include <stdarg.h>
18
19/** DYNAMIC STRINGS
20 **/
21
22typedef struct {
23    char*     s;
24    unsigned  n;
25    unsigned  a;
26} stralloc_t;
27
28#define  STRALLOC_INIT        { NULL, 0, 0 }
29#define  STRALLOC_DEFINE(s)   stralloc_t   s[1] = { STRALLOC_INIT }
30
31extern void   stralloc_reset( stralloc_t*  s );
32extern void   stralloc_ready( stralloc_t*  s, unsigned  len );
33extern void   stralloc_readyplus( stralloc_t*  s, unsigned  len );
34
35extern void   stralloc_copy( stralloc_t*  s, stralloc_t*  from );
36extern void   stralloc_append( stralloc_t*  s, stralloc_t*  from );
37
38extern void   stralloc_add_c( stralloc_t*  s, int  c );
39extern void   stralloc_add_str( stralloc_t*  s, const char*  str );
40extern void   stralloc_add_bytes( stralloc_t*  s, const void*  from, unsigned  len );
41
42extern char*  stralloc_cstr( stralloc_t*  s );
43
44extern void   stralloc_format( stralloc_t*  s, const char*  fmt, ... );
45extern void   stralloc_formatv( stralloc_t*  s, const char*  fmt, va_list  args );
46extern void   stralloc_add_format( stralloc_t*  s, const char*  fmt, ... );
47
48extern void   stralloc_add_quote_c( stralloc_t*  s, int  c );
49extern void   stralloc_add_quote_str( stralloc_t*  s, const char*  str );
50extern void   stralloc_add_quote_bytes( stralloc_t*  s, const void*  from, unsigned   len );
51
52extern void   stralloc_add_hex( stralloc_t*  s, unsigned  value, int  num_digits );
53extern void   stralloc_add_hexdump( stralloc_t*  s, void*  base, int  size, const char*  prefix );
54
55/* Remove leading, trailing or leading+trailing whitespace */
56extern void   stralloc_lstrip( stralloc_t*  s );
57extern void   stralloc_rstrip( stralloc_t*  s );
58extern void   stralloc_strip( stralloc_t*  s );
59
60extern void   stralloc_tabular( stralloc_t*  s, const char** strings, int  count,
61                                                const char*  prefix,  int  width );
62
63extern char*  stralloc_to_tempstr( stralloc_t*  s );
64
65#endif /* ANDROID_UTILS_STRALLOC_H */
66