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#include "android/utils/compiler.h"
20
21ANDROID_BEGIN_HEADER
22
23/** DYNAMIC STRINGS
24 **/
25
26typedef struct {
27    char*     s;
28    unsigned  n;
29    unsigned  a;
30} stralloc_t;
31
32#define  STRALLOC_INIT        { NULL, 0, 0 }
33#define  STRALLOC_DEFINE(s)   stralloc_t   s[1] = { STRALLOC_INIT }
34
35extern void   stralloc_reset( stralloc_t*  s );
36extern void   stralloc_ready( stralloc_t*  s, unsigned  len );
37extern void   stralloc_readyplus( stralloc_t*  s, unsigned  len );
38
39extern void   stralloc_copy( stralloc_t*  s, stralloc_t*  from );
40extern void   stralloc_append( stralloc_t*  s, stralloc_t*  from );
41
42extern void   stralloc_add_c( stralloc_t*  s, int  c );
43extern void   stralloc_add_str( stralloc_t*  s, const char*  str );
44extern void   stralloc_add_bytes( stralloc_t*  s, const void*  from, unsigned  len );
45
46extern char*  stralloc_cstr( stralloc_t*  s );
47
48extern void   stralloc_format( stralloc_t*  s, const char*  fmt, ... );
49extern void   stralloc_formatv( stralloc_t*  s, const char*  fmt, va_list  args );
50extern void   stralloc_add_format( stralloc_t*  s, const char*  fmt, ... );
51
52extern void   stralloc_add_quote_c( stralloc_t*  s, int  c );
53extern void   stralloc_add_quote_str( stralloc_t*  s, const char*  str );
54extern void   stralloc_add_quote_bytes( stralloc_t*  s, const void*  from, unsigned   len );
55
56extern void   stralloc_add_hex( stralloc_t*  s, unsigned  value, int  num_digits );
57extern void   stralloc_add_hexdump( stralloc_t*  s, void*  base, int  size, const char*  prefix );
58
59/* Remove leading, trailing or leading+trailing whitespace */
60extern void   stralloc_lstrip( stralloc_t*  s );
61extern void   stralloc_rstrip( stralloc_t*  s );
62extern void   stralloc_strip( stralloc_t*  s );
63
64extern void   stralloc_tabular( stralloc_t*  s, const char** strings, int  count,
65                                                const char*  prefix,  int  width );
66
67extern char*  stralloc_to_tempstr( stralloc_t*  s );
68
69ANDROID_BEGIN_HEADER
70
71#endif /* ANDROID_UTILS_STRALLOC_H */
72