AString  0.2
A Lightweight C Language String Library
/home/Tom/Projects/astring/astring.h文件参考

AString. 更多...

#include <stdlib.h>
#include <string.h>
#include "atype.h"

浏览该文件的源代码。

数据结构

struct  _AString
 The Main Struct. 更多...
struct  _AStringArray
 AStringArray Struct. 更多...

宏定义

#define A_STRING_FLAG   101
#define ZERO   '\0'
#define A_IS_STRING(string)   (*(auchar *)string == A_STRING_FLAG)
 A define. Check if a variable is an AString.

类型定义

typedef struct _AString AString
 Main Struct.
typedef struct _AStringArray AStringArray
 the array of some AString

函数

AStringa_string_new (const char *init)
 Create a new AString, initialized with the given string.
AStringa_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)
AStringa_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.
AStringa_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.
AStringa_string_dup (AString *source)
 duplicate an AString.
char * a_string_dupstr (AString *source)
 duplicate char * from an AString.
AStringa_string_get_file_content (const char *filename)
 Create a new AString from a file.
AStringa_string_append (AString *string, const char *value)
 Append a string to An AString.
AStringa_string_append_c (AString *string, char c)
 Append a char to An AString.
AStringa_string_append_unichar (AString *string, aunichar wc)
 Append a char to An AString.
AStringa_string_append_len (AString *string, const char *value, asize len)
 Append a char to An AString.
AStringa_string_prepend (AString *string, const char *value)
 Prepend a string to An AString.
AStringa_string_prepend_c (AString *string, char c)
 Prepend a char to An AString.
AStringa_string_prepend_unichar (AString *string, aunichar wc)
 Prepend a char to An AString.
AStringa_string_prepend_len (AString *string, const char *value, asize len)
 Prepend a char to An AString.
AStringa_string_insert (AString *string, asize pos, const char *value)
 Insert a string to An AString.
AStringa_string_insert_c (AString *string, asize pos, char c)
 Insert a char to An AString.
AStringa_string_insert_unichar (AString *string, asize pos, aunichar wc)
 Insert a char to An AString.
AStringa_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.
AStringa_string_overwrite (AString *string, asize pos, const char *value)
 overwrite an AString from pos
AStringa_string_overwrite_len (AString *string, asize pos, const char *value, asize len)
 overwrite an AString from pos, and overwrite the most len char
AStringa_string_erase (AString *string, asize pos, asize len)
 Erase something from an AString.
AStringa_string_truncate (AString *string, asize len)
 Truncate an AString, leave the first len char.
AStringa_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.
AStringa_string_trim (AString *string)
 wipe off the head and tail's space or tab. " abc " will be "abc"
AStringArraya_string_split (AString *string, const char *splitstr)
 Splits a string into array.
AStringa_string_substring (AString *string, asize start, asize end)
 change an AString to it's substring.
AStringa_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.
AStringa_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.
void a_string_free (AString *string)
 Frees the memory allocated for the 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

详细描述

AString.

作者:
Tom
日期:
2011-11-25
版本:
0.2
注解:
A AString is an object that handles the memory management of a C string for you. You can think of it as similar to a Java StringBuffer. In addition to the string itself, GString stores the length of the string, so can be used for binary data with embedded nul bytes. To access the C string managed by the AString string, simply use string->str.

宏定义文档

#define A_IS_STRING (   string)    (*(auchar *)string == A_STRING_FLAG)

A define. Check if a variable is an AString.

#define A_STRING_FLAG   101
#define ZERO   '\0'

类型定义文档

typedef struct _AString AString

Main Struct.

typedef struct _AStringArray AStringArray

the array of some AString


函数文档

AString* a_string_append ( AString string,
const char *  value 
)

Append a string to An AString.

参数:
stringthe destination AString
valuethe string you want to append
返回:
string
自从:
0.1
AString* a_string_append_c ( AString string,
char  c 
)

Append a char to An AString.

参数:
stringthe destination AString
cthe char you want to append
返回:
string
自从:
0.1
AString* a_string_append_len ( AString string,
const char *  value,
asize  len 
)

Append a char to An AString.

参数:
stringthe destination AString
valuethe string you want to append
lenthe max char length to append
返回:
string
自从:
0.1
AString* a_string_append_unichar ( AString string,
aunichar  wc 
)

Append a char to An AString.

参数:
stringthe destination AString
wcthe wide char you want to append
返回:
string
自从:
0.1
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.

参数:
stringthe destination AString. Its current contents are destroyed.
valuethe string to copy into string
返回:
string
自从:
0.1
AString* a_string_dup ( AString source)

duplicate an AString.

警告:
You should free the return string when you don't want to use it.
参数:
sourcethe source AString.
返回:
the new AString
自从:
0.1
char* a_string_dupstr ( AString source)

duplicate char * from an AString.

警告:
You should free the return string when you don't want to use it. When you just want the string to print or view, not change it, you can use source->str instead.
参数:
thesource AString.
返回:
the new AString
自从:
0.1
aboolean a_string_equal ( AString string,
AString string2 
)

compare the two AStrings

参数:
stringthe first AString
string2the second AString
返回:
TRUE or FALSE
自从:
0.1
AString* a_string_erase ( AString string,
asize  pos,
asize  len 
)

Erase something from an AString.

参数:
stringthe AString you want to erase
posthe erase start
lenHow long you want to erase
返回:
string
自从:
0.1
int a_string_find ( AString string,
char *  str,
asize  position 
)

Find a string from an AString.

参数:
stringthe source AString
strthe string you want to find
asizethe position where you want to find
返回:
the position where the str at, return -1 when no found.
自从:
0.1
void a_string_free ( AString string)

Frees the memory allocated for the AString.

参数:
stringthe AString you want to free
自从:
0.1
char a_string_get_char ( AString string,
asize  position 
)

Get the char in an AString.

参数:
stringthe source AString
positionthe position you want to get
返回:
the char in position
自从:
0.1
AString* a_string_get_file_content ( const char *  filename)

Create a new AString from a file.

警告:
You should free the return string when you don't want to use it.
参数:
filenamethe file you need to read.
返回:
the new AString
自从:
0.1
char* a_string_get_key ( AString string)

Get the key of the string When a string is like key=value,it return key.

警告:
You should free the return string when you don't want to use it.
参数:
stringthe source AString
返回:
a new string
自从:
0.2
char* a_string_get_value ( AString string)

Get the value of the string When a string is like key=value,it return value.

警告:
You should free the return string when you don't want to use it.
参数:
stringthe source AString
返回:
a new string
自从:
0.2
auint a_string_hash ( AString string)

Get the hashcode from a string.

参数:
stringthe AString you want to hash
返回:
the hashcode of the string
注解:
using BKDRHash
自从:
0.1
AString* a_string_insert ( AString string,
asize  pos,
const char *  value 
)

Insert a string to An AString.

参数:
stringthe destination AString
posthe position where do you want to insert
valuethe string you want to insert
返回:
string
自从:
0.1
AString* a_string_insert_c ( AString string,
asize  pos,
char  c 
)

Insert a char to An AString.

参数:
stringthe destination AString
posthe position where do you want to insert
cthe char you want to insert
返回:
string
自从:
0.1
AString* a_string_insert_len ( AString string,
asize  pos,
const char *  value,
asize  len 
)

Insert a char to An AString.

参数:
stringthe destination AString
posthe position where do you want to insert
valuethe string you want to insert
lenthe max char length to insert
返回:
string
自从:
0.1
AString* a_string_insert_unichar ( AString string,
asize  pos,
aunichar  wc 
)

Insert a char to An AString.

参数:
stringthe destination AString
posthe position where do you want to insert
wcthe wide char you want to insert
返回:
string
自从:
0.1
AString* a_string_new ( const char *  init)

Create a new AString, initialized with the given string.

参数:
initthe initial text to copy into the string.
返回:
a new AString
自从:
0.1
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)

参数:
initthe initial text to copy into the string.
lenthe max length
返回:
a new AString
自从:
0.1
AString* a_string_overwrite ( AString string,
asize  pos,
const char *  value 
)

overwrite an AString from pos

参数:
stringthe AString you want to overwrite
posthe overwrite position
valuethe string you want to overwrite to
返回:
string
自从:
0.1
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

参数:
stringthe AString you want to overwrite
posthe overwrite position
valuethe string you want to overwrite to
lenthe max char to overwrite
返回:
string
自从:
0.1
AString* a_string_prepend ( AString string,
const char *  value 
)

Prepend a string to An AString.

参数:
stringthe destination AString
valuethe string you want to prepend
返回:
string
自从:
0.1
AString* a_string_prepend_c ( AString string,
char  c 
)

Prepend a char to An AString.

参数:
stringthe destination AString
cthe char you want to prepend
返回:
string
自从:
0.1
AString* a_string_prepend_len ( AString string,
const char *  value,
asize  len 
)

Prepend a char to An AString.

参数:
stringthe destination AString
valuethe string you want to prepend
lenthe max char length to prepend
返回:
string
自从:
0.1
AString* a_string_prepend_unichar ( AString string,
aunichar  wc 
)

Prepend a char to An AString.

参数:
stringthe destination AString
wcthe wide char you want to prepend
返回:
string
自从:
0.1
int a_string_replace ( AString string,
char *  findstr,
char *  replacestr,
asize  position 
)

Replace a string from an AString.

参数:
stringthe source AString
findstrthe string you want to find
replacestrthe string you want to replace
asizethe position where you want to replace
返回:
the position where the str at, return -1 when no found.
自从:
0.1
int a_string_replace_all ( AString string,
char *  findstr,
char *  replacestr 
)

Replace all string from an AString.

参数:
stringthe source AString
findstrthe string you want to find
replacestrthe string you want to replace
返回:
the count you have replace.
参见:
a_string_replace
自从:
0.1
AString* a_string_set_char ( AString string,
asize  position,
char  ch 
)

Set the char in an AString.

参数:
stringthe source AString
positionthe position you want to get
thechar you want to change to
返回:
the char in position
自从:
0.1
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.

参数:
stringthe AString you want to set.
lenthe new length
返回:
string
自从:
0.1
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.

参数:
sizethe default size of the space allocated to hold the string
返回:
a new AString
自从:
0.1
AStringArray* a_string_split ( AString string,
const char *  splitstr 
)

Splits a string into array.

参数:
stringthe AString you want to split
splitstrthe split string
返回:
string
自从:
0.2
AString* a_string_substring ( AString string,
asize  start,
asize  end 
)

change an AString to it's substring.

参数:
stringthe AString you want to sub
startwhere do you want to start
endwhere do you want to end
返回:
string
注解:
Example:
str = astring_new("01234567890");
astring_substring(str, 2, 5);
printf("%s\n", str->str);
Run: 2345
自从:
0.1
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.

警告:
You should free the return string when you don't want to use it.
参数:
stringthe AString you want to sub
startwhere do you want to start
endwhere do you want to end
返回:
string
自从:
0.1
AString* a_string_trim ( AString string)

wipe off the head and tail's space or tab. " abc " will be "abc"

参数:
stringthe AString you want to trim
返回:
string
自从:
0.1
AString* a_string_truncate ( AString string,
asize  len 
)

Truncate an AString, leave the first len char.

参数:
stringthe AString you want to truncate
lenHow long you want to leave
返回:
string
自从:
0.1