HTP
0.5
|
#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) ((*(X)).len) |
#define | bstr_size(X) ((*(X)).size) |
#define | bstr_ptr(X) ( ((*(X)).realptr == NULL) ? ((unsigned char *)(X) + sizeof(bstr)) : (unsigned char *)(*(X)).realptr ) |
#define | bstr_realptr(X) ((*(X)).realptr) |
Typedefs | |
typedef struct bstr_t | bstr |
Functions | |
bstr * | bstr_add (bstr *bdestination, const bstr *bsource) |
bstr * | bstr_add_c (bstr *b, const char *cstr) |
bstr * | bstr_add_c_noex (bstr *b, const char *cstr) |
bstr * | bstr_add_mem (bstr *b, const void *data, size_t len) |
bstr * | bstr_add_mem_noex (bstr *b, const void *data, size_t len) |
bstr * | bstr_add_noex (bstr *bdestination, const bstr *bsource) |
void | bstr_adjust_len (bstr *b, size_t newlen) |
void | bstr_adjust_realptr (bstr *b, void *newrealptr) |
void | bstr_adjust_size (bstr *b, size_t newsize) |
bstr * | bstr_alloc (size_t size) |
int | bstr_begins_with (const bstr *bhaystack, const bstr *bneedle) |
int | bstr_begins_with_c (const bstr *bhaystack, const char *cneedle) |
int | bstr_begins_with_c_nocase (const bstr *bhaystack, const char *cneedle) |
int | bstr_begins_with_mem (const bstr *bhaystack, const void *data, size_t len) |
int | bstr_begins_with_mem_nocase (const bstr *bhaystack, const void *data, size_t len) |
int | bstr_begins_with_nocase (const bstr *bhaystack, const bstr *cneedle) |
int | bstr_char_at (const bstr *b, size_t pos) |
int | bstr_char_at_end (const bstr *b, size_t pos) |
void | bstr_chop (bstr *b) |
int | bstr_chr (const bstr *b, int c) |
int | bstr_cmp (const bstr *b1, const bstr *b2) |
int | bstr_cmp_c (const bstr *b, const char *cstr) |
int | bstr_cmp_c_nocase (const bstr *b, const char *cstr) |
int | bstr_cmp_mem (const bstr *b, const void *data, size_t len) |
int | bstr_cmp_mem_nocase (const bstr *b, const void *data, size_t len) |
int | bstr_cmp_nocase (const bstr *b1, const bstr *b2) |
bstr * | bstr_dup (const bstr *b) |
bstr * | bstr_dup_c (const char *cstr) |
bstr * | bstr_dup_ex (const bstr *b, size_t offset, size_t len) |
bstr * | bstr_dup_lower (const bstr *b) |
bstr * | bstr_dup_mem (const void *data, size_t len) |
bstr * | bstr_expand (bstr *b, size_t newsize) |
void | bstr_free (bstr *b) |
int | bstr_index_of (const bstr *bhaystack, const bstr *bneedle) |
int | bstr_index_of_nocase (const bstr *bhaystack, const bstr *bneedle) |
int | bstr_index_of_c (const bstr *bhaystack, const char *cneedle) |
int | bstr_index_of_c_nocase (const bstr *bhaystack, const char *cneedle) |
int | bstr_index_of_mem (const bstr *bhaystack, const void *data, size_t len) |
int | bstr_index_of_mem_nocase (const bstr *bhaystack, const void *data, size_t len) |
int | bstr_rchr (const bstr *b, int c) |
bstr * | bstr_to_lowercase (bstr *b) |
int | bstr_util_cmp_mem (const void *data1, size_t len1, const void *data2, size_t len2) |
int | bstr_util_cmp_mem_nocase (const void *data1, size_t len1, const void *data2, size_t len2) |
int64_t | bstr_util_mem_to_pint (const void *data, size_t len, int base, size_t *lastlen) |
int | bstr_util_mem_index_of_c (const void *data, size_t len, const char *cstr) |
int | bstr_util_mem_index_of_c_nocase (const void *data, size_t len, const char *cstr) |
int | bstr_util_mem_index_of_mem (const void *data1, size_t len1, const void *data2, size_t len2) |
int | bstr_util_mem_index_of_mem_nocase (const void *data1, size_t len1, const void *data2, size_t len2) |
void | bstr_util_mem_trim (unsigned char **data, size_t *len) |
char * | bstr_util_memdup_to_c (const void *data, size_t len) |
char * | bstr_util_strdup_to_c (const bstr *b) |
bstr * | bstr_wrap_c (const char *cstr) |
bstr * | bstr_wrap_mem (const void *data, size_t len) |
#define bstr_len | ( | X | ) | ((*(X)).len) |
#define bstr_ptr | ( | X | ) | ( ((*(X)).realptr == NULL) ? ((unsigned char *)(X) + sizeof(bstr)) : (unsigned char *)(*(X)).realptr ) |
#define bstr_realptr | ( | X | ) | ((*(X)).realptr) |
#define bstr_size | ( | X | ) | ((*(X)).size) |
Append source bstring to destination bstring, growing destination if necessary. If the destination bstring 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.
[in] | bdestination | |
[in] | bsource |
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.
[in] | b | |
[in] | cstr |
Append as many bytes from the source to destination bstring. The destination storage will not be expanded if there is not enough space in it already to accommodate all of the data.
[in] | b | |
[in] | cstr |
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.
[in] | b | |
[in] | data | |
[in] | len |
Append as many bytes from the source to destination bstring. The destination storage will not be expanded if there is not enough space in it already to accommodate all of the data.
[in] | b | |
[in] | data | |
[in] | len |
Append as many bytes from the source bstring to destination bstring. The destination storage will not be expanded if there is not enough space in it already to accommodate all of the data.
[in] | bdestination | |
[in] | bsource |
void bstr_adjust_len | ( | bstr * | b, |
size_t | newlen | ||
) |
Adjust bstring length. You will need to use this method whenever you work directly with the string contents, and end up changing its length by direct structure manipulation.
[in] | b | |
[in] | newlen |
void bstr_adjust_realptr | ( | bstr * | b, |
void * | newrealptr | ||
) |
Change the external pointer used by bstring. You will need to use this function only if you're messing with bstr internals. Use with caution.
[in] | b | |
[in] | newrealptr |
void bstr_adjust_size | ( | bstr * | b, |
size_t | newsize | ||
) |
Adjust bstring size. This does not change the size of the storage behind the bstring, just changes the field that keeps track of how many bytes there are in the storage. You will need to use this function only if you're messing with bstr internals. Use with caution.
[in] | b | |
[in] | newsize |
bstr* bstr_alloc | ( | size_t | size | ) |
Allocate a zero-length bstring, reserving space for at least size bytes.
[in] | size |
Checks whether bstring begins with another bstring. Case sensitive.
[in] | bhaystack | |
[in] | bneedle |
int bstr_begins_with_c | ( | const bstr * | bhaystack, |
const char * | cneedle | ||
) |
Checks whether bstring begins with NUL-terminated string. Case sensitive.
[in] | bhaystack | |
[in] | cneedle |
int bstr_begins_with_c_nocase | ( | const bstr * | bhaystack, |
const char * | cneedle | ||
) |
Checks whether bstring begins with NUL-terminated string. Case insensitive.
[in] | bhaystack | |
[in] | cneedle |
int bstr_begins_with_mem | ( | const bstr * | bhaystack, |
const void * | data, | ||
size_t | len | ||
) |
Checks whether the bstring begins with the given memory block. Case sensitive.
[in] | bhaystack | |
[in] | data | |
[in] | len |
int bstr_begins_with_mem_nocase | ( | const bstr * | bhaystack, |
const void * | data, | ||
size_t | len | ||
) |
Checks whether bstring begins with memory block. Case insensitive.
[in] | bhaystack | |
[in] | data | |
[in] | len |
Checks whether bstring begins with another bstring. Case insensitive.
[in] | bhaystack | |
[in] | cneedle |
int bstr_char_at | ( | const bstr * | b, |
size_t | pos | ||
) |
Return the byte at the given position.
[in] | b | |
[in] | pos |
int bstr_char_at_end | ( | const bstr * | b, |
size_t | pos | ||
) |
Return the byte at the given position, counting from the end of the string (e.g., byte at position 0 is the last byte in the string.)
[in] | b | |
[in] | pos |
void bstr_chop | ( | bstr * | b | ) |
Remove the last byte from bstring, assuming it contains at least one byte. This function will not reduce the storage that backs the string, only the amount of data used.
[in] | b |
int bstr_chr | ( | const bstr * | b, |
int | c | ||
) |
Return the first position of the provided byte.
[in] | b | |
[in] | c |
Case-sensitive comparison of two bstrings.
[in] | b1 | |
[in] | b2 |
int bstr_cmp_c | ( | const bstr * | b, |
const char * | cstr | ||
) |
Case-sensitive comparison of a bstring and a NUL-terminated string.
[in] | b | |
[in] | cstr |
int bstr_cmp_c_nocase | ( | const bstr * | b, |
const char * | cstr | ||
) |
Case-insensitive comparison of a bstring with a NUL-terminated string.
[in] | b | |
[in] | cstr |
int bstr_cmp_mem | ( | const bstr * | b, |
const void * | data, | ||
size_t | len | ||
) |
Performs a case-sensitive comparison of a bstring with a memory region.
[in] | b | |
[in] | data | |
[in] | len |
int bstr_cmp_mem_nocase | ( | const bstr * | b, |
const void * | data, | ||
size_t | len | ||
) |
Performs a case-insensitive comparison of a bstring with a memory region.
[in] | b | |
[in] | data | |
[in] | len |
Case-insensitive comparison two bstrings.
[in] | b1 | |
[in] | b2 |
Create a new bstring by copying the provided bstring.
[in] | b |
bstr* bstr_dup_c | ( | const char * | cstr | ) |
Create a new bstring by copying the provided NUL-terminated string.
[in] | cstr |
Create a new bstring by copying a part of the provided bstring.
[in] | b | |
[in] | offset | |
[in] | len |
Create a copy of the provided bstring, then convert it to lowercase.
[in] | b |
bstr* bstr_dup_mem | ( | const void * | data, |
size_t | len | ||
) |
Create a new bstring by copying the provided memory region.
[in] | data | |
[in] | len |
Expand internal bstring storage to support at least newsize bytes. The storage is not expanded if the current size is equal or greater to newsize. Because realloc is used underneath, the old pointer to bstring may no longer be valid after this function completes successfully.
[in] | b | |
[in] | newsize |
void bstr_free | ( | bstr * | b | ) |
Deallocate the supplied bstring instance and set it to NULL. Allows NULL on input.
[in] | b |
Find the needle in the haystack.
[in] | bhaystack | |
[in] | bneedle |
int bstr_index_of_c | ( | const bstr * | bhaystack, |
const char * | cneedle | ||
) |
Find the needle in the haystack, with the needle being a NUL-terminated string.
[in] | bhaystack | |
[in] | cneedle |
int bstr_index_of_c_nocase | ( | const bstr * | bhaystack, |
const char * | cneedle | ||
) |
Find the needle in the haystack, with the needle being a NUL-terminated string. Ignore case differences.
[in] | bhaystack | |
[in] | cneedle |
int bstr_index_of_mem | ( | const bstr * | bhaystack, |
const void * | data, | ||
size_t | len | ||
) |
Find the needle in the haystack, with the needle being a memory region.
[in] | bhaystack | |
[in] | data | |
[in] | len |
int bstr_index_of_mem_nocase | ( | const bstr * | bhaystack, |
const void * | data, | ||
size_t | len | ||
) |
Find the needle in the haystack, with the needle being a memory region. Ignore case differences.
[in] | bhaystack | |
[in] | data | |
[in] | len |
Find the needle in the haystack, ignoring case differences.
[in] | bhaystack | |
[in] | bneedle |
int bstr_rchr | ( | const bstr * | b, |
int | c | ||
) |
Return the last position of a character (byte).
[in] | b | |
[in] | c |
Convert bstring to lowercase. This function converts the supplied string, it does not create a new string.
[in] | b |
int bstr_util_cmp_mem | ( | const void * | data1, |
size_t | len1, | ||
const void * | data2, | ||
size_t | len2 | ||
) |
Case-sensitive comparison of two memory regions.
[in] | data1 | |
[in] | len1 | |
[in] | data2 | |
[in] | len2 |
int bstr_util_cmp_mem_nocase | ( | const void * | data1, |
size_t | len1, | ||
const void * | data2, | ||
size_t | len2 | ||
) |
Case-insensitive comparison of two memory regions.
[in] | data1 | |
[in] | len1 | |
[in] | data2 | |
[in] | len2 |
int bstr_util_mem_index_of_c | ( | const void * | data, |
size_t | len, | ||
const char * | cstr | ||
) |
Searches a memory block for the given NUL-terminated string. Case sensitive.
[in] | data | |
[in] | len | |
[in] | cstr |
int bstr_util_mem_index_of_c_nocase | ( | const void * | data, |
size_t | len, | ||
const char * | cstr | ||
) |
Searches a memory block for the given NUL-terminated string. Case insensitive.
[in] | data | |
[in] | len | |
[in] | cstr |
int bstr_util_mem_index_of_mem | ( | const void * | data1, |
size_t | len1, | ||
const void * | data2, | ||
size_t | len2 | ||
) |
Searches the haystack memory block for the needle memory block. Case sensitive.
data1 | |
len1 | |
data2 | |
len2 |
int bstr_util_mem_index_of_mem_nocase | ( | const void * | data1, |
size_t | len1, | ||
const void * | data2, | ||
size_t | len2 | ||
) |
Searches the haystack memory block for the needle memory block. Case sensitive.
data1 | |
len1 | |
data2 | |
len2 |
int64_t bstr_util_mem_to_pint | ( | const void * | data, |
size_t | len, | ||
int | base, | ||
size_t * | lastlen | ||
) |
Convert contents of a memory region to a positive integer.
[in] | data | |
[in] | len | |
[in] | base | The desired number base. |
[in] | lastlen | Points to the first unused byte in the region |
void bstr_util_mem_trim | ( | unsigned char ** | data, |
size_t * | len | ||
) |
Removes whitespace from the beginning and the end of a memory region. The data itself is not modified; this function only adjusts the provided pointers.
[in,out] | data | |
[in,out] | len |
char* bstr_util_memdup_to_c | ( | const void * | data, |
size_t | len | ||
) |
Take the provided memory region, allocate a new memory buffer, and construct a NUL-terminated string, replacing each NUL byte with "\0" (two bytes). The caller is responsible to keep track of the allocated memory area and free it once it is no longer needed.
[in] | data | |
[in] | len |
char* bstr_util_strdup_to_c | ( | const bstr * | b | ) |
Create a new NUL-terminated string out of the provided bstring. If NUL bytes are contained in the bstring, each will be replaced with "\0" (two characters). The caller is responsible to keep track of the allocated memory area and free it once it is no longer needed.
[in] | b |
bstr* bstr_wrap_c | ( | const char * | cstr | ) |
Create a new bstring from the provided NUL-terminated string and without copying the data. The caller must ensure that the input string continues to point to a valid memory location for as long as the bstring is used.
[in] | cstr |
bstr* bstr_wrap_mem | ( | const void * | data, |
size_t | len | ||
) |
Create a new bstring from the provided memory buffer without copying the data. The caller must ensure that the buffer remains valid for as long as the bstring is used.
[in] | data | |
[in] | len |