gmio_core/internal: rename buffer->str for gmio_string_t variables

This commit is contained in:
Hugues Delorme 2015-10-29 11:25:04 +01:00
parent 64e2456728
commit 0981f63658
2 changed files with 21 additions and 25 deletions

View File

@ -28,32 +28,32 @@ void gmio_string_stream_fwd_iterator_init(gmio_string_stream_fwd_iterator_t *it)
} }
gmio_eat_word_error_t gmio_eat_word( gmio_eat_word_error_t gmio_eat_word(
gmio_string_stream_fwd_iterator_t *it, gmio_string_t *buffer) gmio_string_stream_fwd_iterator_t *it, gmio_string_t *str)
{ {
char* buffer_ptr = buffer->ptr; char* str_ptr = str->ptr;
const size_t buffer_capacity = buffer->max_len; const size_t str_capacity = str->max_len;
const char* stream_curr_char = NULL; const char* stream_curr_char = NULL;
size_t i = buffer->len; size_t i = str->len;
/* assert(buffer != NULL && buffer->ptr != NULL); */ /* assert(str != NULL && str->ptr != NULL); */
stream_curr_char = gmio_skip_spaces(it); stream_curr_char = gmio_skip_spaces(it);
if (stream_curr_char == NULL) { /* Empty word */ if (stream_curr_char == NULL) { /* Empty word */
buffer_ptr[i] = 0; str_ptr[i] = 0;
return GMIO_EAT_WORD_ERROR_EMPTY; return GMIO_EAT_WORD_ERROR_EMPTY;
} }
do { do {
buffer_ptr[i] = *stream_curr_char; str_ptr[i] = *stream_curr_char;
stream_curr_char = gmio_next_char(it); stream_curr_char = gmio_next_char(it);
++i; ++i;
} while(i < buffer_capacity } while(i < str_capacity
&& stream_curr_char != NULL && stream_curr_char != NULL
&& !gmio_clocale_isspace(*stream_curr_char)); && !gmio_clocale_isspace(*stream_curr_char));
if (i < buffer_capacity) { if (i < str_capacity) {
buffer_ptr[i] = 0; /* End string with terminating null byte */ str_ptr[i] = 0; /* End string with terminating null byte */
buffer->len = i; str->len = i;
return GMIO_EAT_WORD_ERROR_OK; return GMIO_EAT_WORD_ERROR_OK;
} }
return GMIO_EAT_WORD_ERROR_CAPACITY_OVERFLOW; return GMIO_EAT_WORD_ERROR_CAPACITY_OVERFLOW;

View File

@ -67,12 +67,13 @@ GMIO_INLINE const char *gmio_next_char(
GMIO_INLINE const char* gmio_skip_spaces( GMIO_INLINE const char* gmio_skip_spaces(
gmio_string_stream_fwd_iterator_t* it); gmio_string_stream_fwd_iterator_t* it);
/*! Advances iterator until the first non-space char and copies any space found /*! Advances iterator until the first non-space char and copies in \p str any
* in \p buffer */ * space found */
GMIO_INLINE void gmio_copy_spaces( GMIO_INLINE void gmio_copy_spaces(
gmio_string_stream_fwd_iterator_t* it, gmio_string_stream_fwd_iterator_t* it,
gmio_string_t* buffer); gmio_string_t* str);
/*! Error codes returned by gmio_eat_word() */
enum gmio_eat_word_error enum gmio_eat_word_error
{ {
GMIO_EAT_WORD_ERROR_OK = 0, GMIO_EAT_WORD_ERROR_OK = 0,
@ -81,13 +82,9 @@ enum gmio_eat_word_error
}; };
typedef enum gmio_eat_word_error gmio_eat_word_error_t; typedef enum gmio_eat_word_error gmio_eat_word_error_t;
/*! Advances iterator so that next word is extracted into \p buffer /*! Advances iterator so that next word is extracted into \p str */
*
* \retval 0 On success
* \retval <=-1 On error
*/
gmio_eat_word_error_t gmio_eat_word( gmio_eat_word_error_t gmio_eat_word(
gmio_string_stream_fwd_iterator_t* it, gmio_string_t* buffer); gmio_string_stream_fwd_iterator_t* it, gmio_string_t* str);
#if 0 #if 0
/*! Iterate over stream while it matches input string \p str /*! Iterate over stream while it matches input string \p str
@ -147,17 +144,16 @@ const char* gmio_skip_spaces(
} }
void gmio_copy_spaces( void gmio_copy_spaces(
gmio_string_stream_fwd_iterator_t* it, gmio_string_stream_fwd_iterator_t* it, gmio_string_t* str)
gmio_string_t* buffer)
{ {
const char* curr_char = gmio_current_char(it); const char* curr_char = gmio_current_char(it);
while (curr_char != NULL while (curr_char != NULL
&& gmio_clocale_isspace(*curr_char) && gmio_clocale_isspace(*curr_char)
&& buffer->len < buffer->max_len) && str->len < str->max_len)
{ {
buffer->ptr[buffer->len] = *curr_char; str->ptr[str->len] = *curr_char;
curr_char = gmio_next_char(it); curr_char = gmio_next_char(it);
++buffer->len; ++str->len;
} }
} }