gmio_core/internal: rename gmio_string_stream_fwd_iterator -> gmio_stringstream
This commit is contained in:
parent
083a885d0f
commit
c1db98e8c3
@ -68,10 +68,10 @@
|
|||||||
# define GMIO_TARGET_ARCH_BIT_SIZE @GMIO_TARGET_ARCH_BIT_SIZE@
|
# define GMIO_TARGET_ARCH_BIT_SIZE @GMIO_TARGET_ARCH_BIT_SIZE@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Header: gmio_core/internal/string_parse.h */
|
/* Header: gmio_core/internal/stringstream.h */
|
||||||
#ifndef GMIO_STRINGPARSE_USE_FAST_ATOF
|
#ifndef GMIO_STRINGSTREAM_USE_FAST_ATOF
|
||||||
/* Use fast_atof() instead of std string-to-float functions */
|
/* Use fast_atof() instead of std string-to-float functions */
|
||||||
# define GMIO_STRINGPARSE_USE_FAST_ATOF
|
# define GMIO_STRINGSTREAM_USE_FAST_ATOF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Header: gmio_core/internal/string_utils.h */
|
/* Header: gmio_core/internal/string_utils.h */
|
||||||
|
@ -13,23 +13,23 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "string_parse.h"
|
#include "stringstream.h"
|
||||||
|
|
||||||
#include "helper_stream.h"
|
#include "helper_stream.h"
|
||||||
|
|
||||||
void gmio_string_stream_fwd_iterator_init(gmio_string_stream_fwd_iterator_t *it)
|
void gmio_stringstream_init(gmio_stringstream_t *it)
|
||||||
{
|
{
|
||||||
/* 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()
|
||||||
*/
|
*/
|
||||||
it->strbuff.len = 0;
|
it->strbuff.len = 0;
|
||||||
it->strbuff_ptr_end = it->strbuff.ptr;
|
it->strbuff_end = it->strbuff.ptr;
|
||||||
it->strbuff_ptr_at = it->strbuff_ptr_end;
|
it->strbuff_at = it->strbuff_end;
|
||||||
gmio_next_char(it);
|
gmio_stringstream_next_char(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
gmio_eat_word_error_t gmio_eat_word(
|
gmio_eat_word_error_t gmio_stringstream_eat_word(
|
||||||
gmio_string_stream_fwd_iterator_t *it, gmio_string_t *str)
|
gmio_stringstream_t *it, gmio_string_t *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->max_len;
|
||||||
@ -37,7 +37,7 @@ gmio_eat_word_error_t gmio_eat_word(
|
|||||||
|
|
||||||
/* assert(str != NULL && str->ptr != NULL); */
|
/* assert(str != NULL && str->ptr != NULL); */
|
||||||
|
|
||||||
stream_curr_char = gmio_skip_spaces(it);
|
stream_curr_char = gmio_stringstream_skip_ascii_spaces(it);
|
||||||
if (stream_curr_char == NULL) { /* Empty word */
|
if (stream_curr_char == NULL) { /* Empty word */
|
||||||
*str_ptr_at = 0;
|
*str_ptr_at = 0;
|
||||||
return GMIO_EAT_WORD_ERROR_EMPTY;
|
return GMIO_EAT_WORD_ERROR_EMPTY;
|
||||||
@ -45,7 +45,7 @@ gmio_eat_word_error_t gmio_eat_word(
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
*str_ptr_at = *stream_curr_char;
|
*str_ptr_at = *stream_curr_char;
|
||||||
stream_curr_char = gmio_next_char(it);
|
stream_curr_char = gmio_stringstream_next_char(it);
|
||||||
++str_ptr_at;
|
++str_ptr_at;
|
||||||
} while (stream_curr_char != NULL
|
} while (stream_curr_char != NULL
|
||||||
&& !gmio_ascii_isspace(*stream_curr_char)
|
&& !gmio_ascii_isspace(*stream_curr_char)
|
||||||
@ -60,15 +60,15 @@ gmio_eat_word_error_t gmio_eat_word(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
gmio_bool_t gmio_checked_next_chars(
|
gmio_bool_t gmio_stringstream_checked_next_chars(
|
||||||
gmio_string_stream_fwd_iterator_t *it, const char *str)
|
gmio_stringstream_t *it, const char *str)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
const char* curr_char = gmio_current_char(it);
|
const char* curr_char = gmio_stringstream_current_char(it);
|
||||||
gmio_bool_t same = curr_char != NULL && *curr_char == *str;
|
gmio_bool_t same = curr_char != NULL && *curr_char == *str;
|
||||||
|
|
||||||
while (same) {
|
while (same) {
|
||||||
curr_char = gmio_next_char(it);
|
curr_char = gmio_stringstream_next_char(it);
|
||||||
same = curr_char != NULL && *curr_char == str[++pos];
|
same = curr_char != NULL && *curr_char == str[++pos];
|
||||||
}
|
}
|
||||||
|
|
@ -13,60 +13,54 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef GMIO_INTERNAL_STRING_PARSE_H
|
#ifndef GMIO_INTERNAL_STRINGSTREAM_H
|
||||||
#define GMIO_INTERNAL_STRING_PARSE_H
|
#define GMIO_INTERNAL_STRINGSTREAM_H
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "../stream.h"
|
#include "../stream.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
/*! Forward iterator over a stream
|
/*! Stream that operates on a string
|
||||||
*
|
*
|
||||||
* To be used with API below.
|
* To be used with API below.
|
||||||
* It allows to iterate over a stream (until end is reached) as if it was a
|
* It allows to iterate over a stream (until end is reached) as if it was a
|
||||||
* string.
|
* string.
|
||||||
*
|
|
||||||
* TODO: rename to gmio_string_stream
|
|
||||||
*/
|
*/
|
||||||
struct gmio_string_stream_fwd_iterator
|
struct gmio_stringstream
|
||||||
{
|
{
|
||||||
gmio_stream_t* stream;
|
gmio_stream_t* stream;
|
||||||
gmio_string_t strbuff;
|
gmio_string_t strbuff;
|
||||||
const char* strbuff_ptr_end; /*!< Position after last char in strbuff */
|
const char* strbuff_end; /*!< Position after last char in strbuff */
|
||||||
const char* strbuff_ptr_at; /*!< Position indicator in buffer */
|
const char* strbuff_at; /*!< Position indicator in buffer */
|
||||||
|
|
||||||
void* cookie;
|
void* cookie;
|
||||||
void (*func_stream_read_hook)(void* cookie, const gmio_string_t* strbuff);
|
void (*func_stream_read_hook)(void* cookie, const gmio_string_t* strbuff);
|
||||||
};
|
};
|
||||||
|
typedef struct gmio_stringstream gmio_stringstream_t;
|
||||||
typedef struct gmio_string_stream_fwd_iterator
|
|
||||||
gmio_string_stream_fwd_iterator_t;
|
|
||||||
|
|
||||||
/*! Initializes iterator */
|
/*! Initializes iterator */
|
||||||
void gmio_string_stream_fwd_iterator_init(
|
void gmio_stringstream_init(gmio_stringstream_t* it);
|
||||||
gmio_string_stream_fwd_iterator_t* it);
|
|
||||||
|
|
||||||
/*! 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_current_char(
|
GMIO_INLINE const char* gmio_stringstream_current_char(
|
||||||
const gmio_string_stream_fwd_iterator_t* it);
|
const gmio_stringstream_t* it);
|
||||||
|
|
||||||
/*! Moves on next char in stream */
|
/*! Moves on next char in stream */
|
||||||
GMIO_INLINE const char* gmio_next_char(
|
GMIO_INLINE const char* gmio_stringstream_next_char(
|
||||||
gmio_string_stream_fwd_iterator_t *it);
|
gmio_stringstream_t *it);
|
||||||
|
|
||||||
/*! Moves on next char in stream */
|
/*! Moves on next char in stream */
|
||||||
GMIO_INLINE gmio_string_stream_fwd_iterator_t* gmio_move_next_char(
|
GMIO_INLINE gmio_stringstream_t* gmio_stringstream_move_next_char(
|
||||||
gmio_string_stream_fwd_iterator_t *it);
|
gmio_stringstream_t *it);
|
||||||
|
|
||||||
/*! Advances iterator until the first non-space char */
|
/*! Advances iterator until the first non-space char */
|
||||||
GMIO_INLINE const char* gmio_skip_spaces(
|
GMIO_INLINE const char* gmio_stringstream_skip_ascii_spaces(
|
||||||
gmio_string_stream_fwd_iterator_t* it);
|
gmio_stringstream_t* it);
|
||||||
|
|
||||||
/*! Advances iterator until the first non-space char and copies in \p str any
|
/*! Advances iterator until the first non-space char and copies in \p str any
|
||||||
* space found */
|
* space found */
|
||||||
GMIO_INLINE void gmio_copy_spaces(
|
GMIO_INLINE void gmio_stringstream_copy_ascii_spaces(
|
||||||
gmio_string_stream_fwd_iterator_t* it,
|
gmio_stringstream_t* it, gmio_string_t* str);
|
||||||
gmio_string_t* str);
|
|
||||||
|
|
||||||
/*! Error codes returned by gmio_eat_word() */
|
/*! Error codes returned by gmio_eat_word() */
|
||||||
enum gmio_eat_word_error
|
enum gmio_eat_word_error
|
||||||
@ -78,30 +72,35 @@ 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 str */
|
/*! Advances iterator so that next word is extracted into \p str */
|
||||||
gmio_eat_word_error_t gmio_eat_word(
|
gmio_eat_word_error_t gmio_stringstream_eat_word(
|
||||||
gmio_string_stream_fwd_iterator_t* it, gmio_string_t* str);
|
gmio_stringstream_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
|
||||||
*
|
*
|
||||||
* Returns GMIO_TRUE if \p str was fully matched
|
* Returns GMIO_TRUE if \p str was fully matched
|
||||||
*/
|
*/
|
||||||
gmio_bool_t gmio_checked_next_chars(
|
gmio_bool_t gmio_stringstream_checked_next_chars(
|
||||||
gmio_string_stream_fwd_iterator_t* it, const char* str);
|
gmio_stringstream_t* it, const char* str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*! Parses float from string iterator \p it */
|
/*! Parses float from string iterator \p it */
|
||||||
GMIO_INLINE gmio_float32_t gmio_parse_float32(
|
GMIO_INLINE gmio_float32_t gmio_stringstream_parse_float32(
|
||||||
gmio_string_stream_fwd_iterator_t* it);
|
gmio_stringstream_t* it);
|
||||||
|
|
||||||
/*! Converts C string \p str to float
|
/*! Converts C string \p str to float
|
||||||
*
|
*
|
||||||
* \retval 0 On success
|
* \retval 0 On success
|
||||||
* \retval -1 On error(check \c errno to see what happened)
|
* \retval -1 On error(check \c errno to see what happened)
|
||||||
|
*
|
||||||
|
* TODO: move to another header
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE int gmio_get_float32(const char* str, gmio_float32_t* value_ptr);
|
GMIO_INLINE int gmio_get_float32(const char* str, gmio_float32_t* value_ptr);
|
||||||
|
|
||||||
/*! Converts C string \p str to float */
|
/*! Converts C string \p str to float
|
||||||
|
*
|
||||||
|
* TODO: move to another header
|
||||||
|
*/
|
||||||
GMIO_INLINE gmio_float32_t gmio_to_float32(const char* str);
|
GMIO_INLINE gmio_float32_t gmio_to_float32(const char* str);
|
||||||
|
|
||||||
|
|
||||||
@ -112,33 +111,32 @@ GMIO_INLINE gmio_float32_t gmio_to_float32(const char* str);
|
|||||||
|
|
||||||
#include "helper_stream.h"
|
#include "helper_stream.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
#ifdef GMIO_STRINGPARSE_USE_FAST_ATOF
|
#ifdef GMIO_STRINGSTREAM_USE_FAST_ATOF
|
||||||
# include "fast_atof.h"
|
# include "fast_atof.h"
|
||||||
# include "string_parse_fast_atof.h"
|
# include "stringstream_fast_atof.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
const char* gmio_current_char(
|
const char* gmio_stringstream_current_char(const gmio_stringstream_t* it)
|
||||||
const gmio_string_stream_fwd_iterator_t* it)
|
|
||||||
{
|
{
|
||||||
return it->strbuff_ptr_at < it->strbuff_ptr_end ?
|
return it->strbuff_at < it->strbuff_end ?
|
||||||
it->strbuff_ptr_at :
|
it->strbuff_at :
|
||||||
NULL;
|
NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *gmio_next_char(gmio_string_stream_fwd_iterator_t *it)
|
const char *gmio_stringstream_next_char(gmio_stringstream_t *it)
|
||||||
{
|
{
|
||||||
++(it->strbuff_ptr_at);
|
++(it->strbuff_at);
|
||||||
if (it->strbuff_ptr_at < it->strbuff_ptr_end)
|
if (it->strbuff_at < it->strbuff_end)
|
||||||
return it->strbuff_ptr_at;
|
return it->strbuff_at;
|
||||||
|
|
||||||
/* Read next chunk of data */
|
/* Read next chunk of data */
|
||||||
it->strbuff_ptr_at = it->strbuff.ptr;
|
it->strbuff_at = it->strbuff.ptr;
|
||||||
it->strbuff.len = gmio_stream_read(
|
it->strbuff.len = gmio_stream_read(
|
||||||
it->stream, it->strbuff.ptr, sizeof(char), it->strbuff.max_len);
|
it->stream, it->strbuff.ptr, sizeof(char), it->strbuff.max_len);
|
||||||
it->strbuff_ptr_end = it->strbuff.ptr + it->strbuff.len;
|
it->strbuff_end = it->strbuff.ptr + it->strbuff.len;
|
||||||
if (it->strbuff.len > 0) {
|
if (it->strbuff.len > 0) {
|
||||||
if (it->func_stream_read_hook != NULL)
|
if (it->func_stream_read_hook != NULL)
|
||||||
it->func_stream_read_hook(it->cookie, &it->strbuff);
|
it->func_stream_read_hook(it->cookie, &it->strbuff);
|
||||||
@ -147,39 +145,37 @@ const char *gmio_next_char(gmio_string_stream_fwd_iterator_t *it)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gmio_string_stream_fwd_iterator_t* gmio_move_next_char(
|
gmio_stringstream_t* gmio_stringstream_move_next_char(gmio_stringstream_t *it)
|
||||||
gmio_string_stream_fwd_iterator_t *it)
|
|
||||||
{
|
{
|
||||||
gmio_next_char(it);
|
gmio_stringstream_next_char(it);
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* gmio_skip_spaces(
|
const char* gmio_stringstream_skip_ascii_spaces(gmio_stringstream_t* it)
|
||||||
gmio_string_stream_fwd_iterator_t* it)
|
|
||||||
{
|
{
|
||||||
const char* curr_char = gmio_current_char(it);
|
const char* curr_char = gmio_stringstream_current_char(it);
|
||||||
while (curr_char != NULL && gmio_ascii_isspace(*curr_char))
|
while (curr_char != NULL && gmio_ascii_isspace(*curr_char))
|
||||||
curr_char = gmio_next_char(it);
|
curr_char = gmio_stringstream_next_char(it);
|
||||||
return curr_char;
|
return curr_char;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gmio_copy_spaces(
|
void gmio_stringstream_copy_ascii_spaces(
|
||||||
gmio_string_stream_fwd_iterator_t* it, gmio_string_t* str)
|
gmio_stringstream_t* it, gmio_string_t* str)
|
||||||
{
|
{
|
||||||
const char* curr_char = gmio_current_char(it);
|
const char* curr_char = gmio_stringstream_current_char(it);
|
||||||
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->max_len)
|
||||||
{
|
{
|
||||||
str->ptr[str->len] = *curr_char;
|
str->ptr[str->len] = *curr_char;
|
||||||
curr_char = gmio_next_char(it);
|
curr_char = gmio_stringstream_next_char(it);
|
||||||
++str->len;
|
++str->len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int gmio_get_float32(const char* str, gmio_float32_t* value_ptr)
|
int gmio_get_float32(const char* str, gmio_float32_t* value_ptr)
|
||||||
{
|
{
|
||||||
#if defined(GMIO_STRINGPARSE_USE_FAST_ATOF)
|
#if defined(GMIO_STRINGSTREAM_USE_FAST_ATOF)
|
||||||
const char* end_ptr = NULL;
|
const char* end_ptr = NULL;
|
||||||
*value_ptr = fast_strtof(str, &end_ptr);
|
*value_ptr = fast_strtof(str, &end_ptr);
|
||||||
#elif defined(GMIO_HAVE_STRTOF_FUNC) /* Requires C99 */
|
#elif defined(GMIO_HAVE_STRTOF_FUNC) /* Requires C99 */
|
||||||
@ -194,7 +190,7 @@ int gmio_get_float32(const char* str, gmio_float32_t* value_ptr)
|
|||||||
|
|
||||||
gmio_float32_t gmio_to_float32(const char* str)
|
gmio_float32_t gmio_to_float32(const char* str)
|
||||||
{
|
{
|
||||||
#if defined(GMIO_STRINGPARSE_USE_FAST_ATOF)
|
#if defined(GMIO_STRINGSTREAM_USE_FAST_ATOF)
|
||||||
return fast_atof(str);
|
return fast_atof(str);
|
||||||
#elif defined(GMIO_HAVE_STRTOF_FUNC) /* Requires C99 */
|
#elif defined(GMIO_HAVE_STRTOF_FUNC) /* Requires C99 */
|
||||||
return strtof(str, NULL);
|
return strtof(str, NULL);
|
||||||
@ -203,16 +199,16 @@ gmio_float32_t gmio_to_float32(const char* str)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gmio_float32_t gmio_parse_float32(gmio_string_stream_fwd_iterator_t* it)
|
gmio_float32_t gmio_stringstream_parse_float32(gmio_stringstream_t* it)
|
||||||
{
|
{
|
||||||
#if defined(GMIO_STRINGPARSE_USE_FAST_ATOF)
|
#if defined(GMIO_STRINGSTREAM_USE_FAST_ATOF)
|
||||||
return gmio_fast_atof(it);
|
return gmio_stringstream_fast_atof(it);
|
||||||
#else
|
#else
|
||||||
char strbuff_ptr[64];
|
char strbuff_ptr[64];
|
||||||
gmio_string_t strbuff = { &strbuff_ptr[0], 0, sizeof(strbuff_ptr) };
|
gmio_string_t strbuff = { &strbuff_ptr[0], 0, sizeof(strbuff_ptr) };
|
||||||
gmio_eat_word(it, &strbuff);
|
gmio_stringstream_eat_word(it, &strbuff);
|
||||||
return (gmio_float32_t)atof(strbuff_ptr);
|
return (gmio_float32_t)atof(strbuff_ptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STRING_PARSE_H */
|
#endif /* GMIO_INTERNAL_STRINGSTREAM_H */
|
@ -6,57 +6,60 @@
|
|||||||
|
|
||||||
/* Adapted to ISO-C90 */
|
/* Adapted to ISO-C90 */
|
||||||
|
|
||||||
#ifndef GMIO_INTERNAL_STRING_PARSE_FAST_ATOF_H
|
#ifndef GMIO_INTERNAL_STRINGSTREAM_FAST_ATOF_H
|
||||||
#define GMIO_INTERNAL_STRING_PARSE_FAST_ATOF_H
|
#define GMIO_INTERNAL_STRINGSTREAM_FAST_ATOF_H
|
||||||
|
|
||||||
#include "fast_atof.h"
|
#include "fast_atof.h"
|
||||||
#include "string_parse.h"
|
#include "stringstream.h"
|
||||||
|
|
||||||
GMIO_INLINE uint32_t gmio_strtoul10(gmio_string_stream_fwd_iterator_t* it)
|
GMIO_INLINE uint32_t gmio_stringstream_strtoul10(gmio_stringstream_t* it)
|
||||||
{
|
{
|
||||||
unsigned int value = 0;
|
unsigned int value = 0;
|
||||||
const char* in = gmio_current_char(it);
|
const char* in = gmio_stringstream_current_char(it);
|
||||||
for (; in != NULL && gmio_ascii_isdigit(*in); in = gmio_next_char(it))
|
for (;
|
||||||
|
in != NULL && gmio_ascii_isdigit(*in);
|
||||||
|
in = gmio_stringstream_next_char(it))
|
||||||
|
{
|
||||||
value = (value * 10) + (*in - '0');
|
value = (value * 10) + (*in - '0');
|
||||||
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE int32_t gmio_strtol10(gmio_string_stream_fwd_iterator_t* it)
|
GMIO_INLINE int32_t gmio_stringstream_strtol10(gmio_stringstream_t* it)
|
||||||
{
|
{
|
||||||
const char* in = gmio_current_char(it);
|
const char* in = gmio_stringstream_current_char(it);
|
||||||
const gmio_bool_t inv = (*in == '-');
|
const gmio_bool_t inv = (*in == '-');
|
||||||
int value = 0;
|
int value = 0;
|
||||||
if (inv || *in == '+')
|
if (inv || *in == '+')
|
||||||
in = gmio_next_char(it);
|
in = gmio_stringstream_next_char(it);
|
||||||
|
|
||||||
value = gmio_strtoul10(it);
|
value = gmio_stringstream_strtoul10(it);
|
||||||
if (inv)
|
if (inv)
|
||||||
value = -value;
|
value = -value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gmio_strtof10_result
|
typedef struct
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
unsigned char_diff;
|
unsigned char_diff;
|
||||||
};
|
} gmio_stringstream_strtof10_result_t;
|
||||||
typedef struct gmio_strtof10_result gmio_strtof10_result_t;
|
|
||||||
|
|
||||||
GMIO_INLINE gmio_strtof10_result_t gmio_strtof10(
|
GMIO_INLINE gmio_stringstream_strtof10_result_t gmio_stringstream_strtof10(
|
||||||
gmio_string_stream_fwd_iterator_t* it)
|
gmio_stringstream_t* it)
|
||||||
{
|
{
|
||||||
const char* in = gmio_current_char(it);
|
const char* in = gmio_stringstream_current_char(it);
|
||||||
const uint32_t MAX_SAFE_U32_VALUE = UINT_MAX / 10 - 10;
|
const uint32_t MAX_SAFE_U32_VALUE = UINT_MAX / 10 - 10;
|
||||||
uint32_t int_val = 0;
|
uint32_t int_val = 0;
|
||||||
float float_val = 0.f;
|
float float_val = 0.f;
|
||||||
unsigned char_diff = 0;
|
unsigned char_diff = 0;
|
||||||
gmio_strtof10_result_t result;
|
gmio_stringstream_strtof10_result_t result;
|
||||||
|
|
||||||
/* Use integer arithmetic for as long as possible, for speed and
|
/* Use integer arithmetic for as long as possible, for speed and
|
||||||
* precision */
|
* precision */
|
||||||
for (;
|
for (;
|
||||||
in != NULL && gmio_ascii_isdigit(*in) && int_val < MAX_SAFE_U32_VALUE;
|
in != NULL && gmio_ascii_isdigit(*in) && int_val < MAX_SAFE_U32_VALUE;
|
||||||
in = gmio_next_char(it))
|
in = gmio_stringstream_next_char(it))
|
||||||
{
|
{
|
||||||
int_val = (int_val * 10) + (*in - '0');
|
int_val = (int_val * 10) + (*in - '0');
|
||||||
++char_diff;
|
++char_diff;
|
||||||
@ -66,7 +69,7 @@ GMIO_INLINE gmio_strtof10_result_t gmio_strtof10(
|
|||||||
* arithmetic from here */
|
* arithmetic from here */
|
||||||
for (;
|
for (;
|
||||||
in != NULL && gmio_ascii_isdigit(*in) && float_val <= FLT_MAX;
|
in != NULL && gmio_ascii_isdigit(*in) && float_val <= FLT_MAX;
|
||||||
in = gmio_next_char(it))
|
in = gmio_stringstream_next_char(it))
|
||||||
{
|
{
|
||||||
float_val = (float_val * 10) + (*in - '0');
|
float_val = (float_val * 10) + (*in - '0');
|
||||||
++char_diff;
|
++char_diff;
|
||||||
@ -76,37 +79,38 @@ GMIO_INLINE gmio_strtof10_result_t gmio_strtof10(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE float gmio_fast_atof(gmio_string_stream_fwd_iterator_t* it)
|
GMIO_INLINE float gmio_stringstream_fast_atof(gmio_stringstream_t* it)
|
||||||
{
|
{
|
||||||
const char* in = gmio_current_char(it);
|
const char* in = gmio_stringstream_current_char(it);
|
||||||
const gmio_bool_t negative = ('-' == *in);
|
const gmio_bool_t negative = ('-' == *in);
|
||||||
float value = 0.f;
|
float value = 0.f;
|
||||||
|
|
||||||
/* Please run the regression test when making any modifications to this
|
/* Please run the regression test when making any modifications to this
|
||||||
* function. */
|
* function. */
|
||||||
if (negative || ('+' == *in))
|
if (negative || ('+' == *in))
|
||||||
in = gmio_next_char(it);
|
in = gmio_stringstream_next_char(it);
|
||||||
value = gmio_strtof10(it).val;
|
value = gmio_stringstream_strtof10(it).val;
|
||||||
in = gmio_current_char(it);
|
in = gmio_stringstream_current_char(it);
|
||||||
if (is_local_decimal_point(*in)) {
|
if (is_local_decimal_point(*in)) {
|
||||||
const gmio_strtof10_result_t decimal =
|
const gmio_stringstream_strtof10_result_t decimal =
|
||||||
gmio_strtof10(gmio_move_next_char(it));
|
gmio_stringstream_strtof10(
|
||||||
|
gmio_stringstream_move_next_char(it));
|
||||||
value += decimal.val * fast_atof_table[decimal.char_diff];
|
value += decimal.val * fast_atof_table[decimal.char_diff];
|
||||||
in = gmio_current_char(it);
|
in = gmio_stringstream_current_char(it);
|
||||||
}
|
}
|
||||||
if (in != NULL && ('e' == *in || 'E' == *in)) {
|
if (in != NULL && ('e' == *in || 'E' == *in)) {
|
||||||
in = gmio_next_char(it);
|
in = gmio_stringstream_next_char(it);
|
||||||
/* Assume that the exponent is a whole number.
|
/* Assume that the exponent is a whole number.
|
||||||
* strtol10() will deal with both + and - signs,
|
* strtol10() will deal with both + and - signs,
|
||||||
* but calculate as float to prevent overflow at FLT_MAX */
|
* but calculate as float to prevent overflow at FLT_MAX */
|
||||||
value *=
|
value *=
|
||||||
#ifdef GMIO_HAVE_POWF_FUNC
|
#ifdef GMIO_HAVE_POWF_FUNC
|
||||||
powf(10.f, (float)gmio_strtol10(it));
|
powf(10.f, (float)gmio_stringstream_strtol10(it));
|
||||||
#else
|
#else
|
||||||
(float)pow(10., (double)gmio_strtol10(it));
|
(float)pow(10., (double)gmio_stringstream_strtol10(it));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return negative ? -value : value;
|
return negative ? -value : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GMIO_INTERNAL_STRING_PARSE_FAST_ATOF_H */
|
#endif /* GMIO_INTERNAL_STRINGSTREAM_FAST_ATOF_H */
|
@ -24,7 +24,7 @@
|
|||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
#include "../gmio_core/internal/helper_transfer.h"
|
#include "../gmio_core/internal/helper_transfer.h"
|
||||||
#include "../gmio_core/internal/min_max.h"
|
#include "../gmio_core/internal/min_max.h"
|
||||||
#include "../gmio_core/internal/string_parse.h"
|
#include "../gmio_core/internal/stringstream.h"
|
||||||
#include "../gmio_core/internal/string_utils.h"
|
#include "../gmio_core/internal/string_utils.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -98,7 +98,7 @@ typedef enum
|
|||||||
unknown_token
|
unknown_token
|
||||||
} gmio_stla_token_t;
|
} gmio_stla_token_t;
|
||||||
|
|
||||||
/* gmio_stream_fwd_iterator_stla_cookie */
|
/* gmio_stringstream_stla_cookie_t */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/* Copy of gmio_stla_read() corresponding argument */
|
/* Copy of gmio_stla_read() corresponding argument */
|
||||||
@ -109,15 +109,15 @@ typedef struct
|
|||||||
gmio_streamoffset_t stream_offset;
|
gmio_streamoffset_t stream_offset;
|
||||||
/* Cache for gmio_transfer::func_is_stop_requested() */
|
/* Cache for gmio_transfer::func_is_stop_requested() */
|
||||||
gmio_bool_t is_stop_requested;
|
gmio_bool_t is_stop_requested;
|
||||||
} gmio_string_stream_fwd_iterator_cookie_t;
|
} gmio_stringstream_stla_cookie_t;
|
||||||
|
|
||||||
/* gmio_stla_parse_data */
|
/* gmio_stla_parse_data */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
gmio_stla_token_t token;
|
gmio_stla_token_t token;
|
||||||
gmio_bool_t error;
|
gmio_bool_t error;
|
||||||
gmio_string_stream_fwd_iterator_t stream_iterator;
|
gmio_stringstream_t stream_iterator;
|
||||||
gmio_string_stream_fwd_iterator_cookie_t stream_iterator_cookie;
|
gmio_stringstream_stla_cookie_t stream_iterator_cookie;
|
||||||
gmio_string_t string_buffer;
|
gmio_string_t string_buffer;
|
||||||
gmio_stl_mesh_creator_t* creator;
|
gmio_stl_mesh_creator_t* creator;
|
||||||
} gmio_stla_parse_data_t;
|
} gmio_stla_parse_data_t;
|
||||||
@ -126,11 +126,11 @@ typedef struct
|
|||||||
enum { GMIO_STLA_READ_STRING_MAX_LEN = 1024 };
|
enum { GMIO_STLA_READ_STRING_MAX_LEN = 1024 };
|
||||||
|
|
||||||
/* Callback used for gmio_string_stream_fwd_iterator::func_stream_read_hook */
|
/* Callback used for gmio_string_stream_fwd_iterator::func_stream_read_hook */
|
||||||
static void gmio_stream_fwd_iterator_stla_read_hook(
|
static void gmio_stringstream_stla_read_hook(
|
||||||
void* cookie, const gmio_string_t* strbuff)
|
void* cookie, const gmio_string_t* strbuff)
|
||||||
{
|
{
|
||||||
gmio_string_stream_fwd_iterator_cookie_t* tcookie =
|
gmio_stringstream_stla_cookie_t* tcookie =
|
||||||
(gmio_string_stream_fwd_iterator_cookie_t*)(cookie);
|
(gmio_stringstream_stla_cookie_t*)(cookie);
|
||||||
const gmio_transfer_t* trsf = tcookie != NULL ? tcookie->transfer : NULL;
|
const gmio_transfer_t* trsf = tcookie != NULL ? tcookie->transfer : NULL;
|
||||||
if (tcookie != NULL) {
|
if (tcookie != NULL) {
|
||||||
tcookie->stream_offset += strbuff->len;
|
tcookie->stream_offset += strbuff->len;
|
||||||
@ -168,8 +168,8 @@ int gmio_stla_read(gmio_transfer_t* trsf, gmio_stl_mesh_creator_t* creator)
|
|||||||
parse_data.stream_iterator.strbuff.max_len = trsf->memblock.size;
|
parse_data.stream_iterator.strbuff.max_len = trsf->memblock.size;
|
||||||
parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie;
|
parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie;
|
||||||
parse_data.stream_iterator.func_stream_read_hook =
|
parse_data.stream_iterator.func_stream_read_hook =
|
||||||
gmio_stream_fwd_iterator_stla_read_hook;
|
gmio_stringstream_stla_read_hook;
|
||||||
gmio_string_stream_fwd_iterator_init(&parse_data.stream_iterator);
|
gmio_stringstream_init(&parse_data.stream_iterator);
|
||||||
|
|
||||||
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;
|
||||||
@ -462,14 +462,14 @@ int stla_eat_next_token(
|
|||||||
gmio_stla_parse_data_t* data,
|
gmio_stla_parse_data_t* data,
|
||||||
gmio_stla_token_t expected_token)
|
gmio_stla_token_t expected_token)
|
||||||
{
|
{
|
||||||
gmio_string_t* data_strbuff = &data->string_buffer;
|
gmio_string_t* strbuff = &data->string_buffer;
|
||||||
gmio_eat_word_error_t eat_error;
|
gmio_eat_word_error_t eat_error;
|
||||||
|
|
||||||
data_strbuff->len = 0;
|
strbuff->len = 0;
|
||||||
eat_error = gmio_eat_word(&data->stream_iterator, data_strbuff);
|
eat_error = gmio_stringstream_eat_word(&data->stream_iterator, strbuff);
|
||||||
if (eat_error == GMIO_EAT_WORD_ERROR_OK) {
|
if (eat_error == GMIO_EAT_WORD_ERROR_OK) {
|
||||||
const char* expected_token_str = stla_token_to_string(expected_token);
|
const char* expected_token_str = stla_token_to_string(expected_token);
|
||||||
if (gmio_ascii_stricmp(data_strbuff->ptr, expected_token_str) == 0) {
|
if (gmio_ascii_stricmp(strbuff->ptr, expected_token_str) == 0) {
|
||||||
data->token = expected_token;
|
data->token = expected_token;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -489,13 +489,13 @@ int stla_eat_next_token_inplace(
|
|||||||
gmio_stla_parse_data_t* data,
|
gmio_stla_parse_data_t* data,
|
||||||
gmio_stla_token_t expected_token)
|
gmio_stla_token_t expected_token)
|
||||||
{
|
{
|
||||||
gmio_string_stream_fwd_iterator_t* it = &data->stream_iterator;
|
gmio_stringstream_t* it = &data->stream_iterator;
|
||||||
const char* stream_char = NULL;
|
const char* stream_char = NULL;
|
||||||
const char* expected_token_str = stla_token_to_string(expected_token);
|
const char* expected_token_str = stla_token_to_string(expected_token);
|
||||||
gmio_bool_t error = GMIO_FALSE;
|
gmio_bool_t error = GMIO_FALSE;
|
||||||
|
|
||||||
data->token = unknown_token;
|
data->token = unknown_token;
|
||||||
stream_char = gmio_skip_spaces(it);
|
stream_char = gmio_stringstream_skip_ascii_spaces(it);
|
||||||
while (!error) {
|
while (!error) {
|
||||||
if (stream_char == NULL || gmio_ascii_isspace(*stream_char)) {
|
if (stream_char == NULL || gmio_ascii_isspace(*stream_char)) {
|
||||||
if (*expected_token_str == 0) {
|
if (*expected_token_str == 0) {
|
||||||
@ -509,7 +509,7 @@ int stla_eat_next_token_inplace(
|
|||||||
{
|
{
|
||||||
error = GMIO_TRUE;
|
error = GMIO_TRUE;
|
||||||
}
|
}
|
||||||
stream_char = gmio_next_char(it);
|
stream_char = gmio_stringstream_next_char(it);
|
||||||
++expected_token_str;
|
++expected_token_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,22 +524,21 @@ int stla_eat_until_token(
|
|||||||
gmio_stla_parse_data_t* data, const gmio_stla_token_t* end_tokens)
|
gmio_stla_parse_data_t* data, const gmio_stla_token_t* end_tokens)
|
||||||
{
|
{
|
||||||
if (!stla_token_match_candidate(data->token, end_tokens)) {
|
if (!stla_token_match_candidate(data->token, end_tokens)) {
|
||||||
gmio_string_stream_fwd_iterator_t* stream_it = &data->stream_iterator;
|
gmio_stringstream_t* stream_it = &data->stream_iterator;
|
||||||
gmio_string_t* string_buf = &data->string_buffer;
|
gmio_string_t* strbuff = &data->string_buffer;
|
||||||
gmio_bool_t end_token_found = GMIO_FALSE;
|
gmio_bool_t end_token_found = GMIO_FALSE;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const size_t previous_buff_len = string_buf->len;
|
const size_t previous_buff_len = strbuff->len;
|
||||||
gmio_eat_word_error_t eat_word_err = 0;
|
gmio_eat_word_error_t eat_word_err = 0;
|
||||||
const char* next_word = NULL; /* Pointer on next word string */
|
const char* next_word = NULL; /* Pointer on next word string */
|
||||||
size_t next_word_len = 0; /* Length of next word string */
|
size_t next_word_len = 0; /* Length of next word string */
|
||||||
|
|
||||||
gmio_copy_spaces(stream_it, string_buf);
|
gmio_stringstream_copy_ascii_spaces(stream_it, strbuff);
|
||||||
/* Next word */
|
/* Next word */
|
||||||
next_word = string_buf->ptr + string_buf->len;
|
next_word = strbuff->ptr + strbuff->len;
|
||||||
eat_word_err = gmio_eat_word(stream_it, string_buf);
|
eat_word_err = gmio_stringstream_eat_word(stream_it, strbuff);
|
||||||
next_word_len =
|
next_word_len = (strbuff->ptr + strbuff->len) - next_word;
|
||||||
(string_buf->ptr + string_buf->len) - next_word;
|
|
||||||
/* Qualify token */
|
/* Qualify token */
|
||||||
data->token =
|
data->token =
|
||||||
eat_word_err == GMIO_EAT_WORD_ERROR_OK ?
|
eat_word_err == GMIO_EAT_WORD_ERROR_OK ?
|
||||||
@ -550,10 +549,10 @@ int stla_eat_until_token(
|
|||||||
/* True ?
|
/* True ?
|
||||||
* trim string_buf so it contains only contents before end token */
|
* trim string_buf so it contains only contents before end token */
|
||||||
if (end_token_found) {
|
if (end_token_found) {
|
||||||
string_buf->len = previous_buff_len;
|
strbuff->len = previous_buff_len;
|
||||||
string_buf->ptr[previous_buff_len] = 0;
|
strbuff->ptr[previous_buff_len] = 0;
|
||||||
}
|
}
|
||||||
} while (!end_token_found && string_buf->len < string_buf->max_len);
|
} while (!end_token_found && strbuff->len < strbuff->max_len);
|
||||||
|
|
||||||
if (!end_token_found) {
|
if (!end_token_found) {
|
||||||
stla_error_msg(
|
stla_error_msg(
|
||||||
@ -639,20 +638,20 @@ GMIO_INLINE int is_float_char(const char* str)
|
|||||||
int parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
|
int parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
|
||||||
{
|
{
|
||||||
int errc = 0;
|
int errc = 0;
|
||||||
gmio_string_stream_fwd_iterator_t* it = &data->stream_iterator;
|
gmio_stringstream_t* it = &data->stream_iterator;
|
||||||
const char* strbuff = NULL;
|
const char* strbuff = NULL;
|
||||||
|
|
||||||
strbuff = gmio_skip_spaces(it);
|
strbuff = gmio_stringstream_skip_ascii_spaces(it);
|
||||||
errc += !is_float_char(strbuff);
|
errc += !is_float_char(strbuff);
|
||||||
coords->x = gmio_parse_float32(it);
|
coords->x = gmio_stringstream_parse_float32(it);
|
||||||
|
|
||||||
strbuff = gmio_skip_spaces(it);
|
strbuff = gmio_stringstream_skip_ascii_spaces(it);
|
||||||
errc += !is_float_char(strbuff);
|
errc += !is_float_char(strbuff);
|
||||||
coords->y = gmio_parse_float32(it);
|
coords->y = gmio_stringstream_parse_float32(it);
|
||||||
|
|
||||||
strbuff = gmio_skip_spaces(it);
|
strbuff = gmio_stringstream_skip_ascii_spaces(it);
|
||||||
errc += !is_float_char(strbuff);
|
errc += !is_float_char(strbuff);
|
||||||
coords->z = gmio_parse_float32(it);
|
coords->z = gmio_stringstream_parse_float32(it);
|
||||||
|
|
||||||
data->string_buffer.len = 0;
|
data->string_buffer.len = 0;
|
||||||
data->token = unknown_token;
|
data->token = unknown_token;
|
||||||
@ -702,7 +701,7 @@ void parse_facets(gmio_stla_parse_data_t* data)
|
|||||||
func_add_triangle(creator_cookie, i_facet, &facet);
|
func_add_triangle(creator_cookie, i_facet, &facet);
|
||||||
/* Eat next unknown token */
|
/* Eat next unknown token */
|
||||||
strbuff->len = 0;
|
strbuff->len = 0;
|
||||||
gmio_eat_word(&data->stream_iterator, strbuff);
|
gmio_stringstream_eat_word(&data->stream_iterator, strbuff);
|
||||||
data->token = stla_find_token_from_string(strbuff);
|
data->token = stla_find_token_from_string(strbuff);
|
||||||
++i_facet;
|
++i_facet;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ const char* test_internal__byte_codec();
|
|||||||
const char* test_internal__fast_atof();
|
const char* test_internal__fast_atof();
|
||||||
const char* test_internal__gmio_fast_atof();
|
const char* test_internal__gmio_fast_atof();
|
||||||
const char* test_internal__safe_cast();
|
const char* test_internal__safe_cast();
|
||||||
const char* test_internal__string_parse();
|
const char* test_internal__stringstream();
|
||||||
const char* test_internal__string_utils();
|
const char* test_internal__string_utils();
|
||||||
|
|
||||||
const char* test_platform__alignment();
|
const char* test_platform__alignment();
|
||||||
@ -46,7 +46,7 @@ const char* all_tests()
|
|||||||
UTEST_RUN(test_internal__fast_atof);
|
UTEST_RUN(test_internal__fast_atof);
|
||||||
UTEST_RUN(test_internal__gmio_fast_atof);
|
UTEST_RUN(test_internal__gmio_fast_atof);
|
||||||
UTEST_RUN(test_internal__safe_cast);
|
UTEST_RUN(test_internal__safe_cast);
|
||||||
UTEST_RUN(test_internal__string_parse);
|
UTEST_RUN(test_internal__stringstream);
|
||||||
UTEST_RUN(test_internal__string_utils);
|
UTEST_RUN(test_internal__string_utils);
|
||||||
|
|
||||||
UTEST_RUN(test_platform__alignment);
|
UTEST_RUN(test_platform__alignment);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "../src/gmio_core/internal/convert.h"
|
#include "../src/gmio_core/internal/convert.h"
|
||||||
#include "../src/gmio_core/internal/fast_atof.h"
|
#include "../src/gmio_core/internal/fast_atof.h"
|
||||||
#include "../src/gmio_core/internal/safe_cast.h"
|
#include "../src/gmio_core/internal/safe_cast.h"
|
||||||
#include "../src/gmio_core/internal/string_parse.h"
|
#include "../src/gmio_core/internal/stringstream.h"
|
||||||
#include "../src/gmio_core/internal/string_utils.h"
|
#include "../src/gmio_core/internal/string_utils.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -131,7 +131,7 @@ const char* test_internal__gmio_fast_atof()
|
|||||||
|
|
||||||
{
|
{
|
||||||
char strbuff[2048] = {0};
|
char strbuff[2048] = {0};
|
||||||
gmio_string_stream_fwd_iterator_t it = {0};
|
gmio_stringstream_t it = {0};
|
||||||
gmio_stream_buffer_t streambuff = {0};
|
gmio_stream_buffer_t streambuff = {0};
|
||||||
gmio_stream_t stream = {0};
|
gmio_stream_t stream = {0};
|
||||||
float f2;
|
float f2;
|
||||||
@ -143,9 +143,9 @@ const char* test_internal__gmio_fast_atof()
|
|||||||
it.stream = &stream;
|
it.stream = &stream;
|
||||||
it.strbuff.ptr = &strbuff[0];
|
it.strbuff.ptr = &strbuff[0];
|
||||||
it.strbuff.max_len = sizeof(strbuff) - 1;
|
it.strbuff.max_len = sizeof(strbuff) - 1;
|
||||||
gmio_string_stream_fwd_iterator_init(&it);
|
gmio_stringstream_init(&it);
|
||||||
|
|
||||||
f2 = gmio_fast_atof(&it);
|
f2 = gmio_stringstream_fast_atof(&it);
|
||||||
|
|
||||||
UTEST_ASSERT(gmio_float32_equals_by_ulp(f1, f2, 1));
|
UTEST_ASSERT(gmio_float32_equals_by_ulp(f1, f2, 1));
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ const char* test_internal__safe_cast()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* test_internal__string_parse()
|
const char* test_internal__stringstream()
|
||||||
{
|
{
|
||||||
const char text[] =
|
const char text[] =
|
||||||
"Une citation,\to je crois qu'elle est de moi :"
|
"Une citation,\to je crois qu'elle est de moi :"
|
||||||
@ -189,7 +189,7 @@ const char* test_internal__string_parse()
|
|||||||
|
|
||||||
char small_fwd_it_str[4];
|
char small_fwd_it_str[4];
|
||||||
char fwd_it_str[32];
|
char fwd_it_str[32];
|
||||||
gmio_string_stream_fwd_iterator_t fwd_it = {0};
|
gmio_stringstream_t fwd_it = {0};
|
||||||
|
|
||||||
char copy_str[128];
|
char copy_str[128];
|
||||||
gmio_string_t copy_strbuff;
|
gmio_string_t copy_strbuff;
|
||||||
@ -202,46 +202,46 @@ const char* test_internal__string_parse()
|
|||||||
fwd_it.stream = &stream;
|
fwd_it.stream = &stream;
|
||||||
fwd_it.strbuff.ptr = fwd_it_str;
|
fwd_it.strbuff.ptr = fwd_it_str;
|
||||||
fwd_it.strbuff.max_len = sizeof(fwd_it_str);
|
fwd_it.strbuff.max_len = sizeof(fwd_it_str);
|
||||||
gmio_string_stream_fwd_iterator_init(&fwd_it);
|
gmio_stringstream_init(&fwd_it);
|
||||||
|
|
||||||
copy_strbuff.ptr = copy_str;
|
copy_strbuff.ptr = copy_str;
|
||||||
copy_strbuff.max_len = sizeof(copy_str);
|
copy_strbuff.max_len = sizeof(copy_str);
|
||||||
|
|
||||||
UTEST_ASSERT(gmio_current_char(&fwd_it) != NULL);
|
UTEST_ASSERT(gmio_stringstream_current_char(&fwd_it) != NULL);
|
||||||
UTEST_ASSERT(*gmio_current_char(&fwd_it) == 'U');
|
UTEST_ASSERT(*gmio_stringstream_current_char(&fwd_it) == 'U');
|
||||||
|
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_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(copy_strbuff.ptr, "Une") == 0);
|
||||||
|
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0);
|
||||||
|
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "o") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "o") == 0);
|
||||||
|
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "je") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "je") == 0);
|
||||||
|
|
||||||
gmio_skip_spaces(&fwd_it);
|
gmio_stringstream_skip_ascii_spaces(&fwd_it);
|
||||||
UTEST_ASSERT(gmio_next_char(&fwd_it) != NULL);
|
UTEST_ASSERT(gmio_stringstream_next_char(&fwd_it) != NULL);
|
||||||
UTEST_ASSERT(*gmio_current_char(&fwd_it) == 'r');
|
UTEST_ASSERT(*gmio_stringstream_current_char(&fwd_it) == '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;
|
fwd_it.strbuff.ptr = small_fwd_it_str;
|
||||||
fwd_it.strbuff.max_len = sizeof(small_fwd_it_str);
|
fwd_it.strbuff.max_len = sizeof(small_fwd_it_str);
|
||||||
gmio_string_stream_fwd_iterator_init(&fwd_it);
|
gmio_stringstream_init(&fwd_it);
|
||||||
|
|
||||||
UTEST_ASSERT(*gmio_current_char(&fwd_it) == 'U');
|
UTEST_ASSERT(*gmio_stringstream_current_char(&fwd_it) == 'U');
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "citation,") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ const char* test_internal__string_parse()
|
|||||||
gmio_stream_t stream = {0};
|
gmio_stream_t stream = {0};
|
||||||
|
|
||||||
char fwd_it_str[32];
|
char fwd_it_str[32];
|
||||||
gmio_string_stream_fwd_iterator_t fwd_it = {0};
|
gmio_stringstream_t fwd_it = {0};
|
||||||
|
|
||||||
char copy_str[128];
|
char copy_str[128];
|
||||||
gmio_string_t copy_strbuff;
|
gmio_string_t copy_strbuff;
|
||||||
@ -263,18 +263,18 @@ const char* test_internal__string_parse()
|
|||||||
fwd_it.stream = &stream;
|
fwd_it.stream = &stream;
|
||||||
fwd_it.strbuff.ptr = fwd_it_str;
|
fwd_it.strbuff.ptr = fwd_it_str;
|
||||||
fwd_it.strbuff.max_len = sizeof(fwd_it_str);
|
fwd_it.strbuff.max_len = sizeof(fwd_it_str);
|
||||||
gmio_string_stream_fwd_iterator_init(&fwd_it);
|
gmio_stringstream_init(&fwd_it);
|
||||||
|
|
||||||
copy_strbuff.ptr = copy_str;
|
copy_strbuff.ptr = copy_str;
|
||||||
copy_strbuff.len = 0;
|
copy_strbuff.len = 0;
|
||||||
copy_strbuff.max_len = sizeof(copy_str);
|
copy_strbuff.max_len = sizeof(copy_str);
|
||||||
|
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Une") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Une") == 0);
|
||||||
|
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Unecitation,") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Unecitation,") == 0);
|
||||||
UTEST_ASSERT(gmio_eat_word(&fwd_it, ©_strbuff) == 0);
|
UTEST_ASSERT(gmio_stringstream_eat_word(&fwd_it, ©_strbuff) == 0);
|
||||||
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Unecitation,o") == 0);
|
UTEST_ASSERT(strcmp(copy_strbuff.ptr, "Unecitation,o") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user