string_array.c File Reference

String array module implementation file. More...

#include "string_array.h"
#include "memory.h"
#include "definitions.h"
#include "log_util.h"
Include dependency graph for string_array.c:

Go to the source code of this file.

Functions

E_MCL_ERROR_CODE string_array_initialize (mcl_size_t count, string_array_t **array)
 String array initialize method. More...
 
E_MCL_ERROR_CODE string_array_set_increment (string_array_t *array, mcl_size_t increment_value)
 Sets the increment value of the array. More...
 
E_MCL_ERROR_CODE string_array_add (string_array_t *array, string_t *string, mcl_bool_t destroy)
 Adds an string_t string object into the array. More...
 
string_tstring_array_get (string_array_t *array, mcl_size_t index)
 To get the string_t string object at a specified index. More...
 
string_tstring_array_to_string (string_array_t *array)
 To concatenate the strings in the array. More...
 
void string_array_destroy (string_array_t **array)
 Destroys the string array handle. More...
 

Detailed Description

String array module implementation file.


Date
Aug 19, 2016

Definition in file string_array.c.

Function Documentation

E_MCL_ERROR_CODE string_array_add ( string_array_t array,
string_t string,
mcl_bool_t  destroy 
)

Adds an string_t string object into the array.

Caller also have to decide wheter this string object should be destroyed or not when string array is destroyed.

Parameters
[in]arrayString array handle to operate.
[in]stringThe string_t string object to be added into the array.
[in]destroyDestroy flag is used to decide during string_array_destroy() operation wheter call string_destroy() for this string item or not.
Returns

Definition at line 70 of file string_array.c.

References ASSERT_CODE_MESSAGE, string_array_t::count, DEBUG_ENTRY, DEBUG_LEAVE, DEFAULT_INCREMENT_VALUE, string_array_item_t::destroy, string_array_t::increment_value, string_array_t::index, string_array_t::items, MCL_DEBUG, MCL_FALSE, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_RESIZE, string_array_item_t::string, and string_array_t::total_length.

Referenced by _join_with_dot(), _response_header_callback(), and http_request_add_header().

Here is the caller graph for this function:

void string_array_destroy ( string_array_t **  array)

Destroys the string array handle.

With a loop over its items, check destroy flag of each of the items and calls string_destroy() if the flag is MCL_TRUE.

Warning
Even though this function calls string_destroy() buffer of that string might not be freed. It is depended on how the string is initialized. Please
See also
string_initialize() functions.
Parameters
[in]arrayAddress of string array handle. String array will be MCL_NULL after this operation.

Definition at line 174 of file string_array.c.

References string_array_t::count, DEBUG_ENTRY, DEBUG_LEAVE, string_array_item_t::destroy, string_array_t::items, MCL_DEBUG, MCL_FREE, MCL_NULL, MCL_TRUE, string_array_item_t::string, and string_destroy().

Referenced by _join_with_dot(), http_client_send(), http_request_destroy(), and http_response_destroy().

Here is the call graph for this function:

Here is the caller graph for this function:

string_t* string_array_get ( string_array_t array,
mcl_size_t  index 
)

To get the string_t string object at a specified index.

Parameters
[in]arrayString array handle to operate.
[in]indexSpecifes the index in the array of the reqeusted string object. Index has to be greater than 0 and smaller then array's current index.
Returns
Returns the string object on success. MCL_NULL if index is invalid.

Definition at line 114 of file string_array.c.

References ASSERT_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, string_array_t::items, MCL_NULL, and string_array_item_t::string.

Referenced by _set_request_options(), and http_response_get_header().

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_array_initialize ( mcl_size_t  count,
string_array_t **  array 
)

String array initialize method.

Initializes a string array handle suitable to hold count items.

Parameters
[in]countInitial item count that this string array will hold. This count value might be changed if it is not enough for future add operations.
[out]arrayInitialized string array handle.
Returns

Definition at line 19 of file string_array.c.

References ASSERT_CODE_MESSAGE, string_array_t::count, DEFAULT_INCREMENT_VALUE, string_array_item_t::destroy, string_array_t::increment_value, string_array_t::index, string_array_t::items, MCL_ERROR_RETURN, MCL_FALSE, MCL_FREE, MCL_INVALID_PARAMETER, MCL_MALLOC, MCL_NEW, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, string_array_item_t::string, string_array_t::total_length, VERBOSE_ENTRY, and VERBOSE_LEAVE.

Referenced by _join_with_dot(), http_client_send(), and http_request_initialize().

Here is the caller graph for this function:

E_MCL_ERROR_CODE string_array_set_increment ( string_array_t array,
mcl_size_t  increment_value 
)

Sets the increment value of the array.

Incrementing the array means if during an add operation, there initialized array count is not enough to hold the additional item, array increasses it's size by its increment value. With this function this value can be set. For its default value refer to DEFAULT_INCREMENT_VALUE.

Parameters
[in]arrayString array handle to operate.
[in]increment_valueThe increment value. Have to be greater than 0.
Returns

Definition at line 58 of file string_array.c.

References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, string_array_t::increment_value, MCL_INVALID_PARAMETER, and MCL_OK.

string_t* string_array_to_string ( string_array_t array)

To concatenate the strings in the array.

It collects the strings in its array and concatenates them into a final string and returns it.

Parameters
[in]arrayString array handle to operate.
Returns
Returns pointer to string_t string object which holds the concatenated form of the strings in the array, MCL_NULL on failure.

Definition at line 132 of file string_array.c.

References ASSERT_MESSAGE, string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, string_array_t::index, string_array_t::items, string_t::length, MCL_DEBUG, MCL_ERROR_RETURN_POINTER, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, string_array_item_t::string, string_initialize_dynamic(), string_util_strncat(), and string_array_t::total_length.

Referenced by _join_with_dot().

Here is the call graph for this function:

Here is the caller graph for this function: