gmio_core/internal: rename gmio_string::max_len to "capacity"
This commit is contained in:
parent
e97c880343
commit
61a44ca6dc
@ -87,7 +87,7 @@ static void snprintf_wrap(void* cookie, const char* fmt, ...)
|
|||||||
struct gmio_string* str = (struct gmio_string*)cookie;
|
struct gmio_string* str = (struct gmio_string*)cookie;
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
gmio_vsnprintf(str->ptr, str->max_len, fmt, args);
|
gmio_vsnprintf(str->ptr, str->capacity, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,13 +203,13 @@ static void printf_func_exec_time(
|
|||||||
/*! Returns the strlen of the longest tag string */
|
/*! Returns the strlen of the longest tag string */
|
||||||
static size_t find_maxlen_cmp_result_tag(struct benchmark_cmp_result_array res_array)
|
static size_t find_maxlen_cmp_result_tag(struct benchmark_cmp_result_array res_array)
|
||||||
{
|
{
|
||||||
size_t max_len = 0;
|
size_t maxlen = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < res_array.count; ++i) {
|
for (i = 0; i < res_array.count; ++i) {
|
||||||
const size_t len = safe_strlen(res_array.ptr[i].tag);
|
const size_t len = safe_strlen(res_array.ptr[i].tag);
|
||||||
max_len = size_t_max(len, max_len);
|
maxlen = size_t_max(len, maxlen);
|
||||||
}
|
}
|
||||||
return max_len;
|
return maxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Writes in output args the func1 execution informations */
|
/*! Writes in output args the func1 execution informations */
|
||||||
@ -243,16 +243,16 @@ static size_t find_maxlen_cmp_result_func_exec_time(
|
|||||||
{
|
{
|
||||||
char strbuff[1024] = {0};
|
char strbuff[1024] = {0};
|
||||||
struct gmio_string str = gmio_string(strbuff, 0, sizeof(strbuff));
|
struct gmio_string str = gmio_string(strbuff, 0, sizeof(strbuff));
|
||||||
size_t max_len = 0;
|
size_t maxlen = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < res_array.count; ++i) {
|
for (i = 0; i < res_array.count; ++i) {
|
||||||
gmio_time_ms_t time = 0;
|
gmio_time_ms_t time = 0;
|
||||||
bool has_time = false;
|
bool has_time = false;
|
||||||
func_select_exec_infos(&res_array.ptr[i], &time, &has_time);
|
func_select_exec_infos(&res_array.ptr[i], &time, &has_time);
|
||||||
gprintf_func_exec_time(&str, &snprintf_wrap, 0, time, has_time);
|
gprintf_func_exec_time(&str, &snprintf_wrap, 0, time, has_time);
|
||||||
max_len = size_t_max(safe_strlen(strbuff), max_len);
|
maxlen = size_t_max(safe_strlen(strbuff), maxlen);
|
||||||
}
|
}
|
||||||
return max_len;
|
return maxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the strlen of the longest func2/func1 ratio string */
|
/*! Returns the strlen of the longest func2/func1 ratio string */
|
||||||
@ -261,14 +261,14 @@ static size_t find_maxlen_cmp_result_ratio(
|
|||||||
{
|
{
|
||||||
char strbuff[1024] = {0};
|
char strbuff[1024] = {0};
|
||||||
struct gmio_string str = gmio_string(strbuff, 0, sizeof(strbuff));
|
struct gmio_string str = gmio_string(strbuff, 0, sizeof(strbuff));
|
||||||
size_t max_len = 0;
|
size_t maxlen = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < res_array.count; ++i) {
|
for (i = 0; i < res_array.count; ++i) {
|
||||||
const float ratio = res_array.ptr[i].func2_func1_ratio;
|
const float ratio = res_array.ptr[i].func2_func1_ratio;
|
||||||
gprintf_func_exec_ratio(&str, &snprintf_wrap, 0, ratio);
|
gprintf_func_exec_ratio(&str, &snprintf_wrap, 0, ratio);
|
||||||
max_len = size_t_max(safe_strlen(strbuff), max_len);
|
maxlen = size_t_max(safe_strlen(strbuff), maxlen);
|
||||||
}
|
}
|
||||||
return max_len;
|
return maxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_benchmark_cmp_result_ratio(
|
static void update_benchmark_cmp_result_ratio(
|
||||||
|
@ -39,7 +39,7 @@ struct gmio_string
|
|||||||
{
|
{
|
||||||
char* ptr; /*!< Contents */
|
char* ptr; /*!< Contents */
|
||||||
size_t len; /*!< Size(length) of current contents */
|
size_t len; /*!< Size(length) of current contents */
|
||||||
size_t max_len; /*!< Maximum contents size(capacity) */
|
size_t capacity; /*!< Maximum contents size */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Expands to bracket initialization of a gmio_const_string from const char[]
|
/*! Expands to bracket initialization of a gmio_const_string from const char[]
|
||||||
@ -57,11 +57,14 @@ GMIO_INLINE struct gmio_const_string gmio_const_string(const char* ptr, size_t l
|
|||||||
|
|
||||||
/*! Returns an initialized struct gmio_string object
|
/*! Returns an initialized struct gmio_string object
|
||||||
*
|
*
|
||||||
* string.max_len is set to max(len,max_len)
|
* gmio_string::capacity is set to <tt>max(len,capacity)</tt>
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE struct gmio_string gmio_string(char* ptr, size_t len, size_t max_len);
|
GMIO_INLINE struct gmio_string gmio_string(char* ptr, size_t len, size_t capacity);
|
||||||
|
|
||||||
/*! Clears the contents of the string \p str and makes it null */
|
/*! Clears the contents of the string \p str and makes it null
|
||||||
|
*
|
||||||
|
* \warning Memory pointed to by gmio_string::ptr is not freed in any way
|
||||||
|
*/
|
||||||
GMIO_INLINE void gmio_string_clear(struct gmio_string* str);
|
GMIO_INLINE void gmio_string_clear(struct gmio_string* str);
|
||||||
|
|
||||||
/*! Returns a pointer after the last character of \p str */
|
/*! Returns a pointer after the last character of \p str */
|
||||||
@ -90,12 +93,12 @@ struct gmio_const_string gmio_const_string(const char* ptr, size_t len)
|
|||||||
return cstr;
|
return cstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gmio_string gmio_string(char* ptr, size_t len, size_t max_len)
|
struct gmio_string gmio_string(char* ptr, size_t len, size_t capacity)
|
||||||
{
|
{
|
||||||
struct gmio_string str;
|
struct gmio_string str;
|
||||||
str.ptr = ptr;
|
str.ptr = ptr;
|
||||||
str.len = len;
|
str.len = len;
|
||||||
str.max_len = GMIO_MAX(len, max_len);
|
str.capacity = GMIO_MAX(len, capacity);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +116,7 @@ const char* gmio_string_end(const struct gmio_string* str)
|
|||||||
void gmio_string_copy(
|
void gmio_string_copy(
|
||||||
struct gmio_string* dst, const struct gmio_string* src)
|
struct gmio_string* dst, const struct gmio_string* src)
|
||||||
{
|
{
|
||||||
const size_t dst_new_len = GMIO_MIN(dst->max_len, src->len);
|
const size_t dst_new_len = GMIO_MIN(dst->capacity, src->len);
|
||||||
strncpy(dst->ptr, src->ptr, dst_new_len);
|
strncpy(dst->ptr, src->ptr, dst_new_len);
|
||||||
dst->len = dst_new_len;
|
dst->len = dst_new_len;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ enum gmio_eat_word_error gmio_stringstream_eat_word(
|
|||||||
struct gmio_string *str)
|
struct gmio_string *str)
|
||||||
{
|
{
|
||||||
char* str_ptr_at = str->ptr + str->len;
|
char* str_ptr_at = str->ptr + str->len;
|
||||||
const char* str_ptr_end = str->ptr + str->max_len;
|
const char* str_ptr_end = str->ptr + str->capacity;
|
||||||
const char* stream_curr_char = NULL;
|
const char* stream_curr_char = NULL;
|
||||||
|
|
||||||
/* assert(str != NULL && str->ptr != NULL); */
|
/* assert(str != NULL && str->ptr != NULL); */
|
||||||
|
@ -167,7 +167,7 @@ const char *gmio_stringstream_next_char(struct gmio_stringstream *sstream)
|
|||||||
sstream->cookie,
|
sstream->cookie,
|
||||||
&sstream->stream,
|
&sstream->stream,
|
||||||
sstream->strbuff.ptr,
|
sstream->strbuff.ptr,
|
||||||
sstream->strbuff.max_len);
|
sstream->strbuff.capacity);
|
||||||
sstream->strbuff_end = sstream->strbuff.ptr + sstream->strbuff.len;
|
sstream->strbuff_end = sstream->strbuff.ptr + sstream->strbuff.len;
|
||||||
return sstream->strbuff.len > 0 ? sstream->strbuff.ptr : NULL;
|
return sstream->strbuff.len > 0 ? sstream->strbuff.ptr : NULL;
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ void gmio_stringstream_copy_ascii_spaces(
|
|||||||
const char* curr_char = gmio_stringstream_current_char(sstream);
|
const char* curr_char = gmio_stringstream_current_char(sstream);
|
||||||
while (curr_char != NULL
|
while (curr_char != NULL
|
||||||
&& gmio_ascii_isspace(*curr_char)
|
&& gmio_ascii_isspace(*curr_char)
|
||||||
&& str->len < str->max_len)
|
&& str->len < str->capacity)
|
||||||
{
|
{
|
||||||
str->ptr[str->len] = *curr_char;
|
str->ptr[str->len] = *curr_char;
|
||||||
curr_char = gmio_stringstream_next_char(sstream);
|
curr_char = gmio_stringstream_next_char(sstream);
|
||||||
|
@ -134,7 +134,7 @@ int gmio_stla_read(
|
|||||||
|
|
||||||
parse_data.strstream.stream = *stream;
|
parse_data.strstream.stream = *stream;
|
||||||
parse_data.strstream.strbuff.ptr = mblock->ptr;
|
parse_data.strstream.strbuff.ptr = mblock->ptr;
|
||||||
parse_data.strstream.strbuff.max_len = mblock->size;
|
parse_data.strstream.strbuff.capacity = mblock->size;
|
||||||
parse_data.strstream.cookie = &parse_data.strstream_cookie;
|
parse_data.strstream.cookie = &parse_data.strstream_cookie;
|
||||||
parse_data.strstream.func_stream_read = gmio_stringstream_stla_read;
|
parse_data.strstream.func_stream_read = gmio_stringstream_stla_read;
|
||||||
gmio_stringstream_init_pos(&parse_data.strstream);
|
gmio_stringstream_init_pos(&parse_data.strstream);
|
||||||
@ -449,7 +449,7 @@ int gmio_stla_eat_next_token_inplace(
|
|||||||
data->token_str.ptr[i++] = *(it++);
|
data->token_str.ptr[i++] = *(it++);
|
||||||
}
|
}
|
||||||
/* -- Copy the non matching part */
|
/* -- Copy the non matching part */
|
||||||
while (i < data->token_str.max_len
|
while (i < data->token_str.capacity
|
||||||
&& stream_char != NULL
|
&& stream_char != NULL
|
||||||
&& !gmio_ascii_isspace(*stream_char))
|
&& !gmio_ascii_isspace(*stream_char))
|
||||||
{
|
{
|
||||||
@ -457,7 +457,7 @@ int gmio_stla_eat_next_token_inplace(
|
|||||||
stream_char = gmio_stringstream_next_char(sstream);
|
stream_char = gmio_stringstream_next_char(sstream);
|
||||||
}
|
}
|
||||||
/* -- Fill remaining space with NUL byte */
|
/* -- Fill remaining space with NUL byte */
|
||||||
memset(data->token_str.ptr + i, '\0', data->token_str.max_len - i);
|
memset(data->token_str.ptr + i, '\0', data->token_str.capacity - i);
|
||||||
data->token_str.len = i;
|
data->token_str.len = i;
|
||||||
data->token = stla_find_token_from_string(&data->token_str);
|
data->token = stla_find_token_from_string(&data->token_str);
|
||||||
|
|
||||||
@ -501,7 +501,7 @@ int gmio_stla_eat_until_token(
|
|||||||
strbuff->len = previous_buff_len;
|
strbuff->len = previous_buff_len;
|
||||||
strbuff->ptr[previous_buff_len] = 0;
|
strbuff->ptr[previous_buff_len] = 0;
|
||||||
}
|
}
|
||||||
} while (!end_token_found && strbuff->len < strbuff->max_len);
|
} while (!end_token_found && strbuff->len < strbuff->capacity);
|
||||||
|
|
||||||
if (!end_token_found) {
|
if (!end_token_found) {
|
||||||
stla_error_msg(
|
stla_error_msg(
|
||||||
|
@ -227,8 +227,7 @@ const char* test_internal__stringstream()
|
|||||||
|
|
||||||
/* Test with very small string buffer */
|
/* Test with very small string buffer */
|
||||||
buff.pos = 0;
|
buff.pos = 0;
|
||||||
sstream.strbuff.ptr = cstr_small;
|
sstream.strbuff = gmio_string(cstr_small, 0, sizeof(cstr_small));
|
||||||
sstream.strbuff.max_len = sizeof(cstr_small);
|
|
||||||
gmio_stringstream_init_pos(&sstream);
|
gmio_stringstream_init_pos(&sstream);
|
||||||
|
|
||||||
UTEST_ASSERT(*gmio_stringstream_current_char(&sstream) == 'U');
|
UTEST_ASSERT(*gmio_stringstream_current_char(&sstream) == 'U');
|
||||||
|
Loading…
Reference in New Issue
Block a user