|
|
|
@ -56,6 +56,8 @@ INLINE str *str_dup(const str *s);
|
|
|
|
|
INLINE str *str_chunk_insert(GStringChunk *c, const str *s);
|
|
|
|
|
/* shifts pointer by len chars and decrements len. returns -1 if buffer too short, 0 otherwise */
|
|
|
|
|
INLINE int str_shift(str *s, int len);
|
|
|
|
|
/* eats the supplied string from the beginning of s. returns -1 if string head doesn't match */
|
|
|
|
|
INLINE int str_shift_cmp(str *s, const char *);
|
|
|
|
|
/* binary compares str object with memory chunk of equal size */
|
|
|
|
|
INLINE int str_memcmp(const str *s, void *m);
|
|
|
|
|
/* locate a substring within a string, returns character index or -1 */
|
|
|
|
@ -85,6 +87,12 @@ gboolean str_equal(gconstpointer a, gconstpointer b);
|
|
|
|
|
/* destroy function, frees a slice-alloc'd str */
|
|
|
|
|
void str_slice_free(void *);
|
|
|
|
|
|
|
|
|
|
/* saves "in" into "out" pseudo-URI encoded. "out" point to a buffer with sufficient length. returns length */
|
|
|
|
|
int str_uri_encode_len(char *out, const char *in, int in_len);
|
|
|
|
|
INLINE int str_uri_encode(char *out, const str *in);
|
|
|
|
|
/* reverse of the above. stores newly allocated buffer in *out. returns length */
|
|
|
|
|
int str_uri_decode_len(char **out, const char *in, int in_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -105,6 +113,16 @@ INLINE int str_shift(str *s, int len) {
|
|
|
|
|
s->len -= len;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
INLINE int str_shift_cmp(str *s, const char *t) {
|
|
|
|
|
int len = strlen(t);
|
|
|
|
|
if (s->len < len)
|
|
|
|
|
return -1;
|
|
|
|
|
if (memcmp(s->s, t, len))
|
|
|
|
|
return -1;
|
|
|
|
|
s->s += len;
|
|
|
|
|
s->len -= len;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
INLINE char *str_chr(const str *s, int c) {
|
|
|
|
|
return memchr(s->s, c, s->len);
|
|
|
|
|
}
|
|
|
|
@ -292,6 +310,10 @@ INLINE int str_token(str *new_token, str *ori_and_remainder, int sep) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INLINE int str_uri_encode(char *out, const str *in) {
|
|
|
|
|
return str_uri_encode_len(out, in->s, in->len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Generates a hex string representing n random bytes. len(rand_str) = 2*num_bytes + 1 */
|
|
|
|
|
char *rand_hex_str(char *rand_str, int num_bytes);
|
|
|
|
|