gmio_core: rename gmio_stringstream_init() to gmio_stringstream_init_pos()

This commit is contained in:
Hugues Delorme 2016-01-13 10:04:41 +01:00
parent 351bb6cafc
commit f2a1665493
4 changed files with 63 additions and 71 deletions

View File

@ -23,11 +23,11 @@ struct gmio_stringstream gmio_stringstream(
struct gmio_stringstream sstream = {0}; struct gmio_stringstream sstream = {0};
sstream.stream = stream; sstream.stream = stream;
sstream.strbuff = strbuff; sstream.strbuff = strbuff;
gmio_stringstream_init(&sstream); gmio_stringstream_init_pos(&sstream);
return sstream; return sstream;
} }
void gmio_stringstream_init(struct gmio_stringstream *sstream) void gmio_stringstream_init_pos(struct gmio_stringstream *sstream)
{ {
/* Trick: declaring the buffer exhausted will actually trigger the first /* Trick: declaring the buffer exhausted will actually trigger the first
* call to gmio_stream_read() inside gmio_next_char() * call to gmio_stream_read() inside gmio_next_char()

View File

@ -43,11 +43,8 @@ struct gmio_stringstream gmio_stringstream(
const struct gmio_stream stream, const struct gmio_stream stream,
const struct gmio_string strbuff); const struct gmio_string strbuff);
/*! Initializes position indicator /*! Initializes position indicator */
* void gmio_stringstream_init_pos(struct gmio_stringstream* sstream);
* TODO: rename to gmio_stringstream_initpos()
*/
void gmio_stringstream_init(struct gmio_stringstream* sstream);
/*! Returns the char where the iterator is currently pointing at */ /*! Returns the char where the iterator is currently pointing at */
GMIO_INLINE const char* gmio_stringstream_current_char( GMIO_INLINE const char* gmio_stringstream_current_char(

View File

@ -168,7 +168,7 @@ int gmio_stla_read(struct gmio_stl_read_args* args)
parse_data.strstream.strbuff.max_len = core_args->stream_memblock.size; parse_data.strstream.strbuff.max_len = core_args->stream_memblock.size;
parse_data.strstream.cookie = &parse_data.strstream_cookie; parse_data.strstream.cookie = &parse_data.strstream_cookie;
parse_data.strstream.func_stream_read_hook = gmio_stringstream_stla_read_hook; parse_data.strstream.func_stream_read_hook = gmio_stringstream_stla_read_hook;
gmio_stringstream_init(&parse_data.strstream); gmio_stringstream_init_pos(&parse_data.strstream);
parse_data.string_buffer.ptr = &fixed_buffer[0]; parse_data.string_buffer.ptr = &fixed_buffer[0];
parse_data.string_buffer.len = 0; parse_data.string_buffer.len = 0;

View File

@ -99,10 +99,12 @@ static gmio_bool_t gmio_test_calculation_atof(const char* val_str)
{ /* Test gmio_stringstream_fast_atof() */ { /* Test gmio_stringstream_fast_atof() */
char iobuff[512] = {0}; char iobuff[512] = {0};
struct gmio_ro_buffer ibuff = gmio_ro_buffer(val_str, strlen(val_str), 0); struct gmio_ro_buffer ibuff =
struct gmio_stringstream sstream = gmio_stringstream( gmio_ro_buffer(val_str, strlen(val_str), 0);
struct gmio_stringstream sstream =
gmio_stringstream(
gmio_istream_buffer(&ibuff), gmio_istream_buffer(&ibuff),
gmio_string(iobuff, 0, GMIO_ARRAY_SIZE(iobuff))); gmio_string(iobuff, 0, sizeof(iobuff)));
const gmio_float32_t fast_val = gmio_stringstream_fast_atof(&sstream); const gmio_float32_t fast_val = gmio_stringstream_fast_atof(&sstream);
if (gmio_float32_ulp_equals(fast_val, std_val, 1)) { if (gmio_float32_ulp_equals(fast_val, std_val, 1)) {
++accurate_count; ++accurate_count;
@ -185,86 +187,79 @@ const char* test_internal__stringstream()
"Parfois le chemin est rude.\n" "Parfois le chemin est rude.\n"
"pi : 3.1415926535897932384626433832795"; "pi : 3.1415926535897932384626433832795";
{ {
struct gmio_ro_buffer buff = { text, sizeof(text) - 1, 0 }; struct gmio_ro_buffer buff =
gmio_ro_buffer(text, sizeof(text) - 1, 0);
char small_fwd_it_str[4]; char cstr_small[4];
char fwd_it_str[32]; char cstr[32];
struct gmio_stringstream fwd_it = {0}; struct gmio_stringstream sstream =
gmio_stringstream(
gmio_istream_buffer(&buff),
gmio_string(cstr, 0, sizeof(cstr)));
char copy_str[128]; char cstr_copy[128];
struct gmio_string copy_strbuff; struct gmio_string str_copy =
gmio_string(cstr_copy, 0, sizeof(cstr_copy));
fwd_it.stream = gmio_istream_buffer(&buff); UTEST_ASSERT(gmio_stringstream_current_char(&sstream) != NULL);
fwd_it.strbuff.ptr = fwd_it_str; UTEST_ASSERT(*gmio_stringstream_current_char(&sstream) == 'U');
fwd_it.strbuff.max_len = sizeof(fwd_it_str);
gmio_stringstream_init(&fwd_it);
copy_strbuff.ptr = copy_str; str_copy.len = 0;
copy_strbuff.max_len = sizeof(copy_str); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
UTEST_ASSERT(gmio_stringstream_current_char(&fwd_it) != NULL);
UTEST_ASSERT(*gmio_stringstream_current_char(&fwd_it) == 'U');
copy_strbuff.len = 0;
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0);
/* printf("\ncopy_strbuff.ptr = \"%s\"\n", copy_strbuff.ptr); */ /* printf("\ncopy_strbuff.ptr = \"%s\"\n", copy_strbuff.ptr); */
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Une") == 0); UTEST_ASSERT(strcmp(str_copy.ptr, "Une") == 0);
copy_strbuff.len = 0; str_copy.len = 0;
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0); UTEST_ASSERT(strcmp(str_copy.ptr, "citation,") == 0);
copy_strbuff.len = 0; str_copy.len = 0;
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "o") == 0); UTEST_ASSERT(strcmp(str_copy.ptr, "o") == 0);
copy_strbuff.len = 0; str_copy.len = 0;
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "je") == 0); UTEST_ASSERT(strcmp(str_copy.ptr, "je") == 0);
gmio_stringstream_skip_ascii_spaces(&fwd_it); gmio_stringstream_skip_ascii_spaces(&sstream);
UTEST_ASSERT(gmio_stringstream_next_char(&fwd_it) != NULL); UTEST_ASSERT(gmio_stringstream_next_char(&sstream) != NULL);
UTEST_ASSERT(*gmio_stringstream_current_char(&fwd_it) == 'r'); UTEST_ASSERT(*gmio_stringstream_current_char(&sstream) == 'r');
/* Test with very small string buffer */ /* Test with very small string buffer */
buff.pos = 0; buff.pos = 0;
fwd_it.strbuff.ptr = small_fwd_it_str; sstream.strbuff.ptr = cstr_small;
fwd_it.strbuff.max_len = sizeof(small_fwd_it_str); sstream.strbuff.max_len = sizeof(cstr_small);
gmio_stringstream_init(&fwd_it); gmio_stringstream_init_pos(&sstream);
UTEST_ASSERT(*gmio_stringstream_current_char(&fwd_it) == 'U'); UTEST_ASSERT(*gmio_stringstream_current_char(&sstream) == 'U');
copy_strbuff.len = 0; str_copy.len = 0;
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
copy_strbuff.len = 0; str_copy.len = 0;
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0); UTEST_ASSERT(strcmp(str_copy.ptr, "citation,") == 0);
} }
{ {
struct gmio_ro_buffer buff = { text, sizeof(text) - 1, 0 }; struct gmio_ro_buffer buff =
gmio_ro_buffer(text, sizeof(text) - 1, 0);
char fwd_it_str[32]; char cstr[32];
struct gmio_stringstream fwd_it = {0}; struct gmio_stringstream sstream =
gmio_stringstream(
gmio_istream_buffer(&buff),
gmio_string(cstr, 0, sizeof(cstr)));
char copy_str[128]; char cstr_copy[128];
struct gmio_string copy_strbuff; struct gmio_string str_copy =
gmio_string(cstr_copy, 0, sizeof(cstr_copy));
fwd_it.stream = gmio_istream_buffer(&buff); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
fwd_it.strbuff.ptr = fwd_it_str; UTEST_ASSERT(strcmp(str_copy.ptr, "Une") == 0);
fwd_it.strbuff.max_len = sizeof(fwd_it_str);
gmio_stringstream_init(&fwd_it);
copy_strbuff.ptr = copy_str; UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
copy_strbuff.len = 0; UTEST_ASSERT(strcmp(str_copy.ptr, "Unecitation,") == 0);
copy_strbuff.max_len = sizeof(copy_str); UTEST_ASSERT(gmio_stringstream_eat_word(&sstream, &str_copy) == 0);
UTEST_ASSERT(strcmp(str_copy.ptr, "Unecitation,o") == 0);
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Une") == 0);
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Unecitation,") == 0);
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, &copy_strbuff) == 0);
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Unecitation,o") == 0);
} }
return NULL; return NULL;