bstr.h File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "bstr_builder.h"
Include dependency graph for bstr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bstr_t

Defines

#define bstr_len(X)   ((*(bstr_t *)(X)).len)
#define bstr_size(X)   ((*(bstr_t *)(X)).size)
#define bstr_ptr(X)   ( ((*(bstr_t *)(X)).ptr == NULL) ? ((char *)(X) + sizeof(bstr_t)) : (char *)(*(bstr_t *)(X)).ptr )

Typedefs

typedef struct bstr_t bstr_t
typedef bstr_t bstr

Functions

bstrbstr_alloc (size_t newsize)
void bstr_free (bstr **s)
bstrbstr_expand (bstr *s, size_t newsize)
bstrbstr_dup (const bstr *b)
bstrbstr_dup_ex (const bstr *b, size_t offset, size_t len)
bstrbstr_dup_c (const char *)
bstrbstr_dup_mem (const char *data, size_t len)
bstrbstr_dup_lower (const bstr *)
int bstr_chr (const bstr *, int)
int bstr_rchr (const bstr *, int)
int bstr_cmp (const bstr *, const bstr *)
int bstr_cmp_nocase (const bstr *, const bstr *)
int bstr_cmp_c (const bstr *, const char *)
int bstr_cmp_c_nocase (const bstr *, const char *)
int bstr_cmp_ex (const char *, size_t, const char *, size_t)
int bstr_cmp_nocase_ex (const char *, size_t, const char *, size_t)
bstrbstr_to_lowercase (bstr *)
bstrbstr_add (bstr *, const bstr *)
bstrbstr_add_c (bstr *, const char *)
bstrbstr_add_mem (bstr *, const char *, size_t)
bstrbstr_add_noex (bstr *, const bstr *)
bstrbstr_add_c_noex (bstr *, const char *)
bstrbstr_add_mem_noex (bstr *, const char *, size_t)
int bstr_index_of (const bstr *haystack, const bstr *needle)
int bstr_index_of_nocase (const bstr *haystack, const bstr *needle)
int bstr_index_of_c (const bstr *haystack, const char *needle)
int bstr_index_of_c_nocase (const bstr *haystack, const char *needle)
int bstr_index_of_mem (const bstr *haystack, const char *data, size_t len)
int bstr_index_of_mem_nocase (const bstr *haystack, const char *data, size_t len)
int bstr_begins_with_mem (const bstr *haystack, const char *data, size_t len)
int bstr_begins_with_mem_nocase (const bstr *haystack, const char *data, size_t len)
int bstr_begins_with (const bstr *haystack, const bstr *needle)
int bstr_begins_with_c (const bstr *haystack, const char *needle)
int bstr_begins_with_nocase (const bstr *haystack, const bstr *needle)
int bstr_begins_withc_nocase (const bstr *haystack, const char *needle)
unsigned char bstr_char_at (const bstr *s, size_t pos)
void bstr_chop (bstr *b)
void bstr_util_adjust_len (bstr *s, size_t newlen)
int64_t bstr_util_mem_to_pint (const char *data, size_t len, int base, size_t *lastlen)
char * bstr_util_memdup_to_c (const char *data, size_t len)
char * bstr_util_strdup_to_c (const bstr *)

Detailed Description

Author:
Ivan Ristic <ivanr@webkreator.com>

Define Documentation

#define bstr_len (  )     ((*(bstr_t *)(X)).len)
#define bstr_ptr (  )     ( ((*(bstr_t *)(X)).ptr == NULL) ? ((char *)(X) + sizeof(bstr_t)) : (char *)(*(bstr_t *)(X)).ptr )
#define bstr_size (  )     ((*(bstr_t *)(X)).size)

Typedef Documentation

typedef bstr_t bstr
typedef struct bstr_t bstr_t

Function Documentation

bstr* bstr_add ( bstr destination,
const bstr source 
)

Append source bstring to destination bstring, growing destination if necessary. If the string is expanded, the pointer will change. You must replace the original destination pointer with the returned one. Destination is not changed on memory allocation failure.

Parameters:
destination 
source 
Returns:
destination, at a potentially different memory location

Here is the call graph for this function:

bstr* bstr_add_c ( bstr destination,
const char *  source 
)

Append a NUL-terminated source to destination, growing destination if necessary. If the string is expanded, the pointer will change. You must replace the original destination pointer with the returned one. Destination is not changed on memory allocation failure. Destination is not changed on memory allocation failure.

Parameters:
destination 
source 
Returns:
destination, at a potentially different memory location

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_add_c_noex ( bstr destination,
const char *  source 
)

Append a NUL-terminated source to destination, growing destination if necessary. If the string is expanded, the pointer will change. You must replace the original destination pointer with the returned one. Destination is not changed on memory allocation failure.

Parameters:
destination 
source 
Returns:
destination, at a potentially different memory location

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_add_mem ( bstr destination,
const char *  data,
size_t  len 
)

Append a memory region to destination, growing destination if necessary. If the string is expanded, the pointer will change. You must replace the original destination pointer with the returned one. Destination is not changed on memory allocation failure.

Parameters:
destination 
data 
len 
Returns:
destination, at a potentially different memory location

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_add_mem_noex ( bstr destination,
const char *  data,
size_t  len 
)

Append a memory region to destination. If there is not enough room in the destination, copy as many bytes as possible.

Parameters:
destination 
data 
len 
Returns:
destination, at a potentially different memory location

Here is the caller graph for this function:

bstr* bstr_add_noex ( bstr destination,
const bstr source 
)

Append source bstring to destination bstring, growing destination if necessary. If the string is expanded, the pointer will change. You must replace the original destination pointer with the returned one. Destination is not changed on memory allocation failure.

Parameters:
destination 
source 
Returns:
destination, at a potentially different memory location

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_alloc ( size_t  len  ) 

Allocate a zero-length bstring, but reserving space for at least len bytes.

Parameters:
len 
Returns:
New string

Here is the caller graph for this function:

int bstr_begins_with ( const bstr haystack,
const bstr needle 
)

Checks whether bstring begins with another bstring. Case sensitive.

Parameters:
haystack 
needle 
Returns:
1 if true, otherwise

Here is the call graph for this function:

int bstr_begins_with_c ( const bstr haystack,
const char *  needle 
)

Checks whether bstring begins with NUL-terminated string. Case sensitive.

Parameters:
haystack 
needle 
Returns:

Here is the call graph for this function:

int bstr_begins_with_mem ( const bstr haystack,
const char *  data,
size_t  len 
)

Checks whether bstring begins with memory block. Case sensitive.

Parameters:
haystack 
needle 
Returns:
1 if true, otherwise

Here is the caller graph for this function:

int bstr_begins_with_mem_nocase ( const bstr haystack,
const char *  data,
size_t  len 
)

Checks whether bstring begins with memory block. Case insensitive.

Parameters:
haystack 
needle 
Returns:
1 if true, otherwise

Here is the caller graph for this function:

int bstr_begins_with_nocase ( const bstr haystack,
const bstr needle 
)

Checks whether bstring begins with another bstring. Case insensitive.

Parameters:
haystack 
needle 
Returns:
1 if true, 0 otherwise

Here is the call graph for this function:

int bstr_begins_withc_nocase ( const bstr haystack,
const char *  needle 
)

Checks whether bstring begins with NUL-terminated string. Case insensitive.

Parameters:
haystack 
needle 
Returns:
1 if true, 0 otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned char bstr_char_at ( const bstr s,
size_t  pos 
)

Return the character (byte) at the given position.

Parameters:
s 
pos 
Returns:
the character, or -1 if the bstring is too short
void bstr_chop ( bstr s  ) 

Remove one byte from the end of the string, provided the it contains at least one byte.

Parameters:
s 

Here is the caller graph for this function:

int bstr_chr ( const bstr b,
int  c 
)

Return the first position of the provided character (byte).

Parameters:
b 
c 
Returns:
the first position of the character, or -1 if it could not be found

Here is the caller graph for this function:

int bstr_cmp ( const bstr b1,
const bstr b2 
)

Case-sensitive comparison two bstrings.

Parameters:
b1 
b2 
Returns:
0, -1 or +1

Here is the call graph for this function:

int bstr_cmp_c ( const bstr b,
const char *  c 
)

Case-sensitive comparison of a bstring with a NUL-terminated string.

Parameters:
b 
c 
Returns:
0, -1 or +1

Here is the call graph for this function:

Here is the caller graph for this function:

int bstr_cmp_c_nocase ( const bstr b,
const char *  c 
)

Case-insensitive comparison of a bstring with a NUL-terminated string.

Parameters:
b 
c 
Returns:
0, -1 or +1

Here is the call graph for this function:

Here is the caller graph for this function:

int bstr_cmp_ex ( const char *  s1,
size_t  l1,
const char *  s2,
size_t  l2 
)

Case-sensitive comparison of two memory regions.

Parameters:
s1 
l1 
s2 
l2 
Returns:
0 if the memory regions are identical, -1 or +1 if they're not

Here is the caller graph for this function:

int bstr_cmp_nocase ( const bstr b1,
const bstr b2 
)

Case-insensitive comparison two bstrings.

Parameters:
b1 
b2 
Returns:
0, -1 or +1

Here is the call graph for this function:

Here is the caller graph for this function:

int bstr_cmp_nocase_ex ( const char *  s1,
size_t  l1,
const char *  s2,
size_t  l2 
)

Case-insensitive comparison of two memory regions.

Parameters:
s1 
l1 
s2 
l2 
Returns:
0 if the memory regions are identical, -1 or +1 if they're not

Here is the caller graph for this function:

bstr* bstr_dup ( const bstr b  ) 

Create a new bstring by copying the provided bstring.

Parameters:
b 
Returns:
new bstring

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_dup_c ( const char *  data  ) 

Create a new bstring by copying the provided NUL-terminated string.

Parameters:
data 
Returns:
new bstring

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_dup_ex ( const bstr b,
size_t  offset,
size_t  len 
)

Create a new bstring by copying a part of the provided bstring.

Parameters:
b 
offset 
len 
Returns:
new bstring

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_dup_lower ( const bstr b  ) 

Create a copy of the provided bstring, then convert it to lowercase.

Parameters:
b 
Returns:
bstring copy

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_dup_mem ( const char *  data,
size_t  len 
)

Create a new bstring by copying the provided memory region.

Parameters:
data 
len 
Returns:
new bstring

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* bstr_expand ( bstr s,
size_t  newsize 
)

Expand a string to support at least newsize bytes. The input bstring is not changed if it is big enough to accommodate the desired size. If the input bstring is smaller, however, it is expanded. The pointer to the bstring may change. If the expansion fails, the original bstring is left untouched (it is not freed).

Parameters:
s 
newsize 
Returns:
new bstring, or NULL if memory allocation failed

Here is the caller graph for this function:

void bstr_free ( bstr **  b  ) 

Deallocate the supplied bstring and overwrite the supplied pointer to it. Allows a NULL bstring on input.

Parameters:
b 

Here is the caller graph for this function:

int bstr_index_of ( const bstr haystack,
const bstr needle 
)

Find needle in haystack.

Parameters:
haystack 
needle 
Returns:
position of the match, or -1 if there is no match

Here is the call graph for this function:

int bstr_index_of_c ( const bstr haystack,
const char *  needle 
)

Find index in the haystack, with the needle being a NUL-terminated string.

Parameters:
haystack 
needle 
Returns:
position of the match, or -1 if there is no match

Here is the call graph for this function:

Here is the caller graph for this function:

int bstr_index_of_c_nocase ( const bstr haystack,
const char *  needle 
)

Find index in the haystack, with the needle being a NUL-terminated string. Ignore case differences.

Parameters:
haystack 
needle 
Returns:
position of the match, or -1 if there is no match

Here is the call graph for this function:

Here is the caller graph for this function:

int bstr_index_of_mem ( const bstr haystack,
const char *  data2,
size_t  len2 
)

Find index in the haystack, with the needle being a memory region.

Parameters:
haystack 
data2 
len2 
Returns:
position of the match, or -1 if there is no match

Here is the caller graph for this function:

int bstr_index_of_mem_nocase ( const bstr haystack,
const char *  data2,
size_t  len2 
)

Find index in the haystack, with the needle being a memory region. Ignore case differences.

Parameters:
haystack 
data2 
len2 
Returns:
position of the match, or -1 if there is no match

Here is the caller graph for this function:

int bstr_index_of_nocase ( const bstr haystack,
const bstr needle 
)

Find index in the haystack. Ignore case differences.

Parameters:
haystack 
needle 
Returns:
position of the match, or -1 if there is no match

Here is the call graph for this function:

int bstr_rchr ( const bstr b,
int  c 
)

Return the last position of a character (byte).

Parameters:
b 
c 
Returns:
the last position of the character, or -1 if it could not be found
bstr* bstr_to_lowercase ( bstr b  ) 

Convert bstring to lowercase.

Parameters:
b 
Returns:
b

Here is the caller graph for this function:

void bstr_util_adjust_len ( bstr s,
size_t  newlen 
)

Adjust bstring length. You will need to use this method whenever you work directly with the string contents, and you end up changing its length.

Parameters:
s 
newlen 

Here is the caller graph for this function:

int64_t bstr_util_mem_to_pint ( const char *  data,
size_t  len,
int  base,
size_t *  lastlen 
)

Convert the memory region into a positive integer.

Parameters:
data Pointer to the start of the memory region.
len Length of the memory region.
base The desired base.
lastlen Points to the first unused byte in the region
Returns:
the number, or -1 if there wasn't a single valid digit, -2 if there was an overflow

Here is the caller graph for this function:

char* bstr_util_memdup_to_c ( const char *  data,
size_t  len 
)

Take the provided memory region and construct a NUL-terminated string, replacing NUL bytes with "\0".

Parameters:
data 
len 
Returns:
new NUL-terminated string

Here is the caller graph for this function:

char* bstr_util_strdup_to_c ( const bstr b  ) 

Create a new NUL-terminated string out of the provided bstring.

Parameters:
b 
Returns:
new NUL-terminated string

Here is the call graph for this function:


Generated on 28 Jan 2013 for HTP by  doxygen 1.6.1