2015-03-03 00:38:33 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** GeomIO Library
|
|
|
|
** Copyright FougSys (2 Mar. 2015)
|
|
|
|
** contact@fougsys.fr
|
|
|
|
**
|
|
|
|
** This software is a reusable library whose purpose is to provide complete
|
|
|
|
** I/O support for various CAD file formats (eg. STL)
|
|
|
|
**
|
|
|
|
** This software is governed by the CeCILL-B license under French law and
|
|
|
|
** abiding by the rules of distribution of free software. You can use,
|
|
|
|
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
|
|
|
** license as circulated by CEA, CNRS and INRIA at the following URL
|
|
|
|
** "http://www.cecill.info".
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
#ifndef GMIO_INTERNAL_STRING_PARSE_H
|
|
|
|
#define GMIO_INTERNAL_STRING_PARSE_H
|
2014-03-28 23:33:35 +08:00
|
|
|
|
|
|
|
#include "../global.h"
|
|
|
|
#include "../stream.h"
|
|
|
|
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Stores traditional 8-bit strings
|
|
|
|
*
|
|
|
|
* For faster length lookups, it knowns the length of its contents. It must
|
|
|
|
* never exceeds the maximum length of the buffer.
|
|
|
|
*/
|
2015-03-03 00:54:57 +08:00
|
|
|
struct gmio_string_buffer
|
2014-03-28 23:33:35 +08:00
|
|
|
{
|
2015-03-03 23:44:14 +08:00
|
|
|
char* ptr; /*!< Buffer contents */
|
|
|
|
size_t len; /*!< Size(length) of current contents */
|
|
|
|
size_t max_len; /*!< Maximum contents size(length) */
|
2014-03-31 21:39:21 +08:00
|
|
|
};
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
typedef struct gmio_string_buffer gmio_string_buffer_t;
|
2014-03-31 21:39:21 +08:00
|
|
|
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Forward iterator over a stream
|
|
|
|
*
|
|
|
|
* To be used with API below.
|
|
|
|
* It allows to iterate over a stream (until end is reached) as if it was a
|
|
|
|
* string.
|
|
|
|
*/
|
2015-03-03 00:54:57 +08:00
|
|
|
struct gmio_string_stream_fwd_iterator
|
2014-03-28 23:33:35 +08:00
|
|
|
{
|
2015-03-03 17:35:36 +08:00
|
|
|
gmio_stream_t* stream;
|
|
|
|
gmio_string_buffer_t buffer;
|
|
|
|
size_t buffer_pos; /*!< Position indicator in buffer */
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 17:35:36 +08:00
|
|
|
void* cookie;
|
|
|
|
void (*stream_read_hook)(void* cookie, const gmio_string_buffer_t* str_buffer);
|
2014-03-31 21:39:21 +08:00
|
|
|
};
|
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
typedef struct gmio_string_stream_fwd_iterator gmio_string_stream_fwd_iterator_t;
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
void gmio_string_stream_fwd_iterator_init(gmio_string_stream_fwd_iterator_t* it);
|
2015-03-03 23:44:14 +08:00
|
|
|
const char* gmio_current_char(const gmio_string_stream_fwd_iterator_t* it);
|
2015-03-03 00:54:57 +08:00
|
|
|
void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t* it);
|
|
|
|
int gmio_eat_word(gmio_string_stream_fwd_iterator_t* it, gmio_string_buffer_t* buffer);
|
2015-01-29 05:39:03 +08:00
|
|
|
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! Move on next char in stream */
|
2015-03-03 23:44:14 +08:00
|
|
|
const char* gmio_next_char(gmio_string_stream_fwd_iterator_t* it);
|
2015-03-05 01:25:51 +08:00
|
|
|
|
|
|
|
/*! Iterate over stream while it matches input string \p str
|
|
|
|
*
|
|
|
|
* Returns GMIO_TRUE if \p str was fully matched
|
|
|
|
*/
|
2015-03-03 23:44:14 +08:00
|
|
|
gmio_bool_t gmio_checked_next_chars(gmio_string_stream_fwd_iterator_t* it, const char* str);
|
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Converts the string pointed to by \p str to gmio_float32_t representation
|
2015-01-29 05:39:03 +08:00
|
|
|
*
|
|
|
|
* \retval 0 On success
|
|
|
|
* \retval -1 On error(check \c errno to see what happened)
|
|
|
|
*/
|
2015-03-05 01:25:51 +08:00
|
|
|
int gmio_get_float32(const char* str, gmio_float32_t* value_ptr);
|
2014-03-28 23:33:35 +08:00
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
#endif /* GMIO_INTERNAL_STRING_PARSE_H */
|