AString
0.2
A Lightweight C Language String Library
|
宏定义 | |
#define | a_new(type, size) (type *)malloc(sizeof(type) * (size)) |
#define | P(lock) while(lock++){--lock;} |
#define | V(lock) --lock; |
#define | A_WARING(msg) do{fprintf(stderr, "[WARING] %s: [%s():%d] %s\n", __FILE__, __func__, __LINE__, msg);}while(0) |
#define | A_WARING_NOT_STRING A_WARING("A_IS_STRING Check falt!") |
函数 | |
AString * | a_string_new (const char *init) |
Create a new AString, initialized with the given string. | |
AString * | a_string_new_len (const char *init, asize len) |
Create a new AString with len length. if strlen(init) is larger than len, the length of new string will be len, otherwise the length will be strlen(init) | |
AString * | a_string_sized_new (asize size) |
Create a new AString with size allocated_len This is useful if you are going to add a lot of text to the string and don't want it to be reallocated too often. | |
AString * | a_string_assign (AString *string, const char *value) |
Copies the bytes from a string into an AString, destroying any previous contents. It is rather like the standard strcpy() function, except that you do not have to worry about having enough space to copy the string. | |
AString * | a_string_get_file_content (const char *filename) |
Create a new AString from a file. | |
AString * | a_string_dup (AString *source) |
duplicate an AString. | |
char * | a_string_dupstr (AString *source) |
duplicate char * from an AString. | |
AString * | a_string_append (AString *string, const char *value) |
Append a string to An AString. | |
AString * | a_string_append_c (AString *string, char c) |
Append a char to An AString. | |
AString * | a_string_append_unichar (AString *string, aunichar wc) |
Append a char to An AString. | |
AString * | a_string_append_len (AString *string, const char *value, asize len) |
Append a char to An AString. | |
AString * | a_string_prepend (AString *string, const char *value) |
Prepend a string to An AString. | |
AString * | a_string_prepend_c (AString *string, char c) |
Prepend a char to An AString. | |
AString * | a_string_prepend_unichar (AString *string, aunichar wc) |
Prepend a char to An AString. | |
AString * | a_string_prepend_len (AString *string, const char *value, asize len) |
Prepend a char to An AString. | |
AString * | a_string_insert (AString *string, asize pos, const char *value) |
Insert a string to An AString. | |
AString * | a_string_insert_c (AString *string, asize pos, char c) |
Insert a char to An AString. | |
AString * | a_string_insert_unichar (AString *string, asize pos, aunichar wc) |
Insert a char to An AString. | |
AString * | a_string_insert_len (AString *string, asize pos, const char *value, asize len) |
Insert a char to An AString. | |
char * | a_string_get_key (AString *string) |
Get the key of the string When a string is like key=value,it return key. | |
char * | a_string_get_value (AString *string) |
Get the value of the string When a string is like key=value,it return value. | |
AString * | a_string_overwrite (AString *string, asize pos, const char *value) |
overwrite an AString from pos | |
AString * | a_string_overwrite_len (AString *string, asize pos, const char *value, asize len) |
overwrite an AString from pos, and overwrite the most len char | |
AString * | a_string_erase (AString *string, asize pos, asize len) |
Erase something from an AString. | |
AString * | a_string_truncate (AString *string, asize len) |
Truncate an AString, leave the first len char. | |
AString * | a_string_set_size (AString *string, asize len) |
Set string's length if len is smaller than string->len, it'll be truncate,else it'll fill with undefined char. | |
AStringArray * | a_string_split (AString *string, const char *splitstr) |
Splits a string into array. | |
AString * | a_string_trim (AString *string) |
wipe off the head and tail's space or tab. " abc " will be "abc" | |
AString * | a_string_substring (AString *string, asize start, asize end) |
change an AString to it's substring. | |
AString * | a_string_substring_new (AString *string, asize start, asize end) |
Like substring, but it'll create a new AString to return. string will not to be changed. | |
char | a_string_get_char (AString *string, asize position) |
Get the char in an AString. | |
AString * | a_string_set_char (AString *string, asize position, char ch) |
Set the char in an AString. | |
int | a_string_find (AString *string, char *str, asize position) |
Find a string from an AString. | |
int | a_string_replace (AString *string, char *findstr, char *replacestr, asize position) |
Replace a string from an AString. | |
int | a_string_replace_all (AString *string, char *findstr, char *replacestr) |
Replace all string from an AString. | |
auint | a_string_hash (AString *string) |
Get the hashcode from a string. | |
aboolean | a_string_equal (AString *string, AString *string2) |
compare the two AStrings | |
void | a_string_free (AString *string) |
Frees the memory allocated for the AString. |
#define a_new | ( | type, | |
size | |||
) | (type *)malloc(sizeof(type) * (size)) |
#define A_WARING | ( | msg | ) | do{fprintf(stderr, "[WARING] %s: [%s():%d] %s\n", __FILE__, __func__, __LINE__, msg);}while(0) |
#define A_WARING_NOT_STRING A_WARING("A_IS_STRING Check falt!") |
#define P | ( | lock | ) | while(lock++){--lock;} |
#define V | ( | lock | ) | --lock; |
Append a string to An AString.
string | the destination AString |
value | the string you want to append |
Append a char to An AString.
string | the destination AString |
c | the char you want to append |
Append a char to An AString.
string | the destination AString |
value | the string you want to append |
len | the max char length to append |
Append a char to An AString.
string | the destination AString |
wc | the wide char you want to append |
Copies the bytes from a string into an AString, destroying any previous contents. It is rather like the standard strcpy() function, except that you do not have to worry about having enough space to copy the string.
string | the destination AString. Its current contents are destroyed. |
value | the string to copy into string |
duplicate an AString.
source | the source AString. |
char* a_string_dupstr | ( | AString * | source | ) |
duplicate char * from an AString.
the | source AString. |
compare the two AStrings
string | the first AString |
string2 | the second AString |
Erase something from an AString.
string | the AString you want to erase |
pos | the erase start |
len | How long you want to erase |
Find a string from an AString.
string | the source AString |
str | the string you want to find |
asize | the position where you want to find |
void a_string_free | ( | AString * | string | ) |
Frees the memory allocated for the AString.
string | the AString you want to free |
Get the char in an AString.
string | the source AString |
position | the position you want to get |
AString* a_string_get_file_content | ( | const char * | filename | ) |
Create a new AString from a file.
filename | the file you need to read. |
char* a_string_get_key | ( | AString * | string | ) |
Get the key of the string When a string is like key=value,it return key.
string | the source AString |
char* a_string_get_value | ( | AString * | string | ) |
Get the value of the string When a string is like key=value,it return value.
string | the source AString |
Get the hashcode from a string.
string | the AString you want to hash |
Insert a string to An AString.
string | the destination AString |
pos | the position where do you want to insert |
value | the string you want to insert |
Insert a char to An AString.
string | the destination AString |
pos | the position where do you want to insert |
c | the char you want to insert |
Insert a char to An AString.
string | the destination AString |
pos | the position where do you want to insert |
value | the string you want to insert |
len | the max char length to insert |
Insert a char to An AString.
string | the destination AString |
pos | the position where do you want to insert |
wc | the wide char you want to insert |
AString* a_string_new | ( | const char * | init | ) |
Create a new AString, initialized with the given string.
init | the initial text to copy into the string. |
Create a new AString with len length. if strlen(init) is larger than len, the length of new string will be len, otherwise the length will be strlen(init)
init | the initial text to copy into the string. |
len | the max length |
overwrite an AString from pos
string | the AString you want to overwrite |
pos | the overwrite position |
value | the string you want to overwrite to |
overwrite an AString from pos, and overwrite the most len char
string | the AString you want to overwrite |
pos | the overwrite position |
value | the string you want to overwrite to |
len | the max char to overwrite |
Prepend a string to An AString.
string | the destination AString |
value | the string you want to prepend |
Prepend a char to An AString.
string | the destination AString |
c | the char you want to prepend |
Prepend a char to An AString.
string | the destination AString |
value | the string you want to prepend |
len | the max char length to prepend |
Prepend a char to An AString.
string | the destination AString |
wc | the wide char you want to prepend |
Replace a string from an AString.
string | the source AString |
findstr | the string you want to find |
replacestr | the string you want to replace |
asize | the position where you want to replace |
int a_string_replace_all | ( | AString * | string, |
char * | findstr, | ||
char * | replacestr | ||
) |
Replace all string from an AString.
string | the source AString |
findstr | the string you want to find |
replacestr | the string you want to replace |
Set the char in an AString.
string | the source AString |
position | the position you want to get |
the | char you want to change to |
Set string's length if len is smaller than string->len, it'll be truncate,else it'll fill with undefined char.
string | the AString you want to set. |
len | the new length |
Create a new AString with size allocated_len This is useful if you are going to add a lot of text to the string and don't want it to be reallocated too often.
size | the default size of the space allocated to hold the string |
AStringArray* a_string_split | ( | AString * | string, |
const char * | splitstr | ||
) |
Splits a string into array.
string | the AString you want to split |
splitstr | the split string |
change an AString to it's substring.
string | the AString you want to sub |
start | where do you want to start |
end | where do you want to end |
Like substring, but it'll create a new AString to return. string will not to be changed.
string | the AString you want to sub |
start | where do you want to start |
end | where do you want to end |
wipe off the head and tail's space or tab. " abc " will be "abc"
string | the AString you want to trim |