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