2015-03-03 00:38:33 +08:00
|
|
|
/****************************************************************************
|
2015-05-28 15:40:24 +08:00
|
|
|
** gmio
|
2015-05-01 00:19:45 +08:00
|
|
|
** Copyright Fougue (2 Mar. 2015)
|
2015-07-13 17:42:03 +08:00
|
|
|
** contact@fougue.pro
|
2015-03-03 00:38:33 +08:00
|
|
|
**
|
|
|
|
** 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
|
2015-03-30 15:05:25 +08:00
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
2015-03-03 00:38:33 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
#include "string_parse.h"
|
2014-01-27 22:28:12 +08:00
|
|
|
|
2015-03-13 18:04:14 +08:00
|
|
|
#include "helper_stream.h"
|
2014-01-27 22:28:12 +08:00
|
|
|
|
2015-03-03 00:54:57 +08:00
|
|
|
void gmio_string_stream_fwd_iterator_init(gmio_string_stream_fwd_iterator_t *it)
|
2014-01-28 05:57:10 +08:00
|
|
|
{
|
2015-03-03 23:44:14 +08:00
|
|
|
/* Trick: declaring the buffer exhausted will actually trigger the first
|
|
|
|
* call to gmio_stream_read() inside gmio_next_char()
|
|
|
|
*/
|
2015-10-30 19:38:57 +08:00
|
|
|
it->strbuff.len = 0;
|
|
|
|
it->strbuff_ptr_end = it->strbuff.ptr;
|
|
|
|
it->strbuff_ptr_at = it->strbuff_ptr_end;
|
2015-03-03 17:35:36 +08:00
|
|
|
gmio_next_char(it);
|
2014-01-28 05:57:10 +08:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:35:09 +08:00
|
|
|
gmio_eat_word_error_t gmio_eat_word(
|
2015-10-29 18:25:04 +08:00
|
|
|
gmio_string_stream_fwd_iterator_t *it, gmio_string_t *str)
|
2014-01-27 22:28:12 +08:00
|
|
|
{
|
2015-10-30 19:38:57 +08:00
|
|
|
char* str_ptr_at = str->ptr + str->len;
|
|
|
|
const char* str_ptr_end = str->ptr + str->max_len;
|
2015-03-03 17:35:36 +08:00
|
|
|
const char* stream_curr_char = NULL;
|
|
|
|
|
2015-10-29 18:25:04 +08:00
|
|
|
/* assert(str != NULL && str->ptr != NULL); */
|
2015-03-03 17:35:36 +08:00
|
|
|
|
2015-05-07 21:56:44 +08:00
|
|
|
stream_curr_char = gmio_skip_spaces(it);
|
2015-03-31 21:53:58 +08:00
|
|
|
if (stream_curr_char == NULL) { /* Empty word */
|
2015-10-30 19:38:57 +08:00
|
|
|
*str_ptr_at = 0;
|
2015-10-22 00:35:09 +08:00
|
|
|
return GMIO_EAT_WORD_ERROR_EMPTY;
|
2015-03-31 21:53:58 +08:00
|
|
|
}
|
2015-03-03 17:35:36 +08:00
|
|
|
|
2015-05-07 21:56:44 +08:00
|
|
|
do {
|
2015-10-30 19:38:57 +08:00
|
|
|
*str_ptr_at = *stream_curr_char;
|
2015-05-07 21:56:44 +08:00
|
|
|
stream_curr_char = gmio_next_char(it);
|
2015-10-30 19:38:57 +08:00
|
|
|
++str_ptr_at;
|
|
|
|
} while (stream_curr_char != NULL
|
|
|
|
&& !gmio_ascii_isspace(*stream_curr_char)
|
|
|
|
&& str_ptr_at < str_ptr_end);
|
2015-03-03 17:35:36 +08:00
|
|
|
|
2015-10-30 19:38:57 +08:00
|
|
|
if (str_ptr_at < str_ptr_end) {
|
|
|
|
*str_ptr_at = 0; /* End string with null byte */
|
|
|
|
str->len = str_ptr_at - str->ptr;
|
2015-10-22 00:35:09 +08:00
|
|
|
return GMIO_EAT_WORD_ERROR_OK;
|
2015-03-03 17:35:36 +08:00
|
|
|
}
|
2015-10-22 00:35:09 +08:00
|
|
|
return GMIO_EAT_WORD_ERROR_CAPACITY_OVERFLOW;
|
2014-01-27 22:28:12 +08:00
|
|
|
}
|
|
|
|
|
2015-09-14 17:27:27 +08:00
|
|
|
#if 0
|
2015-03-20 00:31:08 +08:00
|
|
|
gmio_bool_t gmio_checked_next_chars(
|
|
|
|
gmio_string_stream_fwd_iterator_t *it, const char *str)
|
2014-01-28 17:11:26 +08:00
|
|
|
{
|
2015-03-03 17:35:36 +08:00
|
|
|
size_t pos = 0;
|
|
|
|
const char* curr_char = gmio_current_char(it);
|
|
|
|
gmio_bool_t same = curr_char != NULL && *curr_char == *str;
|
2014-01-28 17:11:26 +08:00
|
|
|
|
2015-03-03 17:35:36 +08:00
|
|
|
while (same) {
|
|
|
|
curr_char = gmio_next_char(it);
|
|
|
|
same = curr_char != NULL && *curr_char == str[++pos];
|
|
|
|
}
|
2014-01-28 17:11:26 +08:00
|
|
|
|
2015-03-03 17:35:36 +08:00
|
|
|
return same;
|
2014-01-28 17:11:26 +08:00
|
|
|
}
|
2015-09-14 17:27:27 +08:00
|
|
|
#endif
|