string_type.h
Go to the documentation of this file.
1 /*!**********************************************************************
2 *
3 * @copyright Copyright (C) 2016 Siemens Aktiengesellschaft.\n
4 * All rights reserved.
5 *
6 *************************************************************************
7 *
8 * @file string_type.h
9 * @date Aug 2, 2016
10 * @brief String type module header file.
11 *
12 * This module introduces #string_t type which holds the C string inside along with length information.
13 * Operations that can be performed on this type are also defined in this module.
14 *
15 ************************************************************************/
16 
17 #ifndef STRING_TYPE_H_
18 #define STRING_TYPE_H_
19 
20 #include "list.h"
21 #include "string_util.h"
22 
23 extern const char *hex_table;
24 
33 typedef enum E_MCL_STRING_TYPE
34 {
39 
43 typedef struct string_t
44 {
45  char *buffer;
48 } string_t;
49 
63 E_MCL_ERROR_CODE string_initialize(const string_t *other, string_t **string);
64 
87 E_MCL_ERROR_CODE string_initialize_new(const char *value, mcl_size_t value_length, string_t **string);
88 
112 E_MCL_ERROR_CODE string_initialize_dynamic(const char *value, mcl_size_t value_length, string_t **string);
113 
139 E_MCL_ERROR_CODE string_initialize_static(const char *value, mcl_size_t value_length, string_t **string);
140 
156 E_MCL_ERROR_CODE string_set(string_t *string, const char *value, mcl_size_t value_length);
157 
170 E_MCL_ERROR_CODE string_compare(const string_t *string, const string_t *other);
171 
183 E_MCL_ERROR_CODE string_compare_with_cstr(const string_t *string, const char *other);
184 
198 E_MCL_ERROR_CODE string_split(string_t *string, const char token, list_t **string_list);
199 
215 
223 void string_release(string_t *string);
224 
232 void string_destroy(string_t **string);
233 
246 E_MCL_ERROR_CODE string_concatenate_cstr(string_t *string, char *c_string, string_t **result);
247 
260 E_MCL_ERROR_CODE string_concatenate(string_t *string_1, string_t *string_2, string_t **result);
261 
275 E_MCL_ERROR_CODE string_replace(string_t *source, const char *old_string, const char *new_string, string_t **result);
276 
277 #endif //STRING_TYPE_H_
E_MCL_ERROR_CODE string_initialize_dynamic(const char *value, mcl_size_t value_length, string_t **string)
Initializes a dynamic string_t object with the given value and length.
Definition: string_type.c:68
char * buffer
Buffer of string handle.
Definition: string_type.h:45
E_MCL_ERROR_CODE string_initialize_static(const char *value, mcl_size_t value_length, string_t **string)
Initializes a static string_t object with the given value and length.
Definition: string_type.c:90
E_MCL_STRING_TYPE
This type defines the different kind of string behaviors during string initialization and destroy...
Definition: string_type.h:33
void string_release(string_t *string)
Clears the content of the string. And deallocates the memory.
Definition: string_type.c:298
String utility module implementation file.
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
Definition: mcl_common.h:137
Strings with this type will NOT allocate its buffer during initialization (buffer only points of the ...
Definition: string_type.h:36
E_MCL_STRING_TYPE type
Type of copy and destroy.
Definition: string_type.h:47
E_MCL_ERROR_CODE string_concatenate_cstr(string_t *string, char *c_string, string_t **result)
Concatenates two strings of type string_t into a string_t.
Definition: string_type.c:465
E_MCL_ERROR_CODE string_initialize(const string_t *other, string_t **string)
Initializes an string_t object with another one.
Definition: string_type.c:24
E_MCL_ERROR_CODE string_initialize_new(const char *value, mcl_size_t value_length, string_t **string)
Initializes a new string_t object with the given value and length.
Definition: string_type.c:46
void string_destroy(string_t **string)
Destroys the allocated resources of the string.
Definition: string_type.c:326
uint8_t mcl_uint8_t
Definition: mcl_common.h:43
Strings with this type will allocates its buffer during initialization (copies the initial value to i...
Definition: string_type.h:35
List module header file.
E_MCL_ERROR_CODE string_concatenate(string_t *string_1, string_t *string_2, string_t **result)
Concatenates a C string (i.e. a char array)
Definition: string_type.c:416
mcl_size_t length
Length of buffer.
Definition: string_type.h:46
E_MCL_ERROR_CODE string_replace(string_t *source, const char *old_string, const char *new_string, string_t **result)
Replaces old_string with new_string.
Definition: string_type.c:433
E_MCL_ERROR_CODE string_split(string_t *string, const char token, list_t **string_list)
Splits the string with the given char and returns the result as an list_t of string_t's.
Definition: string_type.c:179
size_t mcl_size_t
Definition: mcl_common.h:38
E_MCL_ERROR_CODE string_compare_with_cstr(const string_t *string, const char *other)
Compare the contents of string_t with a C string.
Definition: string_type.c:139
E_MCL_ERROR_CODE string_convert_binary_to_hex(const mcl_uint8_t *buffer, mcl_size_t buffer_size, string_t **hex_data)
Definition: string_type.c:272
E_MCL_ERROR_CODE string_compare(const string_t *string, const string_t *other)
Compare the contents of two string_t's.
Definition: string_type.c:129
const char * hex_table
Definition: string_type.c:19
E_MCL_ERROR_CODE string_set(string_t *string, const char *value, mcl_size_t value_length)
Sets the buffer of the string with a new value.
Definition: string_type.c:112
Strings with this type will NOT allocate its buffer during initialization (buffer only points of the ...
Definition: string_type.h:37