Macros | Typedefs | Enumerations | Functions
CStr library documentation
Version 3.0.1

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_StrC_Str_new (void)
 
C_StrC_Str_new_len (size_t size)
 
C_StrC_Str_new_with_text (char const *const s_str)
 
C_StrC_Str_new_from_file (char const *const s_file)
 
C_StrC_Str_new_from_sub_string (char const *const s_str, size_t start, size_t end)
 
C_StrC_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_StrC_Str_nth_string_copy_obj (C_Str *const self, int len)
 
char * C_Str_string_copy (C_Str *const self)
 
C_StrC_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_StrC_Str_clone (C_Str *const self)
 

Detailed Description

Author
HECHT Franck
Version
3.0.0

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.

Note
This library is now compatible with the C99.
Attention
Its passage in 3.0.0 involves many changes, the library is no longer compatible with older versions. If you use versions earlier in your projects, you will either continue to use without getting update or switch to the new version.

Here is an example of how to use the library:

#include "c_str.h"
int main (void)
{
C_Str * my_str = C_Str_new_with_text ("Hello, world !");
if (my_str)
{
printf ("%s\n", C_Str_get (my_str));
if (C_Str_replace_string (my_str, 0, 6, "Hi"))
printf ("%s\n", C_Str_get (my_str));
C_Str_destroy (& my_str);
}
return EXIT_SUCCESS;
}

The output on the console:

Hello, world !
Hi, world !
Warning
An object of type C_Str must always be destroyed using the dedicated function C_Str_destroy.

Macro Definition Documentation

#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.

Parameters
selfPointer to object instance.
wordWord 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.

Parameters
selfPointer to object instance.
letterLetter 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.

Parameters
selfPointer to object instance.
stringString 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.

Parameters
selfPointer to object instance.
comparePointer 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.

Parameters
tabPointer 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.

Parameters
tabPointer 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.

Parameters
selfPointer to object instance.
#define C_Str_rtrim (   self)    C_Str_rstrip ((self))

Substitution macro for the function C_Str_rstrip.

Parameters
selfPointeur to object instance.
#define C_Str_trim (   self)    C_Str_strip ((self))

Substitution macro for the function C_Str_strip.

Parameters
selfPointer to object instance.
#define C_Str_set_text (   self,
  string 
)    C_Str_fill ((self), (string))

Substitution macro for the function C_Str_fill.

Parameters
selfPointer to object instance.
stringNew 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.

Parameters
obj1Pointer to a C_Str instance.
obj2Pointer to another C_Str instance.

Typedef Documentation

Opaque type representing the string object.

Enumeration Type Documentation

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.

Function Documentation

const char * C_Str_get_id ( void  )

Returns the id (complete name) of the C_Str library.

Returns
String representing the id of the library.
const char * C_Str_get_version ( void  )

Returns the version of the library.

Returns
String representing the version of the library.
int C_Str_get_version_major ( void  )

Returns the major version of the library.

Returns
Integer representing the major version of the library.
int C_Str_get_version_minor ( void  )

Returns the minor version of the library.

Returns
Integer representing the minor version of the library.
int C_Str_get_version_revision ( void  )

Returns the revision number of the library.

Returns
Integer representing the revision number of the library.
C_Str * C_Str_new ( void  )

Creates a new empty instance of the object C_Str.

Returns
Pointer to the newly created instance.
NULL in case of creation failure.
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)

Parameters
sizeSize of the future string.
Returns
Pointer to the newly created instance.
NULL in case of creation failure.
C_Str * C_Str_new_with_text ( char const *const  s_str)

Creates a new instance of the object C_Str initilized with a string whose length is automatically calculated.

Parameters
s_strString used to initialize the C_Str object. Cannot be NULL.
Returns
Pointer to the newly created instance.
NULL in case of creation failure.
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.

Parameters
s_fileComplete path of the file to open. Cannot be NULL.
Returns
Pointer to the newly created instance.
NULL in case of creation failure.
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.

Parameters
s_strString from which the substring is to be extracted.
Cannot be NULL.
startIndex of the beginning of the substring to extract.
endIndex 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.
Returns
Pointer to the newly created instance.
NULL in case of creation failure.
C_Str * C_Str_new_from_sub_string_obj ( C_Str *const  self,
size_t  start,
size_t  end 
)

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.

Parameters
selfObject from which we want to extract the substring.
Cannot be NULL.
startIndex of the beginning of the substring to extract.
endIndex 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.
Returns
Pointer to the newly created instance.
NULL in case of creation failure.
void C_Str_destroy ( C_Str **const  self)

Destroys an instance of an object of type C_Str.

Parameters
selfPointer 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.

Parameters
selfPointer to a valid instance of an object C_Str.
filenameDestination file.
modeFile open mode.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
C_Str_error C_Str_get_error ( C_Str *const  self)

Returns the error stored in the object passed as a parameter.

Parameters
selfPointer to a valid instance of an object C_Str.
Returns
Returns an error type C_Str_error.
void * C_Str_access_to_generic_buff ( C_Str *const  self)

Return a generic nonconstant pointer of the buffer.

Attention
The buffer can be changed manually, do not use this function if you do not know what you made.
Parameters
selfValid instance of a C_Str object.
Returns
Nonconstant generic pointer to the buffer.
const char * C_Str_get ( C_Str *const  self)

Returns the string stored by the object passed as argument.

Parameters
selfValid instance of a C_Str object.
Returns
Pointer to the string stored by the object. The string returned is not a copy but just a pointer to the string stored by the object self. This string must not be freed !
NULL in case of failure.
char * C_Str_get_new_string ( C_Str *const  self)

Return a string copy of object.

Parameters
selfInstance valide d'un objet C_Str.
Returns
Pointeur vers une nouvelle copie de la chaîne stockée par l'objet. NULL en cas d'échec.
Attention
You must free yourself returned string with standard function free() !
size_t C_Str_len ( C_Str *const  self)

Returns the length of the string stored by the object passed as argument.

Parameters
selfValid instance to a C_Str instance.
Returns
Length of the string.
bool C_Str_is_empty ( C_Str *const  self)

Determines if the string stored by the object is empty or not.

Parameters
selfValid instance to a C_Str object.
Returns
true if string is empty, false otherwise.
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.

Parameters
selfPointeur to the instance of the C_Str object.
s_strString 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.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if the function ends normally.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
bool C_Str_cat ( C_Str *const  but,
C_Str *const  source,
  ... 
)

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.

Parameters
butPointer to the destination C_Str instance.
sourcePointer 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.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if the function ends normally.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
bool C_Str_nth_to_upper ( C_Str *const  self,
size_t  char_pos 
)

Changes the case of a character in the string: uppercase.

Parameters
selfPointer to the instance of the C_Str object.
char_posPosition of the character whose case must be changed. The index starts at 0.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
  • C_STR_BAD_INDEX if the index provided as second argument is out of bounds.
bool C_Str_nth_to_lower ( C_Str *const  self,
size_t  char_pos 
)

Changes the case of a character in the string: lowercase.

Parameters
selfPointer to the instance of the C_Str object.
char_posPosition of the character whose case must be changed. The index starts at 0.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
  • C_STR_BAD_INDEX if the index provided as second argument is out of bounds.
bool C_Str_to_upper ( C_Str *const  self)

Changes the case of the whole string: uppercase.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
bool C_Str_to_lower ( C_Str *const  self)

Changes the case of the whole string: lowercase.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
bool C_Str_capitalize ( C_Str *const  self)

Changes the case of the first character of the string to uppercase.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
bool C_Str_swap_case ( C_Str *const  self)

Swaps the case of all the characters in the string.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
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.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if the string is empty.
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.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if the string is empty.
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.

Parameters
selfPointer to the instance of the C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if the string is empty.
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.

Parameters
selfPointer to the instance of the C_Str object.
startStarting index of the replacement.
lenghtLength of the replacement.
s_strReplacement string.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if the string is empty.
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'.

Parameters
selfPointer to the instance of the C_Str object.
old_letterCharacter to replace.
new_letterReplacement character.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_NO_CHAR_FOUND if no character has been found.
  • C_STR_BAD_STR_LEN if the size of the string is equal to zero, hence an empty string.
int C_Str_index ( C_Str *const  self,
const char  letter 
)

Finds the position of an occurence of the letter in the string.

Parameters
selfPointer 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.
letterOccurence to find.
Returns
Position of the occurence of the letter passed as argument.
0 if no occurence of the letter has been found.
You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_END_STR if end of string has been reached.
int C_Str_r_index ( C_Str *const  self,
const char  letter 
)

Find the last occurence of the lettre.

Parameters
selfPointer to the C_Str instance..
letterLetter to retrieve.
Returns
Position of the letter if it was found, -1 otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
char C_Str_char_at ( C_Str *const  self,
size_t  index 
)

Returns the character at the specified index.

Parameters
selfPointer to the C_Str instance.
indexIndex of the character to retrieve.
Returns
Character at the specified index, null character in case of error. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Attention
The string returned must be freed with free before the end of the program.
Parameters
selfPointer to the C_Str instance.
lenLength to copy. If the length is equal to zero, the whole string is copied.
Returns
Address of the copy of the string or NULL in case of error. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
C_Str * C_Str_nth_string_copy_obj ( 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.

Attention
The C_Str object returned must be freed with C_Str_destroy before the end of the program.

This function returns the address of a newly allocated C_Str object.

Parameters
selfPointer to the C_Str instance.
lenLength to copy. If the length is equal to zero, the whole string is copied.
Returns
Address of the copy of the string or NULL in case of error. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Attention
The string returned must be freed with free before the end of the program.
Parameters
selfPointer to the C_Str instance.
Returns
Address of the copy of the string or NULL in case of error. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
C_Str * C_Str_string_copy_obj ( C_Str *const  self)

Copies the string to another memory address. The copy is achieved starting from the beginning of the string.

Attention
The C_Str object returned must be freed with C_Str_destroy before the end of the program.

This function returns the address of a newly-allocated C_Str object.

Parameters
selfPointer to the C_Str instance.
Returns
Address of the copy of the string or NULL in case of error. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Attention
The slice is done in-place on string stored in the C_Str instance passed as first argument. The string is modified.
Parameters
selfPointer to the C_Str instance
startStarting index of the slice.
endEnd index of the slice.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str instance.
letterLetter whose number of occurences in the string must be found.
Returns
Number of occurences found. 0 if no occurence. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str instance.
wordWord whose number of occurences in the string must be found.
Returns
Number of occurences found. 0 if no occurence or if memory allocation for the copy of the string failed. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str instance.
wordWord whose presence in the string must be determined.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str instance.
letterLetter whose presence in the string is to be determined.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str instance.
sub_stringSubstring to find.
Returns
Pointer to the beginning of the substring in self, NULL in case of error or if no occurence of substring has been found.
The returned pointer must not be freed since it only points to the substring without doing any copy of the original string. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
char * C_Str_sub_string_obj ( C_Str *const  self,
C_Str *const  sub_string 
)

Looks for the substring passed as second argument in the string of the object self.

Parameters
selfPointer to the C_Str instance.
sub_stringPointer to the C_Str instance containing the substring to look for in self.
Returns
Pointer to the beginning of the substring in self, NULL in case of error or if no substring has been found.
The returned pointer must not be freed since it only points to the substring without doing any copy of the original string. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str instance.
startStart index of the substring to retrieve.
endEnd 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.
Returns
Pointer to the beginning of the substring, NULL in case of error or if no substring has been found.
The returned substring must be freed with free since the function generates a copy of the desired substring. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Attention
The array must be freed with the function C_Str_free_split_tab or with the macro C_Str_free_split before the end of the program.
Parameters
selfPointeur vers l'instance de l'objet.
sepList of separators passed to the function in form of a string. The argument can be NULL, in which cas a default list is used.
Returns
Pointer to an array of strings containing all the words split from the self C_Str object. In case of error, the function returns the value NULL. If you do not specify a separator character is the  * character 'Space' which is the default.

You can retrieve the error value stored in the object with the function C_Str_get_error

  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if string is empty.
void C_Str_free_split_tab ( char ***  tab)

Free the memory allocated for an array of strings created by function C_Str_split.

Parameters
tabAddress 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.

Parameters
selfPointer to the C_Str instance.
s_strC-style string to be compared with the string stored by the self C_Str instance.
Returns
true if strings are equals, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if string is empty.
bool C_Str_compare_ignore_case_obj ( C_Str *const  self,
C_Str *const  compare 
)

Compares two strings without taking into account letter case.

Parameters
selfPointer to the C_Str instance.
comparePointer to the instance of another C_Str object for the comparison.
Returns
true if strings are equals, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
  • C_STR_BAD_STR_LEN if string is empty.
bool C_Str_compare ( C_Str *const  self,
char const *const  s_str 
)

Compares two strings.

Parameters
selfPointer to the C_Str instance.
s_strC-style string to be compared with the string stored by the self C_Str instance.
Returns
true if strings are equals, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
bool C_Str_compare_obj ( C_Str *const  self,
C_Str *const  compare 
)

Compares two strings.

Parameters
selfPointer to the C_Str instance.
comparePointer to the instance of another C_Str object for the comparison.
Returns
true if strings are equals, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
bool C_Str_compare_to_object ( C_Str *const  s1,
C_Str *const  s2 
)

Compares two objects of type C_Str.

Parameters
s1Pointer to the first C_Str instance used for the comparison.
s2Pointer to the second C_Str instance used for the comparison.
Returns
true if objects are equals, false otherwise.
bool C_Str_clear ( C_Str *const  self)

Clears the string stored by the C_Str instance. The deletion does not desallocate the memory used internally for the string.

Parameters
selfPointer to the C_Str instance.
Returns
true if the action to be successful, false otherwise.
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.

Parameters
selfPointer to the C_Str instance.
s_strNew string to be stored by the self C_Str object.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
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.

Parameters
selfPointer to the C_Str instance.
cCharacter to insert.
lenLength of the insertion.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_INVALID_SIZE if 'len' parameter is invalid.
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.

Parameters
selfPointer to the C_Str instance
s_strC-style string representing the prefix to retrieve at the beginning of the self C_Str instance.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
int C_Str_start_with_obj ( C_Str *const  self,
C_Str *const  start 
)

Determines if the string starts with the prefix passed as argument.

Parameters
selfPointer to the C_Str instance.
startPointer to a C_Str instance representing the prefix to retrieve at the beginning of the self C_Str instance.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
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.

Parameters
selfPointer to the C_Str object.
s_strC-style string representing the prefix to retrive at the end of the self C_Str instance.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
bool C_Str_end_with_obj ( C_Str *const  self,
C_Str *const  end 
)

Determines if the string ends with the suffix passed as argument.

Parameters
selfPointer to the C_Str instance.
endPointer to a C_Str instance representing the prefix to retrieve at the end of the self C_Str instance.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
bool C_Str_reverse ( C_Str *const  self)

Reverses the string.

Parameters
selfPointer to the C_Str instance.
Returns
true if the action to be successful, false otherwise. You can retrieve the error value stored in the object with the function C_Str_get_error
  • C_STR_NO_ERR if no error occured.
  • C_STR_BAD_STR_LEN if string is empty.
  • C_STR_DYN_ALLOC_ERR if a dynamic memory allocation failed.
C_Str * C_Str_clone ( C_Str *const  self)

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.
Parameters
selfPointer to the C_Str instance to clone.
Returns
Address of the clone of the self C_Str instance. NULL in case of error.