String utility module implementation file. More...
#include "string_util.h"#include "mcl_core/mcl_string_util.h"#include "mcl_core/mcl_assert.h"#include "mcl_core/mcl_memory.h"#include <string.h>#include <stdio.h>#include <stdarg.h>#include <stdlib.h>
Go to the source code of this file.
Macros | |
| #define | LOWERCASE(n) ((n >= 'A' && n <= 'Z') ? (n + ('a' - 'A')) : n) |
Functions | |
| static mcl_error_t | _print_formatted_string (char *string, mcl_size_t length, const char *format, va_list args) |
| mcl_size_t | mcl_string_util_strlen (const char *buffer) |
| mcl_size_t | string_util_strlen (const char *buffer) |
| mcl_size_t | mcl_string_util_strnlen (const char *buffer, mcl_size_t maximum_length) |
| mcl_size_t | string_util_strnlen (const char *buffer, mcl_size_t maximum_length) |
| void | mcl_string_util_strncpy (char *destination, const char *source, mcl_size_t count) |
| void | string_util_strncpy (char *destination, const char *source, mcl_size_t count) |
| void | mcl_string_util_strncat (char *destination, const char *source, mcl_size_t count) |
| void | string_util_strncat (char *destination, const char *source, mcl_size_t count) |
| mcl_error_t | mcl_string_util_strncmp (const char *string_1, const char *string_2, mcl_size_t count) |
| mcl_error_t | string_util_strncmp (const char *string_1, const char *string_2, mcl_size_t count) |
| mcl_error_t | mcl_string_util_snprintf (char *string, mcl_size_t length, const char *format,...) |
| mcl_error_t | string_util_snprintf (char *string, mcl_size_t length, const char *format,...) |
| mcl_bool_t | mcl_string_util_memcmp (const void *block_1, const void *block_2, mcl_size_t count) |
| mcl_bool_t | string_util_memcmp (const void *block_1, const void *block_2, mcl_size_t count) |
| void | mcl_string_util_memcpy (void *destination, const void *source, mcl_size_t count) |
| void | string_util_memcpy (void *destination, const void *source, mcl_size_t count) |
| void | mcl_string_util_memset (void *destination, mcl_uint8_t value, mcl_size_t count) |
| void | string_util_memset (void *destination, mcl_uint8_t value, mcl_size_t count) |
| char * | mcl_string_util_strdup (const char *string) |
| char * | string_util_strdup (const char *string) |
| mcl_bool_t | mcl_string_util_find (const char *source, const char *target, mcl_size_t *start_index) |
| mcl_bool_t | string_util_find (const char *source, const char *target, mcl_size_t *start_index) |
| mcl_bool_t | mcl_string_util_find_case_insensitive (const char *source, const char *target, mcl_size_t *start_index) |
| mcl_bool_t | string_util_find_case_insensitive (const char *source, const char *target, mcl_size_t *start_index) |
| long | mcl_string_util_strtol (const char *source, int base, char **end_pointer) |
| long | string_util_strtol (const char *source, int base, char **end_pointer) |
| mcl_error_t | mcl_string_util_reset (const void *value, char **target) |
| mcl_error_t | string_util_reset (const void *value, char **target) |
| mcl_error_t | mcl_string_util_concatenate (const char *string_1, const char *string_2, char **result) |
| mcl_error_t | string_util_concatenate (const char *string_1, const char *string_2, char **result) |
String utility module implementation file.
Definition in file string_util.c.
| #define LOWERCASE | ( | n | ) | ((n >= 'A' && n <= 'Z') ? (n + ('a' - 'A')) : n) |
Definition at line 18 of file string_util.c.
Referenced by string_util_find_case_insensitive().
|
static |
Definition at line 492 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FAIL, and MCL_OK.
Referenced by mcl_string_util_snprintf(), and string_util_snprintf().

| mcl_error_t mcl_string_util_concatenate | ( | const char * | string_1, |
| const char * | string_2, | ||
| char ** | result | ||
| ) |
Initializes a new result by concatenating the given string_1 and string_2.
| [in] | string_1 | Char array to which the string_2 will be concatenated. |
| [in] | string_2 | Char array which will be concatenated to string_1. |
| [out] | result | The string that is result of the concatenation. |
string_1 or string_2 is null. Definition at line 452 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, MCL_TRIGGERED_WITH_NULL, and string_util_concatenate().

| mcl_bool_t mcl_string_util_find | ( | const char * | source, |
| const char * | target, | ||
| mcl_size_t * | start_index | ||
| ) |
Finds the first occurence of target in source and puts it's first index to start_index.
| [in] | source | Null terminated string to be searched in. |
| [in] | target | Null terminated string to be searched for. |
| [out] | start_index | Index of the first character of target if source contains it. |
target is found then MCL_TRUE, otherwise MCL_FALSE. Definition at line 293 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, MCL_NULL, and string_util_find().

| mcl_bool_t mcl_string_util_find_case_insensitive | ( | const char * | source, |
| const char * | target, | ||
| mcl_size_t * | start_index | ||
| ) |
Finds the first occurence of target in source and puts it's first index to start_index.
| [in] | source | Null terminated string to be searched in. |
| [in] | target | Null terminated string to be searched for. |
| [out] | start_index | Index of the first character of target if source contains it. |
target is found then MCL_TRUE, otherwise MCL_FALSE. Definition at line 342 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, MCL_NULL, and string_util_find_case_insensitive().
Referenced by get_response().


| mcl_bool_t mcl_string_util_memcmp | ( | const void * | block_1, |
| const void * | block_2, | ||
| mcl_size_t | count | ||
| ) |
Standard library memcmp wrapper.
| [in] | block_1 | Fist memory block to compare. |
| [in] | block_2 | Second memory block to compare. |
| [in] | count | Size of first memory block. |
Definition at line 196 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and string_util_memcmp().

| void mcl_string_util_memcpy | ( | void * | destination, |
| const void * | source, | ||
| mcl_size_t | count | ||
| ) |
Standard library memcpy wrapper.
| [in] | destination | Destination memory block. |
| [in] | source | Source memory block. |
| [in] | count | Count of bytes to be copied. Destination should have space for at least count bytes. |
Definition at line 220 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and string_util_memcpy().
Referenced by get_response(), and start_http().


| void mcl_string_util_memset | ( | void * | destination, |
| mcl_uint8_t | value, | ||
| mcl_size_t | count | ||
| ) |
Standard library memset wrapper.
| [in] | destination | Destination memory block. |
| [in] | value | Value to be set. |
| [in] | count | Count of bytes to be set to the value. Destination should have space for at least count bytes. |
Definition at line 238 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and string_util_memset().

| mcl_error_t mcl_string_util_reset | ( | const void * | value, |
| char ** | target | ||
| ) |
Initializes a new target with the given value.
value must be a zero-terminated C string.| [in] | value | The content to initialize target with. |
| [out] | target | Will point to the initialized object. |
value or target is null. Definition at line 414 of file string_util.c.
References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, and string_util_reset().
Referenced by mcl_core_configuration_set_parameter().


| mcl_error_t mcl_string_util_snprintf | ( | char * | string, |
| mcl_size_t | length, | ||
| const char * | format, | ||
| ... | |||
| ) |
Standard library snprintf wrapper.
| [out] | string | String to be set. Must be a zero terminated C string. |
| [in] | length | Specifies how many chars should be processed. |
| [in] | format | Format string followed by format parameters. |
Definition at line 158 of file string_util.c.
References _print_formatted_string(), MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by mcl_core_configuration_set_parameter(), mcl_http_client_send(), mcl_tls_socket_connect(), send_with_callback(), and start_http().


| char* mcl_string_util_strdup | ( | const char * | string | ) |
Standard library strdup wrapper.
| [in] | string | String to duplicate. |
string. Definition at line 259 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and string_util_strdup().

| mcl_size_t mcl_string_util_strlen | ( | const char * | buffer | ) |
Standard library strlen wrapper.
| [in] | buffer | Buffer which length to be calculated. Must be a zero terminated C string. |
Definition at line 23 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and string_util_strlen().
Referenced by _decode_with_table(), mcl_core_configuration_set_parameter(), mcl_tls_ca_chain_add_certificate(), send_header(), send_header_list(), send_with_callback(), and start_http().


| void mcl_string_util_strncat | ( | char * | destination, |
| const char * | source, | ||
| mcl_size_t | count | ||
| ) |
Standard library strncat wrapper.
| [out] | destination | Destination string. Must be a zero terminated C string. |
| [in] | source | Source string. Must be a zero terminated C string. |
| [in] | count | Specifies how many chars from source will be added at the end of destination. |
Definition at line 96 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and string_util_strncat().

| mcl_error_t mcl_string_util_strncmp | ( | const char * | string_1, |
| const char * | string_2, | ||
| mcl_size_t | count | ||
| ) |
Standard library strncmp wrapper.
| [in] | string_1 | Fist string to be compared. Must be a zero terminated C string. |
| [in] | string_2 | Second string to be compared. Must be a zero terminated C string. |
| [in] | count | Specifies how many chars should be compared. |
string_1 or string_2 is null. Definition at line 118 of file string_util.c.
References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, and string_util_strncmp().
Referenced by mcl_http_client_send().


| void mcl_string_util_strncpy | ( | char * | destination, |
| const char * | source, | ||
| mcl_size_t | count | ||
| ) |
Standard library strncpy wrapper. Also sets the terminating null char at the end if source is not longer than count.
| [out] | destination | Destination string. Must be a zero terminated C string. |
| [in] | source | Source string. Must be a zero terminated C string. |
| [in] | count | Specifies how many chars from source will be copied into the destination. |
Definition at line 74 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and string_util_strncpy().

| mcl_size_t mcl_string_util_strnlen | ( | const char * | buffer, |
| mcl_size_t | maximum_length | ||
| ) |
Standard library strnlen wrapper.
| [in] | buffer | Buffer which length to be calculated. Must be a zero terminated C string. |
| [in] | maximum_length | The maximum length to return. If string is not zero terminated this guarantees not accessing unwanted memory. |
Definition at line 47 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and string_util_strnlen().

| long mcl_string_util_strtol | ( | const char * | source, |
| int | base, | ||
| char ** | end_pointer | ||
| ) |
Returns the first occurrence of an integral value in source string.
| [in] | source | String that contains the integral value as string. |
| [in] | base | The base that the number will be interpreted. |
| [out] | end_pointer | The pointer that points to the one past the last index of integral value. |
Definition at line 390 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and string_util_strtol().

| mcl_error_t string_util_concatenate | ( | const char * | string_1, |
| const char * | string_2, | ||
| char ** | result | ||
| ) |
Initializes a new result by concatenating the given string_1 and string_2.
| [in] | string_1 | Char array to which the string_2 will be concatenated. |
| [in] | string_2 | Char array which will be concatenated to string_1. |
| [out] | result | The string that is result of the concatenation. |
Definition at line 467 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, string_util_memcpy(), and string_util_strlen().
Referenced by _compose_access_token_request_payload(), core_processor_initialize(), and mcl_string_util_concatenate().


| mcl_bool_t string_util_find | ( | const char * | source, |
| const char * | target, | ||
| mcl_size_t * | start_index | ||
| ) |
Finds the first occurence of target in source and puts it's first index to start_index.
| [in] | source | Null terminated string to be searched in. |
| [in] | target | Null terminated string to be searched for. |
| [out] | start_index | Index of the first character of target if source contains it. |
target is found then MCL_TRUE, otherwise MCL_FALSE. Definition at line 308 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, MCL_TRUE, and string_util_strlen().
Referenced by mcl_http_response_get_header(), and mcl_string_util_find().


| mcl_bool_t string_util_find_case_insensitive | ( | const char * | source, |
| const char * | target, | ||
| mcl_size_t * | start_index | ||
| ) |
Finds the first occurence of target in source and puts it's first index to start_index.
| [in] | source | Null terminated string to be searched in. |
| [in] | target | Null terminated string to be searched for. |
| [out] | start_index | Index of the first character of target if source contains it. |
target is found then MCL_TRUE, otherwise MCL_FALSE. Definition at line 357 of file string_util.c.
References LOWERCASE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, MCL_TRUE, and string_util_strlen().
Referenced by mcl_http_response_get_header(), and mcl_string_util_find_case_insensitive().


| mcl_bool_t string_util_memcmp | ( | const void * | block_1, |
| const void * | block_2, | ||
| mcl_size_t | count | ||
| ) |
Standard library memcmp wrapper.
| [in] | block_1 | Fist memory block to compare. |
| [in] | block_2 | Second memory block to compare. |
| [in] | count | Size of first memory block. |
Definition at line 208 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, and MCL_TRUE.
Referenced by mcl_string_util_memcmp().

| void string_util_memcpy | ( | void * | destination, |
| const void * | source, | ||
| mcl_size_t | count | ||
| ) |
Standard library memcpy wrapper.
| [in] | destination | Destination memory block. |
| [in] | source | Source memory block. |
| [in] | count | Count of bytes to be copied. Destination should have space for at least count bytes. |
Definition at line 229 of file string_util.c.
References MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by _join_with_dot(), _request_payload_callback_for_put(), _response_header_callback(), _response_payload_callback(), hmac_sha256(), json_util_get_string(), mcl_core_get_last_access_token(), mcl_core_get_last_token_time(), mcl_http_client_initialize(), mcl_string_util_memcpy(), string_util_concatenate(), and string_util_strdup().

| void string_util_memset | ( | void * | destination, |
| mcl_uint8_t | value, | ||
| mcl_size_t | count | ||
| ) |
Standard library memset wrapper.
| [in] | destination | Destination memory block. |
| [in] | value | Value to be set. |
| [in] | count | Count of bytes to be set to the value. Destination should have space for at least count bytes. |
Definition at line 250 of file string_util.c.
References MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by mcl_string_util_memset().

| mcl_error_t string_util_reset | ( | const void * | value, |
| char ** | target | ||
| ) |
Initializes a new target with the given value.
value must be a zero-terminated C string.| [in] | value | The content to initialize target with. |
| [out] | target | Will point to the initialized object. |
Definition at line 431 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, and string_util_strdup().
Referenced by mcl_http_request_set_parameter(), and mcl_string_util_reset().


| mcl_error_t string_util_snprintf | ( | char * | string, |
| mcl_size_t | length, | ||
| const char * | format, | ||
| ... | |||
| ) |
Standard library snprintf wrapper.
| [out] | string | String to be set. Must be a zero terminated C string. |
| [in] | length | Specifies how many chars should be processed. |
| [in] | format | Format string followed by format parameters. |
Definition at line 177 of file string_util.c.
References _print_formatted_string(), MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by _generate_correlation_id_string(), core_processor_register(), mcl_http_request_add_header(), and random_generate_guid().


| char* string_util_strdup | ( | const char * | string | ) |
Standard library strdup wrapper.
| [in] | string | String to duplicate. |
string. Definition at line 274 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR_SIZE, string_util_memcpy(), and string_util_strlen().
Referenced by mcl_http_client_add_certificate(), mcl_http_client_initialize(), mcl_string_util_strdup(), and string_util_reset().


| mcl_size_t string_util_strlen | ( | const char * | buffer | ) |
Standard library strlen wrapper.
| [in] | buffer | Buffer which length to be calculated. Must be a zero terminated C string. |
Definition at line 35 of file string_util.c.
References MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by _calculate_signature(), _check_client_secret(), _check_rsa_private_key(), _get_header_and_payload_encoded_base64_url(), _join_with_dot(), _ssl_context_callback(), core_processor_get_access_token(), core_processor_register(), core_processor_update_credentials(), json_util_get_string(), mcl_core_get_last_access_token(), mcl_core_get_last_token_time(), mcl_http_client_initialize(), mcl_http_request_add_header(), mcl_http_response_get_header(), mcl_string_util_strlen(), mcl_time_util_validate_timestamp(), security_handler_base64_encode(), security_handler_base64_url_encode(), security_handler_hmac_sha256(), security_rsa_get_modulus_and_exponent(), security_rsa_sign(), string_util_concatenate(), string_util_find(), string_util_find_case_insensitive(), and string_util_strdup().

| void string_util_strncat | ( | char * | destination, |
| const char * | source, | ||
| mcl_size_t | count | ||
| ) |
Standard library strncat wrapper.
| [out] | destination | Destination string. Must be a zero terminated C string. |
| [in] | source | Source string. Must be a zero terminated C string. |
| [in] | count | Specifies how many chars from source will be added at the end of destination. |
Definition at line 105 of file string_util.c.
References MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by mcl_string_util_strncat().

| mcl_error_t string_util_strncmp | ( | const char * | string_1, |
| const char * | string_2, | ||
| mcl_size_t | count | ||
| ) |
Standard library strncmp wrapper.
| [in] | string_1 | Fist string to be compared. Must be a zero terminated C string. |
| [in] | string_2 | Second string to be compared. Must be a zero terminated C string. |
| [in] | count | Specifies how many chars should be compared. |
Definition at line 135 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, and MCL_OK.
Referenced by _check_client_secret(), _check_rsa_private_key(), core_processor_update_credentials(), and mcl_string_util_strncmp().

| void string_util_strncpy | ( | char * | destination, |
| const char * | source, | ||
| mcl_size_t | count | ||
| ) |
Standard library strncpy wrapper. Also sets the terminating null char at the end if source is not longer than count.
| [out] | destination | Destination string. Must be a zero terminated C string. |
| [in] | source | Source string. Must be a zero terminated C string. |
| [in] | count | Specifies how many chars from source will be copied into the destination. |
Definition at line 83 of file string_util.c.
References MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by mcl_http_response_get_header(), and mcl_string_util_strncpy().

| mcl_size_t string_util_strnlen | ( | const char * | buffer, |
| mcl_size_t | maximum_length | ||
| ) |
Standard library strnlen wrapper.
| [in] | buffer | Buffer which length to be calculated. Must be a zero terminated C string. |
| [in] | maximum_length | The maximum length to return. If string is not zero terminated this guarantees not accessing unwanted memory. |
Definition at line 59 of file string_util.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and MCL_NULL_CHAR.
Referenced by core_configuration_validate(), and mcl_string_util_strnlen().

| long string_util_strtol | ( | const char * | source, |
| int | base, | ||
| char ** | end_pointer | ||
| ) |
Returns the first occurrence of an integral value in source string.
| [in] | source | String that contains the integral value as string. |
| [in] | base | The base that the number will be interpreted. |
| [out] | end_pointer | The pointer that points to the one past the last index of integral value. |
Definition at line 402 of file string_util.c.
References MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by mcl_string_util_strtol(), and mcl_time_util_validate_timestamp().
