|
|
@ -16,8 +16,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct stralloc {
|
|
|
|
typedef struct stralloc {
|
|
|
|
char* s;
|
|
|
|
char* s;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned long int len;
|
|
|
|
unsigned int a;
|
|
|
|
unsigned long int a;
|
|
|
|
} stralloc;
|
|
|
|
} stralloc;
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_init will initialize a stralloc.
|
|
|
|
/* stralloc_init will initialize a stralloc.
|
|
|
@ -32,22 +32,22 @@ void stralloc_init(stralloc* sa);
|
|
|
|
* bytes of space, copies the old string into the new space, frees the
|
|
|
|
* bytes of space, copies the old string into the new space, frees the
|
|
|
|
* old space, and returns 1. Note that this changes sa.s. If the
|
|
|
|
* old space, and returns 1. Note that this changes sa.s. If the
|
|
|
|
* allocation fails, stralloc_ready leaves sa alone and returns 0. */
|
|
|
|
* allocation fails, stralloc_ready leaves sa alone and returns 0. */
|
|
|
|
int stralloc_ready(stralloc* sa,unsigned int len);
|
|
|
|
int stralloc_ready(stralloc* sa,unsigned long int len);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_readyplus is like stralloc_ready except that, if sa is
|
|
|
|
/* stralloc_readyplus is like stralloc_ready except that, if sa is
|
|
|
|
* already allocated, stralloc_readyplus adds the current length of sa
|
|
|
|
* already allocated, stralloc_readyplus adds the current length of sa
|
|
|
|
* to len. */
|
|
|
|
* to len. */
|
|
|
|
int stralloc_readyplus(stralloc* sa,unsigned int len);
|
|
|
|
int stralloc_readyplus(stralloc* sa,unsigned long int len);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_copyb copies the string buf[0], buf[1], ..., buf[len-1] into
|
|
|
|
/* stralloc_copyb copies the string buf[0], buf[1], ..., buf[len-1] into
|
|
|
|
* sa, allocating space if necessary, and returns 1. If it runs out of
|
|
|
|
* sa, allocating space if necessary, and returns 1. If it runs out of
|
|
|
|
* memory, stralloc_copyb leaves sa alone and returns 0. */
|
|
|
|
* memory, stralloc_copyb leaves sa alone and returns 0. */
|
|
|
|
int stralloc_copyb(stralloc* sa,const char* buf,unsigned int len);
|
|
|
|
int stralloc_copyb(stralloc* sa,const unsigned char* buf,unsigned long int len);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_copys copies a \0-terminated string from buf into sa,
|
|
|
|
/* stralloc_copys copies a \0-terminated string from buf into sa,
|
|
|
|
* without the \0. It is the same as
|
|
|
|
* without the \0. It is the same as
|
|
|
|
* stralloc_copyb(&sa,buf,str_len(buf)). */
|
|
|
|
* stralloc_copyb(&sa,buf,str_len(buf)). */
|
|
|
|
int stralloc_copys(stralloc* sa,const char* buf);
|
|
|
|
int stralloc_copys(stralloc* sa,const unsigned char* buf);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_copy copies the string stored in sa2 into sa. It is the same
|
|
|
|
/* stralloc_copy copies the string stored in sa2 into sa. It is the same
|
|
|
|
* as stralloc_copyb(&sa,sa2.s,sa2.len). sa2 must already be allocated. */
|
|
|
|
* as stralloc_copyb(&sa,sa2.s,sa2.len). sa2 must already be allocated. */
|
|
|
@ -58,12 +58,12 @@ int stralloc_copy(stralloc* sa,const stralloc* sa2);
|
|
|
|
* returns 1. If sa is unallocated, stralloc_catb is the same as
|
|
|
|
* returns 1. If sa is unallocated, stralloc_catb is the same as
|
|
|
|
* stralloc_copyb. If it runs out of memory, stralloc_catb leaves sa
|
|
|
|
* stralloc_copyb. If it runs out of memory, stralloc_catb leaves sa
|
|
|
|
* alone and returns 0. */
|
|
|
|
* alone and returns 0. */
|
|
|
|
int stralloc_catb(stralloc* sa,const char* in,unsigned int len);
|
|
|
|
int stralloc_catb(stralloc* sa,const unsigned char* in,unsigned long int len);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_cats is analogous to stralloc_copys */
|
|
|
|
/* stralloc_cats is analogous to stralloc_copys */
|
|
|
|
int stralloc_cats(stralloc* sa,const char* in);
|
|
|
|
int stralloc_cats(stralloc* sa,const unsigned char* in);
|
|
|
|
|
|
|
|
|
|
|
|
#define stralloc_zero(sa) stralloc_copys(sa,"")
|
|
|
|
void stralloc_zero(stralloc* sa);
|
|
|
|
|
|
|
|
|
|
|
|
/* like stralloc_cats but can cat more than one string at once */
|
|
|
|
/* like stralloc_cats but can cat more than one string at once */
|
|
|
|
int stralloc_catm_internal(stralloc* sa,...);
|
|
|
|
int stralloc_catm_internal(stralloc* sa,...);
|
|
|
@ -76,12 +76,12 @@ int stralloc_cat(stralloc* sa,stralloc* in);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_append adds one byte in[0] to the end of the string stored
|
|
|
|
/* stralloc_append adds one byte in[0] to the end of the string stored
|
|
|
|
* in sa. It is the same as stralloc_catb(&sa,in,1). */
|
|
|
|
* in sa. It is the same as stralloc_catb(&sa,in,1). */
|
|
|
|
int stralloc_append(stralloc* sa,const char* in); /* beware: this takes a pointer to 1 char */
|
|
|
|
int stralloc_append(stralloc* sa,const unsigned char* in); /* beware: this takes a pointer to 1 char */
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_starts returns 1 if the \0-terminated string in "in", without
|
|
|
|
/* stralloc_starts returns 1 if the \0-terminated string in "in", without
|
|
|
|
* the terminating \0, is a prefix of the string stored in sa. Otherwise
|
|
|
|
* the terminating \0, is a prefix of the string stored in sa. Otherwise
|
|
|
|
* it returns 0. sa must already be allocated. */
|
|
|
|
* it returns 0. sa must already be allocated. */
|
|
|
|
int stralloc_starts(stralloc* sa,const char* in) __pure__;
|
|
|
|
int stralloc_starts(stralloc* sa,const unsigned char* in) __pure__;
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_diff returns negative, 0, or positive, depending on whether
|
|
|
|
/* stralloc_diff returns negative, 0, or positive, depending on whether
|
|
|
|
* a is lexicographically smaller than, equal to, or greater than the
|
|
|
|
* a is lexicographically smaller than, equal to, or greater than the
|
|
|
@ -91,7 +91,7 @@ int stralloc_diff(const stralloc* a,const stralloc* b) __pure__;
|
|
|
|
/* stralloc_diffs returns negative, 0, or positive, depending on whether
|
|
|
|
/* stralloc_diffs returns negative, 0, or positive, depending on whether
|
|
|
|
* a is lexicographically smaller than, equal to, or greater than the
|
|
|
|
* a is lexicographically smaller than, equal to, or greater than the
|
|
|
|
* string b[0], b[1], ..., b[n]=='\0'. */
|
|
|
|
* string b[0], b[1], ..., b[n]=='\0'. */
|
|
|
|
int stralloc_diffs(const stralloc* a,const char* b) __pure__;
|
|
|
|
int stralloc_diffs(const stralloc* a,const unsigned char* b) __pure__;
|
|
|
|
|
|
|
|
|
|
|
|
#define stralloc_equal(a,b) (!stralloc_diff((a),(b)))
|
|
|
|
#define stralloc_equal(a,b) (!stralloc_diff((a),(b)))
|
|
|
|
#define stralloc_equals(a,b) (!stralloc_diffs((a),(b)))
|
|
|
|
#define stralloc_equals(a,b) (!stralloc_diffs((a),(b)))
|
|
|
@ -100,10 +100,10 @@ int stralloc_diffs(const stralloc* a,const char* b) __pure__;
|
|
|
|
#define stralloc_0(sa) stralloc_append(sa,"")
|
|
|
|
#define stralloc_0(sa) stralloc_append(sa,"")
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_catulong0 appends a '0' padded ASCII representation of in */
|
|
|
|
/* stralloc_catulong0 appends a '0' padded ASCII representation of in */
|
|
|
|
int stralloc_catulong0(stralloc* sa,unsigned long in,unsigned int n);
|
|
|
|
int stralloc_catulong0(stralloc* sa,unsigned long int in,unsigned long int n);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_catlong0 appends a '0' padded ASCII representation of in */
|
|
|
|
/* stralloc_catlong0 appends a '0' padded ASCII representation of in */
|
|
|
|
int stralloc_catlong0(stralloc* sa,signed long in,unsigned int n);
|
|
|
|
int stralloc_catlong0(stralloc* sa,signed long int in,unsigned long int n);
|
|
|
|
|
|
|
|
|
|
|
|
/* stralloc_free frees the storage associated with sa */
|
|
|
|
/* stralloc_free frees the storage associated with sa */
|
|
|
|
void stralloc_free(stralloc* sa);
|
|
|
|
void stralloc_free(stralloc* sa);
|
|
|
@ -137,12 +137,12 @@ int buffer_putsaflush(buffer* b,stralloc* sa);
|
|
|
|
* data is available. */
|
|
|
|
* data is available. */
|
|
|
|
|
|
|
|
|
|
|
|
/* read token from buffer to stralloc */
|
|
|
|
/* read token from buffer to stralloc */
|
|
|
|
int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen);
|
|
|
|
int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned long int setlen);
|
|
|
|
/* read line from buffer to stralloc */
|
|
|
|
/* read line from buffer to stralloc */
|
|
|
|
int buffer_getline_sa(buffer* b,stralloc* sa);
|
|
|
|
int buffer_getline_sa(buffer* b,stralloc* sa);
|
|
|
|
|
|
|
|
|
|
|
|
/* same as buffer_get_token_sa but empty sa first */
|
|
|
|
/* same as buffer_get_token_sa but empty sa first */
|
|
|
|
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen);
|
|
|
|
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned long int setlen);
|
|
|
|
/* same as buffer_getline_sa but empty sa first */
|
|
|
|
/* same as buffer_getline_sa but empty sa first */
|
|
|
|
int buffer_getnewline_sa(buffer* b,stralloc* sa);
|
|
|
|
int buffer_getnewline_sa(buffer* b,stralloc* sa);
|
|
|
|
|
|
|
|
|
|
|
|