• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 typedef 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 
31 extern void   stralloc_reset( stralloc_t*  s );
32 extern void   stralloc_ready( stralloc_t*  s, unsigned  len );
33 extern void   stralloc_readyplus( stralloc_t*  s, unsigned  len );
34 
35 extern void   stralloc_copy( stralloc_t*  s, stralloc_t*  from );
36 extern void   stralloc_append( stralloc_t*  s, stralloc_t*  from );
37 
38 extern void   stralloc_add_c( stralloc_t*  s, int  c );
39 extern void   stralloc_add_str( stralloc_t*  s, const char*  str );
40 extern void   stralloc_add_bytes( stralloc_t*  s, const void*  from, unsigned  len );
41 
42 extern char*  stralloc_cstr( stralloc_t*  s );
43 
44 extern void   stralloc_format( stralloc_t*  s, const char*  fmt, ... );
45 extern void   stralloc_formatv( stralloc_t*  s, const char*  fmt, va_list  args );
46 extern void   stralloc_add_format( stralloc_t*  s, const char*  fmt, ... );
47 
48 extern void   stralloc_add_quote_c( stralloc_t*  s, int  c );
49 extern void   stralloc_add_quote_str( stralloc_t*  s, const char*  str );
50 extern void   stralloc_add_quote_bytes( stralloc_t*  s, const void*  from, unsigned   len );
51 
52 extern void   stralloc_add_hex( stralloc_t*  s, unsigned  value, int  num_digits );
53 extern void   stralloc_add_hexdump( stralloc_t*  s, void*  base, int  size, const char*  prefix );
54 
55 /* Remove leading, trailing or leading+trailing whitespace */
56 extern void   stralloc_lstrip( stralloc_t*  s );
57 extern void   stralloc_rstrip( stralloc_t*  s );
58 extern void   stralloc_strip( stralloc_t*  s );
59 
60 extern void   stralloc_tabular( stralloc_t*  s, const char** strings, int  count,
61                                                 const char*  prefix,  int  width );
62 
63 extern char*  stralloc_to_tempstr( stralloc_t*  s );
64 
65 #endif /* ANDROID_UTILS_STRALLOC_H */
66