Macros | |
#define | C_Str_has_word(self, word) C_Str_is_word_in_string ((self), (word)) |
#define | C_Str_has_letter(self, letter) C_Str_is_letter_in_string ((self), (letter)) |
#define | C_Str_compare_icase(self, string) C_Str_compare_ignore_case ((self), (string)) |
#define | C_Str_compare_icase_obj(self, compare) C_Str_compare_ignore_case_obj ((self), (compare)) |
#define | C_Str_free_split(tab) C_Str_free_split_tab ((tab)) |
#define | C_Str_free_tab(tab) C_Str_free_split_tab ((tab)) |
#define | C_Str_ltrim(self) C_Str_lstrip ((self)) |
#define | C_Str_rtrim(self) C_Str_rstrip ((self)) |
#define | C_Str_trim(self) C_Str_strip ((self)) |
#define | C_Str_set_text(self, string) C_Str_fill ((self), (string)) |
#define | C_Str_is_equal(obj1, obj2) C_Str_compare_to_object ((obj1), (obj2)) |
Typedefs | |
typedef struct _C_Str | C_Str |
Enumerations | |
enum | C_Str_error { C_STR_END_STR = -1, C_STR_NO_ERR = 0, C_STR_DYN_ALLOC_ERR, C_STR_NULL_ARG, C_STR_BAD_STR_LEN, C_STR_FILE_ERR, C_STR_WRITE_ERR, C_STR_TABLE_SET_ERR, C_STR_BAD_INDEX, C_STR_NO_CHAR_FOUND, C_STR_INVALID_SIZE, C_STR_NB } |
Functions | |
const char * | C_Str_get_id (void) |
const char * | C_Str_get_version (void) |
int | C_Str_get_version_major (void) |
int | C_Str_get_version_minor (void) |
int | C_Str_get_version_revision (void) |
C_Str * | C_Str_new (void) |
C_Str * | C_Str_new_len (size_t size) |
C_Str * | C_Str_new_with_text (char const *const s_str) |
C_Str * | C_Str_new_from_file (char const *const s_file) |
C_Str * | C_Str_new_from_sub_string (char const *const s_str, size_t start, size_t end) |
C_Str * | C_Str_new_from_sub_string_obj (C_Str *const self, size_t start, size_t end) |
void | C_Str_destroy (C_Str **const self) |
bool | C_Str_write_to_file (C_Str *const self, const char *filename, const char *mode) |
C_Str_error | C_Str_get_error (C_Str *const self) |
void * | C_Str_access_to_generic_buff (C_Str *const self) |
const char * | C_Str_get (C_Str *const self) |
char * | C_Str_get_new_string (C_Str *const self) |
size_t | C_Str_len (C_Str *const self) |
bool | C_Str_is_empty (C_Str *const self) |
bool | C_Str_cat_with_str (C_Str *const self, char const *const s_str,...) |
bool | C_Str_cat (C_Str *const but, C_Str *const source,...) |
bool | C_Str_nth_to_upper (C_Str *const self, size_t char_pos) |
bool | C_Str_nth_to_lower (C_Str *const self, size_t char_pos) |
bool | C_Str_to_upper (C_Str *const self) |
bool | C_Str_to_lower (C_Str *const self) |
bool | C_Str_capitalize (C_Str *const self) |
bool | C_Str_swap_case (C_Str *const self) |
bool | C_Str_lstrip (C_Str *const self) |
bool | C_Str_rstrip (C_Str *const self) |
bool | C_Str_strip (C_Str *const self) |
bool | C_Str_replace_string (C_Str *const self, size_t start, size_t lenght, char const *const s_str) |
bool | C_Str_replace_letter (C_Str *const self, const char old_letter, const char new_letter) |
int | C_Str_index (C_Str *const self, const char letter) |
int | C_Str_r_index (C_Str *const self, const char letter) |
char | C_Str_char_at (C_Str *const self, size_t index) |
char * | C_Str_nth_string_copy (C_Str *const self, int len) |
C_Str * | C_Str_nth_string_copy_obj (C_Str *const self, int len) |
char * | C_Str_string_copy (C_Str *const self) |
C_Str * | C_Str_string_copy_obj (C_Str *const self) |
bool | C_Str_cut (C_Str *const self, size_t start, size_t end) |
size_t | C_Str_how_much_letter (C_Str *const self, const char letter) |
size_t | C_Str_how_much_word (C_Str *const self, char const *const word) |
bool | C_Str_is_word_in_string (C_Str *const self, char const *const word) |
bool | C_Str_is_letter_in_string (C_Str *const self, const char letter) |
char * | C_Str_sub_string (C_Str *const self, const char *sub_string) |
char * | C_Str_sub_string_obj (C_Str *const self, C_Str *const sub_string) |
char * | C_Str_sub_string_by_val (C_Str *const self, size_t start, size_t end) |
char ** | C_Str_split (C_Str *const self, char const *const sep) |
void | C_Str_free_split_tab (char ***tab) |
bool | C_Str_compare_ignore_case (C_Str *const self, char const *const s_str) |
bool | C_Str_compare_ignore_case_obj (C_Str *const self, C_Str *const compare) |
bool | C_Str_compare (C_Str *const self, char const *const s_str) |
bool | C_Str_compare_obj (C_Str *const self, C_Str *const compare) |
bool | C_Str_compare_to_object (C_Str *const s1, C_Str *const s2) |
bool | C_Str_clear (C_Str *const self) |
bool | C_Str_fill (C_Str *const self, char const *const s_str) |
bool | C_Str_n_fill (C_Str *const self, char c, size_t len) |
bool | C_Str_start_with (C_Str *const self, char const *const s_str) |
int | C_Str_start_with_obj (C_Str *const self, C_Str *const start) |
bool | C_Str_end_with (C_Str *const self, char const *const s_str) |
bool | C_Str_end_with_obj (C_Str *const self, C_Str *const end) |
bool | C_Str_reverse (C_Str *const self) |
C_Str * | C_Str_clone (C_Str *const self) |
C_Str is a library for the management of character strings as found in higher-level, essentially object oriented, languages such as e.g. Java, C++, C# or Python. C_Str was created with the objective to gather together these various string processing functions into a single library for the C language. C_Str is based on an object (of the same name) which is an opaque structure for safety with respect to handling of memory that is only done internally. For the end user, this is virtually the same to use C_Str rather than any string object from another language. A special feature of this C_Str object is that, during the various string manipulation operations, once the initial instance created, the address of the object remains constant even after a reallocation of memory resulting from an increase of string length. This feature was designed so as to enable comparison, not between differents strings, but between different objects or rather between pointers on different string objects.
Here is an example of how to use the library:
The output on the console:
#define C_Str_has_word | ( | self, | |
word | |||
) | C_Str_is_word_in_string ((self), (word)) |
Substitution macro for the function C_Str_is_word_in_string.
self | Pointer to object instance. |
word | Word whose existence is sought in the string. |
#define C_Str_has_letter | ( | self, | |
letter | |||
) | C_Str_is_letter_in_string ((self), (letter)) |
Substitution macro for the function C_Str_is_letter_in_string.
self | Pointer to object instance. |
letter | Letter whose existence is sought in the string. |
#define C_Str_compare_icase | ( | self, | |
string | |||
) | C_Str_compare_ignore_case ((self), (string)) |
Substitution macro for the function C_Str_compare_ignore_case.
self | Pointer to object instance. |
string | String to compare with that contained in object instance. |
#define C_Str_compare_icase_obj | ( | self, | |
compare | |||
) | C_Str_compare_ignore_case_obj ((self), (compare)) |
Substitution macro for the function C_Str_compare_ignore_case_obj.
self | Pointer to object instance. |
compare | Pointer to another C_Str instance for comparison. |
#define C_Str_free_split | ( | tab) | C_Str_free_split_tab ((tab)) |
Substitution macro for the function C_Str_free_split_tab.
tab | Pointer to the array of strings created by the function C_Str_split. |
#define C_Str_free_tab | ( | tab) | C_Str_free_split_tab ((tab)) |
Substitution macro for the function C_Str_free_split_tab.
tab | Pointer to the array of strings created by the function C_Str_split. |
#define C_Str_ltrim | ( | self) | C_Str_lstrip ((self)) |
Substitution macro for the function C_Str_lstrip.
self | Pointer to object instance. |
#define C_Str_rtrim | ( | self) | C_Str_rstrip ((self)) |
Substitution macro for the function C_Str_rstrip.
self | Pointeur to object instance. |
#define C_Str_trim | ( | self) | C_Str_strip ((self)) |
Substitution macro for the function C_Str_strip.
self | Pointer to object instance. |
#define C_Str_set_text | ( | self, | |
string | |||
) | C_Str_fill ((self), (string)) |
Substitution macro for the function C_Str_fill.
self | Pointer to object instance. |
string | New string to insert. |
#define C_Str_is_equal | ( | obj1, | |
obj2 | |||
) | C_Str_compare_to_object ((obj1), (obj2)) |
Substitution macro for the function C_Str_compare_to_object.
obj1 | Pointer to a C_Str instance. |
obj2 | Pointer to another C_Str instance. |
Opaque type representing the string object.
enum C_Str_error |
Error constants supported by the object C_Str.
Enumerator | |
---|---|
C_STR_END_STR |
End of string: in case of index search for the occurence of a letter with the function C_Str_index. |
C_STR_NO_ERR |
No error. |
C_STR_DYN_ALLOC_ERR |
Error during dynamic memory allocation. |
C_STR_NULL_ARG |
Argument with NULL value. |
C_STR_BAD_STR_LEN |
Bad string size, empty string. |
C_STR_FILE_ERR |
Open/Creation file error. |
C_STR_WRITE_ERR |
File writing error. |
C_STR_TABLE_SET_ERR |
Table data adding error. |
C_STR_BAD_INDEX |
Bad index. |
C_STR_NO_CHAR_FOUND |
No character found. Error used by the function C_Str_replace_letter |
C_STR_INVALID_SIZE |
Used by C_Str_n_fill if 'len' parameter is not valid. |
C_STR_NB |
Number of error constants. |
const char * C_Str_get_id | ( | void | ) |
Returns the id (complete name) of the C_Str library.
const char * C_Str_get_version | ( | void | ) |
Returns the version of the library.
int C_Str_get_version_major | ( | void | ) |
Returns the major version of the library.
int C_Str_get_version_minor | ( | void | ) |
Returns the minor version of the library.
int C_Str_get_version_revision | ( | void | ) |
Returns the revision number of the library.
C_Str * C_Str_new | ( | void | ) |
Creates a new empty instance of the object C_Str.
C_Str* C_Str_new_len | ( | size_t | size) |
Creates a new empty instance of the object C_Str. with a predetermined size.
C_Str * C_Str_new_len (size_t size)
size | Size of the future string. |
C_Str * C_Str_new_with_text | ( | char const *const | s_str) |
C_Str * C_Str_new_from_file | ( | char const *const | s_file) |
Creates a new instance of the object C_Str and initilizes this string with the content of the file whose name is passed in argument.
s_file | Complete path of the file to open. Cannot be NULL. |
C_Str * C_Str_new_from_sub_string | ( | char const *const | s_str, |
size_t | start, | ||
size_t | end | ||
) |
Creates a new instance of the object C_Str from a substring whose limits are passed as arguments.
s_str | String from which the substring is to be extracted. Cannot be NULL. |
start | Index of the beginning of the substring to extract. |
end | Index of the end of the substring to retrieve. If the value of this argument is greater than the length of the string, the substring returned will go to the end of the string pointed by s_str. |
Creates a new instance of the object C_Str from a substring provided by another C_Str instance. The limits of the substring are passed as arguments.
self | Object from which we want to extract the substring. Cannot be NULL. |
start | Index of the beginning of the substring to extract. |
end | Index of the end of the substring to retrieve. If the value of this argument is greater than the length of the string, the substring returned will go to the end of the string represented by self. |
void C_Str_destroy | ( | C_Str **const | self) |
Destroys an instance of an object of type C_Str.
self | Pointer to the isntance to destroy. The freed address is set automatically to the value NULL. |
bool C_Str_write_to_file | ( | C_Str *const | self, |
const char * | filename, | ||
const char * | mode | ||
) |
Writes the contents of an object C_Str in the specified file.
self | Pointer to a valid instance of an object C_Str. |
filename | Destination file. |
mode | File open mode. |
C_Str_error C_Str_get_error | ( | C_Str *const | self) |
Returns the error stored in the object passed as a parameter.
self | Pointer to a valid instance of an object C_Str. |
void * C_Str_access_to_generic_buff | ( | C_Str *const | self) |
Return a generic nonconstant pointer of the buffer.
self | Valid instance of a C_Str object. |
const char * C_Str_get | ( | C_Str *const | self) |
Returns the string stored by the object passed as argument.
self | Valid instance of a C_Str object. |
char * C_Str_get_new_string | ( | C_Str *const | self) |
Return a string copy of object.
self | Instance valide d'un objet C_Str. |
size_t C_Str_len | ( | C_Str *const | self) |
Returns the length of the string stored by the object passed as argument.
self | Valid instance to a C_Str instance. |
bool C_Str_is_empty | ( | C_Str *const | self) |
Determines if the string stored by the object is empty or not.
self | Valid instance to a C_Str object. |
bool C_Str_cat_with_str | ( | C_Str *const | self, |
char const *const | s_str, | ||
... | |||
) |
Concatenation and multiple concatenation.
The concatenation is performed on the string stored in the instance pointed by self with strings passed as arguments.
self | Pointeur to the instance of the C_Str object. |
s_str | String to concatenate with the string stored by the C_Str instance. |
... | Variable-length list of arguments to be concatenated with the string stored by the C_Str instance. The end of the list must be marked by a NULL value. If no argument is to be passed to the variable-length list of variables, use the value NULL. |
Concatenation and multiple concatenation of C_Str objects.
This function is identical to #C_Str_car_with_str except that it takes insatances of the C_Str object as parameters instead of simple strings.
but | Pointer to the destination C_Str instance. |
source | Pointer to the instance of the source object. |
... | Variable-length list of arguments of C_Str opbjects to be concatenated with source string object. Use the value NULL to indicate that there is no variable argument or to indicate the end of the variable-length list of arguments. |
bool C_Str_nth_to_upper | ( | C_Str *const | self, |
size_t | char_pos | ||
) |
Changes the case of a character in the string: uppercase.
self | Pointer to the instance of the C_Str object. |
char_pos | Position of the character whose case must be changed. The index starts at 0. |
bool C_Str_nth_to_lower | ( | C_Str *const | self, |
size_t | char_pos | ||
) |
Changes the case of a character in the string: lowercase.
self | Pointer to the instance of the C_Str object. |
char_pos | Position of the character whose case must be changed. The index starts at 0. |
bool C_Str_to_upper | ( | C_Str *const | self) |
Changes the case of the whole string: uppercase.
self | Pointer to the instance of the C_Str object. |
bool C_Str_to_lower | ( | C_Str *const | self) |
Changes the case of the whole string: lowercase.
self | Pointer to the instance of the C_Str object. |
bool C_Str_capitalize | ( | C_Str *const | self) |
Changes the case of the first character of the string to uppercase.
self | Pointer to the instance of the C_Str object. |
bool C_Str_swap_case | ( | C_Str *const | self) |
Swaps the case of all the characters in the string.
self | Pointer to the instance of the C_Str object. |
bool C_Str_lstrip | ( | C_Str *const | self) |
Removes extra spaces at the beginning of the string.
In case of error, the string of the object remains unchanged.
self | Pointer to the instance of the C_Str object. |
bool C_Str_rstrip | ( | C_Str *const | self) |
Removes extra spaces at the end of the string.
In case of error, the string of the object remains unchanged.
self | Pointer to the instance of the C_Str object. |
bool C_Str_strip | ( | C_Str *const | self) |
Removes extra spaces at the beginning and at the end of the string.
In case of error, the string of the object remains unchanged.
self | Pointer to the instance of the C_Str object. |
bool C_Str_replace_string | ( | C_Str *const | self, |
size_t | start, | ||
size_t | lenght, | ||
char const *const | s_str | ||
) |
Replaces a fragment of the string by a new string.
self | Pointer to the instance of the C_Str object. |
start | Starting index of the replacement. |
lenght | Length of the replacement. |
s_str | Replacement string. |
bool C_Str_replace_letter | ( | C_Str *const | self, |
const char | old_letter, | ||
const char | new_letter | ||
) |
Replaces all occurences of character 'old_letter' with the new character 'new_letter'.
self | Pointer to the instance of the C_Str object. |
old_letter | Character to replace. |
new_letter | Replacement character. |
int C_Str_index | ( | C_Str *const | self, |
const char | letter | ||
) |
Finds the position of an occurence of the letter in the string.
self | Pointer to the C_Str instance. Set the value of this argument to NULL to know the position of the next occurence of the same letter. |
letter | Occurence to find. |
int C_Str_r_index | ( | C_Str *const | self, |
const char | letter | ||
) |
Find the last occurence of the lettre.
self | Pointer to the C_Str instance.. |
letter | Letter to retrieve. |
char C_Str_char_at | ( | C_Str *const | self, |
size_t | index | ||
) |
Returns the character at the specified index.
self | Pointer to the C_Str instance. |
index | Index of the character to retrieve. |
char * C_Str_nth_string_copy | ( | C_Str *const | self, |
int | len | ||
) |
Copies a portion of the string to another memory address.
The copy is achieved starting from the beginning of the string.
self | Pointer to the C_Str instance. |
len | Length to copy. If the length is equal to zero, the whole string is copied. |
Copies a portion of the string to another memory address.
The copy is achieved starting from the beginning of the string.
This function returns the address of a newly allocated C_Str object.
self | Pointer to the C_Str instance. |
len | Length to copy. If the length is equal to zero, the whole string is copied. |
char * C_Str_string_copy | ( | C_Str *const | self) |
Copies the string to another memory address. The copy is achieved starting from the beginning of the string.
self | Pointer to the C_Str instance. |
Copies the string to another memory address. The copy is achieved starting from the beginning of the string.
This function returns the address of a newly-allocated C_Str object.
self | Pointer to the C_Str instance. |
bool C_Str_cut | ( | C_Str *const | self, |
size_t | start, | ||
size_t | end | ||
) |
Slices the string following the two given positions.
If the starting position is the beginning of the string, set start to the value 0.
If the end position is greater than the length of the string, the slice is done until the end of the string.
self | Pointer to the C_Str instance |
start | Starting index of the slice. |
end | End index of the slice. |
size_t C_Str_how_much_letter | ( | C_Str *const | self, |
const char | letter | ||
) |
Looks for the number of occurences of a letter in the string.
self | Pointer to the C_Str instance. |
letter | Letter whose number of occurences in the string must be found. |
size_t C_Str_how_much_word | ( | C_Str *const | self, |
char const *const | word | ||
) |
Looks for the number of occurences of a word in the string.
self | Pointer to the C_Str instance. |
word | Word whose number of occurences in the string must be found. |
bool C_Str_is_word_in_string | ( | C_Str *const | self, |
char const *const | word | ||
) |
Determines if the word passed as second argument is present in the string.
self | Pointer to the C_Str instance. |
word | Word whose presence in the string must be determined. |
bool C_Str_is_letter_in_string | ( | C_Str *const | self, |
const char | letter | ||
) |
Determined if the letter passed as second argument is present in the string.
self | Pointer to the C_Str instance. |
letter | Letter whose presence in the string is to be determined. |
char * C_Str_sub_string | ( | C_Str *const | self, |
const char * | sub_string | ||
) |
Looks for the substring passed as second argument in the string of the object self.
self | Pointer to the C_Str instance. |
sub_string | Substring to find. |
Looks for the substring passed as second argument in the string of the object self.
self | Pointer to the C_Str instance. |
sub_string | Pointer to the C_Str instance containing the substring to look for in self. |
char * C_Str_sub_string_by_val | ( | C_Str *const | self, |
size_t | start, | ||
size_t | end | ||
) |
Searches the substring in the object based on the limits provided in arguments.
self | Pointer to the C_Str instance. |
start | Start index of the substring to retrieve. |
end | End index of the substring to retrieve. If the value of this argument is greater than the length of the string, the substring returned will go to the end of the string. |
char ** C_Str_split | ( | C_Str *const | self, |
char const *const | sep | ||
) |
Splits a string word by word. Each word is stored in an array of strings. Each substring (word) is terminated by end-of-string null character. The array of string ends with a NULL value.
self | Pointeur vers l'instance de l'objet. |
sep | List of separators passed to the function in form of a string. The argument can be NULL, in which cas a default list is used. |
You can retrieve the error value stored in the object with the function C_Str_get_error
void C_Str_free_split_tab | ( | char *** | tab) |
Free the memory allocated for an array of strings created by function C_Str_split.
tab | Address of the array of string created by the C_Str_split function. |
bool C_Str_compare_ignore_case | ( | C_Str *const | self, |
char const *const | s_str | ||
) |
Compares two strings without taking into account letter case.
self | Pointer to the C_Str instance. |
s_str | C-style string to be compared with the string stored by the self C_Str instance. |
Compares two strings without taking into account letter case.
self | Pointer to the C_Str instance. |
compare | Pointer to the instance of another C_Str object for the comparison. |
bool C_Str_compare | ( | C_Str *const | self, |
char const *const | s_str | ||
) |
Compares two strings.
self | Pointer to the C_Str instance. |
s_str | C-style string to be compared with the string stored by the self C_Str instance. |
Compares two strings.
self | Pointer to the C_Str instance. |
compare | Pointer to the instance of another C_Str object for the comparison. |
bool C_Str_clear | ( | C_Str *const | self) |
bool C_Str_fill | ( | C_Str *const | self, |
char const *const | s_str | ||
) |
Inserts a new string in the memory location of the string stored by the C_Str instance whose address is passed as an argument. The old string will be permanently lost.
self | Pointer to the C_Str instance. |
s_str | New string to be stored by the self C_Str object. |
bool C_Str_n_fill | ( | C_Str *const | self, |
char | c, | ||
size_t | len | ||
) |
Inserts a character defined by the c argument on a length len in the string stored by the C_Str instance whose address is passed as first argument. The insertion ever takes place at the beginning of the string stored by the C_Str object.
self | Pointer to the C_Str instance. |
c | Character to insert. |
len | Length of the insertion. |
bool C_Str_start_with | ( | C_Str *const | self, |
char const *const | s_str | ||
) |
Determines if the string starts with the prefix passed as argument.
self | Pointer to the C_Str instance |
s_str | C-style string representing the prefix to retrieve at the beginning of the self C_Str instance. |
Determines if the string starts with the prefix passed as argument.
self | Pointer to the C_Str instance. |
start | Pointer to a C_Str instance representing the prefix to retrieve at the beginning of the self C_Str instance. |
bool C_Str_end_with | ( | C_Str *const | self, |
char const *const | s_str | ||
) |
Determines if the string ends with the suffix passed as argument.
self | Pointer to the C_Str object. |
s_str | C-style string representing the prefix to retrive at the end of the self C_Str instance. |
Determines if the string ends with the suffix passed as argument.
self | Pointer to the C_Str instance. |
end | Pointer to a C_Str instance representing the prefix to retrieve at the end of the self C_Str instance. |
bool C_Str_reverse | ( | C_Str *const | self) |
Reverses the string.
self | Pointer to the C_Str instance. |
Clones the C_Str instance passed as argument.
Cloning a string means doing a copy of it with both the clone #C_Str instance and the string stored in it being located at memory addresses different from the source instance.
self | Pointer to the C_Str instance to clone. |