gmio_core/internal: add gmio_string_buffer_clear() and gmio_copy_spaces()
This commit is contained in:
parent
9ec37f9a88
commit
9fe35b1fc0
@ -32,14 +32,13 @@ int gmio_eat_word(
|
||||
{
|
||||
const size_t buffer_capacity = buffer->max_len;
|
||||
const char* stream_curr_char = NULL;
|
||||
size_t i = 0;
|
||||
size_t i = buffer->len;
|
||||
|
||||
/* assert(buffer != NULL && buffer->ptr != NULL); */
|
||||
|
||||
buffer->len = 0;
|
||||
stream_curr_char = gmio_skip_spaces(it);
|
||||
if (stream_curr_char == NULL) { /* Empty word */
|
||||
buffer->ptr[0] = 0;
|
||||
buffer->ptr[i] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,13 @@ struct gmio_string_buffer
|
||||
{
|
||||
char* ptr; /*!< Buffer contents */
|
||||
size_t len; /*!< Size(length) of current contents */
|
||||
size_t max_len; /*!< Maximum contents size(length) */
|
||||
size_t max_len; /*!< Maximum contents size(capacity) */
|
||||
};
|
||||
|
||||
typedef struct gmio_string_buffer gmio_string_buffer_t;
|
||||
|
||||
GMIO_INLINE void gmio_string_buffer_clear(gmio_string_buffer_t* buffer);
|
||||
|
||||
/*! Forward iterator over a stream
|
||||
*
|
||||
* To be used with API below.
|
||||
@ -76,10 +78,16 @@ GMIO_INLINE const char* gmio_current_char(
|
||||
GMIO_INLINE const char *gmio_next_char(
|
||||
gmio_string_stream_fwd_iterator_t *it);
|
||||
|
||||
/*! Advances iterator until the next non-space char */
|
||||
/*! Advances iterator until the first non-space char */
|
||||
GMIO_INLINE const char* gmio_skip_spaces(
|
||||
gmio_string_stream_fwd_iterator_t* it);
|
||||
|
||||
/*! Advances iterator until the first non-space char and copies any space found
|
||||
* in \p buffer */
|
||||
GMIO_INLINE void gmio_copy_spaces(
|
||||
gmio_string_stream_fwd_iterator_t* it,
|
||||
gmio_string_buffer_t* buffer);
|
||||
|
||||
/*! Advances iterator so that next word is extracted into \p buffer
|
||||
*
|
||||
* \retval 0 On success
|
||||
@ -108,6 +116,12 @@ GMIO_INLINE int gmio_get_float32(const char* str, gmio_float32_t* value_ptr);
|
||||
* -- Implementation
|
||||
*/
|
||||
|
||||
void gmio_string_buffer_clear(gmio_string_buffer_t* buffer)
|
||||
{
|
||||
buffer->ptr[0] = 0;
|
||||
buffer->len = 0;
|
||||
}
|
||||
|
||||
const char* gmio_current_char(
|
||||
const gmio_string_stream_fwd_iterator_t* it)
|
||||
{
|
||||
@ -143,6 +157,21 @@ const char* gmio_skip_spaces(
|
||||
return curr_char;
|
||||
}
|
||||
|
||||
void gmio_copy_spaces(
|
||||
gmio_string_stream_fwd_iterator_t* it,
|
||||
gmio_string_buffer_t* buffer)
|
||||
{
|
||||
const char* curr_char = gmio_current_char(it);
|
||||
while (curr_char != NULL
|
||||
&& gmio_clocale_isspace(*curr_char)
|
||||
&& buffer->len < buffer->max_len)
|
||||
{
|
||||
buffer->ptr[buffer->len] = *curr_char;
|
||||
curr_char = gmio_next_char(it);
|
||||
++buffer->len;
|
||||
}
|
||||
}
|
||||
|
||||
int gmio_get_float32(const char* str, gmio_float32_t* value_ptr)
|
||||
{
|
||||
#if defined(GMIO_STRINGPARSE_USE_FAST_ATOF)
|
||||
|
Loading…
Reference in New Issue
Block a user