HTP
0.3
|
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "bstr_builder.h"
Go to the source code of this file.
Data Structures | |
struct | bstr_t |
Macros | |
#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 | |
bstr * | bstr_alloc (size_t newsize) |
void | bstr_free (bstr **s) |
bstr * | bstr_expand (bstr *s, size_t newsize) |
bstr * | bstr_dup (const bstr *b) |
bstr * | bstr_dup_ex (const bstr *b, size_t offset, size_t len) |
bstr * | bstr_dup_c (const char *) |
bstr * | bstr_dup_mem (const char *data, size_t len) |
bstr * | bstr_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) |
bstr * | bstr_to_lowercase (bstr *) |
bstr * | bstr_add (bstr *, const bstr *) |
bstr * | bstr_add_c (bstr *, const char *) |
bstr * | bstr_add_mem (bstr *, const char *, size_t) |
bstr * | bstr_add_noex (bstr *, const bstr *) |
bstr * | bstr_add_c_noex (bstr *, const char *) |
bstr * | bstr_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 *) |
#define bstr_len | ( | X | ) | ((*(bstr_t *)(X)).len) |
#define bstr_ptr | ( | X | ) | ( ((*(bstr_t *)(X)).ptr == NULL) ? ((char *)(X) + sizeof(bstr_t)) : (char *)(*(bstr_t *)(X)).ptr ) |
#define bstr_size | ( | X | ) | ((*(bstr_t *)(X)).size) |
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.
destination | |
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.
destination | |
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 | |
source |
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.
destination | |
data | |
len |
Append a memory region to destination. If there is not enough room in the destination, copy as many bytes as possible.
destination | |
data | |
len |
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.
destination | |
source |
bstr* bstr_alloc | ( | size_t | len | ) |
Allocate a zero-length bstring, but reserving space for at least len bytes.
len |
Checks whether bstring begins with another bstring. Case sensitive.
haystack | |
needle |
int bstr_begins_with_c | ( | const bstr * | haystack, |
const char * | needle | ||
) |
Checks whether bstring begins with NUL-terminated string. Case sensitive.
haystack | |
needle |
int bstr_begins_with_mem | ( | const bstr * | haystack, |
const char * | data, | ||
size_t | len | ||
) |
Checks whether bstring begins with memory block. Case sensitive.
haystack | |
needle |
int bstr_begins_with_mem_nocase | ( | const bstr * | haystack, |
const char * | data, | ||
size_t | len | ||
) |
Checks whether bstring begins with memory block. Case insensitive.
haystack | |
needle |
Checks whether bstring begins with another bstring. Case insensitive.
haystack | |
needle |
int bstr_begins_withc_nocase | ( | const bstr * | haystack, |
const char * | needle | ||
) |
Checks whether bstring begins with NUL-terminated string. Case insensitive.
haystack | |
needle |
unsigned char bstr_char_at | ( | const bstr * | s, |
size_t | pos | ||
) |
Return the character (byte) at the given position.
s | |
pos |
void bstr_chop | ( | bstr * | s | ) |
Remove one byte from the end of the string, provided the it contains at least one byte.
s |
int bstr_chr | ( | const bstr * | b, |
int | c | ||
) |
Return the first position of the provided character (byte).
b | |
c |
Case-sensitive comparison two bstrings.
b1 | |
b2 |
int bstr_cmp_c | ( | const bstr * | b, |
const char * | c | ||
) |
Case-sensitive comparison of a bstring with a NUL-terminated string.
b | |
c |
int bstr_cmp_c_nocase | ( | const bstr * | b, |
const char * | c | ||
) |
Case-insensitive comparison of a bstring with a NUL-terminated string.
b | |
c |
int bstr_cmp_ex | ( | const char * | s1, |
size_t | l1, | ||
const char * | s2, | ||
size_t | l2 | ||
) |
Case-sensitive comparison of two memory regions.
s1 | |
l1 | |
s2 | |
l2 |
Case-insensitive comparison two bstrings.
b1 | |
b2 |
int bstr_cmp_nocase_ex | ( | const char * | s1, |
size_t | l1, | ||
const char * | s2, | ||
size_t | l2 | ||
) |
Case-insensitive comparison of two memory regions.
s1 | |
l1 | |
s2 | |
l2 |
Create a new bstring by copying the provided bstring.
b |
bstr* bstr_dup_c | ( | const char * | data | ) |
Create a new bstring by copying the provided NUL-terminated string.
data |
Create a new bstring by copying a part of the provided bstring.
b | |
offset | |
len |
Create a copy of the provided bstring, then convert it to lowercase.
b |
bstr* bstr_dup_mem | ( | const char * | data, |
size_t | len | ||
) |
Create a new bstring by copying the provided memory region.
data | |
len |
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).
s | |
newsize |
void bstr_free | ( | bstr ** | b | ) |
Deallocate the supplied bstring and overwrite the supplied pointer to it. Allows a NULL bstring on input.
b |
Find needle in haystack.
haystack | |
needle |
int bstr_index_of_c | ( | const bstr * | haystack, |
const char * | needle | ||
) |
Find index in the haystack, with the needle being a NUL-terminated string.
haystack | |
needle |
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.
haystack | |
needle |
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.
haystack | |
data2 | |
len2 |
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.
haystack | |
data2 | |
len2 |
Find index in the haystack. Ignore case differences.
haystack | |
needle |
int bstr_rchr | ( | const bstr * | b, |
int | c | ||
) |
Return the last position of a character (byte).
b | |
c |
Convert bstring to lowercase.
b |
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.
s | |
newlen |
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.
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 |
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".
data | |
len |
char* bstr_util_strdup_to_c | ( | const bstr * | b | ) |
Create a new NUL-terminated string out of the provided bstring.
b |