Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefix string_array_t with "utilities" #14

Merged
merged 4 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/c_utilities/split.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ extern "C"
#include "c_utilities/visibility_control.h"

C_UTILITIES_PUBLIC
string_array_t
utilities_string_array_t
utilities_split(const char * str, char delimiter);

C_UTILITIES_PUBLIC
string_array_t
utilities_string_array_t
utilities_split_last(const char * str, char delimiter);

#if __cplusplus
Expand Down
14 changes: 8 additions & 6 deletions include/c_utilities/types/string_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ extern "C"

#include <string.h>

#include "c_utilities/macros.h"
#include "c_utilities/types/utilities_ret.h"
#include "c_utilities/visibility_control.h"

typedef struct C_UTILITIES_PUBLIC_TYPE string_array_t
typedef struct C_UTILITIES_PUBLIC_TYPE utilities_string_array_t
{
size_t size;
char ** data;
} string_array_t;
} utilities_string_array_t;

/// Return an empty string array struct.
/**
Expand All @@ -45,12 +46,12 @@ typedef struct C_UTILITIES_PUBLIC_TYPE string_array_t
* string_array_t foo;
* utilities_string_array_fini(&foo); // undefined behavior!
*
* string_arraty_t bar = utilities_get_zero_initialized_string_array();
* utilities_string_array_t bar = utilities_get_zero_initialized_string_array();
* utilities_string_array_fini(&bar); // ok
* ```
*/
C_UTILITIES_PUBLIC
string_array_t
utilities_string_array_t
utilities_get_zero_initialized_string_array();

/// Return a pre-initialized string array struct.
Expand All @@ -70,7 +71,7 @@ utilities_get_zero_initialized_string_array();
* ```
*/
C_UTILITIES_PUBLIC
string_array_t
utilities_string_array_t
utilities_get_pre_initialized_string_array(size_t size);

/// Free the allocated string array struct.
Expand All @@ -79,8 +80,9 @@ utilities_get_pre_initialized_string_array(size_t size);
* and frees all allocated memory within.
*/
C_UTILITIES_PUBLIC
C_UTILITIES_WARN_UNUSED
utilities_ret_t
utilities_string_array_fini(string_array_t * array);
utilities_string_array_fini(utilities_string_array_t * array);

#if __cplusplus
}
Expand Down
12 changes: 6 additions & 6 deletions src/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ extern "C"
#include "c_utilities/split.h"
#include "c_utilities/types.h"

string_array_t
utilities_string_array_t
utilities_split(const char * str, char delimiter)
{
if (!str || strlen(str) == 0) {
string_array_t empty_array = {0, NULL};
utilities_string_array_t empty_array = {0, NULL};
return empty_array;
}

Expand All @@ -46,7 +46,7 @@ utilities_split(const char * str, char delimiter)
rhs_offset = 1;
}

string_array_t tokens = utilities_get_zero_initialized_string_array();
utilities_string_array_t tokens = utilities_get_zero_initialized_string_array();
tokens.size = 1;
for (size_t i = lhs_offset; i < string_size - rhs_offset; ++i) {
if (str[i] == delimiter) {
Expand Down Expand Up @@ -89,11 +89,11 @@ utilities_split(const char * str, char delimiter)
return tokens;
}

string_array_t
utilities_string_array_t
utilities_split_last(const char * str, char delimiter)
{
if (!str || strlen(str) == 0) {
string_array_t empty_array = {0, NULL};
utilities_string_array_t empty_array = {0, NULL};
return empty_array;
}

Expand All @@ -111,7 +111,7 @@ utilities_split_last(const char * str, char delimiter)
rhs_offset = 1;
}

string_array_t tokens = utilities_get_zero_initialized_string_array();
utilities_string_array_t tokens = utilities_get_zero_initialized_string_array();

size_t found_last = string_size;
for (size_t i = lhs_offset; i < string_size - rhs_offset; ++i) {
Expand Down
12 changes: 6 additions & 6 deletions src/string_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ extern "C"
#include "c_utilities/types/string_array.h"
#include "c_utilities/types/utilities_ret.h"

string_array_t
utilities_string_array_t
utilities_get_zero_initialized_string_array()
{
static string_array_t array = {0, NULL};
static utilities_string_array_t array = {0, NULL};
return array;
}

string_array_t
utilities_string_array_t
utilities_get_pre_initialized_string_array(size_t size)
{
static string_array_t array = {0, NULL};
static utilities_string_array_t array = {0, NULL};
array.size = size;
array.data = (char **)calloc(array.size, sizeof(char *));
return array;
}

utilities_ret_t
utilities_string_array_fini(string_array_t * array)
utilities_string_array_fini(utilities_string_array_t * array)
{
if (!array) {
return UTILITIES_RET_ERROR;
}

if (!array->data) {
return UTILITIES_RET_ERROR;
return UTILITIES_RET_OK;
}

for (size_t i = 0; i < array->size; ++i) {
Expand Down
Loading