gmio_core: add string_utils.h
This commit is contained in:
parent
047f24c6dc
commit
f58b6e56b4
@ -16,6 +16,7 @@
|
|||||||
#include "string_parse.h"
|
#include "string_parse.h"
|
||||||
|
|
||||||
#include "helper_stream.h"
|
#include "helper_stream.h"
|
||||||
|
#include "string_utils.h"
|
||||||
/*#define GMIO_USE_FAST_ATOF*/
|
/*#define GMIO_USE_FAST_ATOF*/
|
||||||
#ifdef GMIO_USE_FAST_ATOF
|
#ifdef GMIO_USE_FAST_ATOF
|
||||||
# include "fast_atof.h"
|
# include "fast_atof.h"
|
||||||
@ -72,17 +73,6 @@ const char *gmio_next_char(gmio_string_stream_fwd_iterator_t *it)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE int gmio_clocale_isspace(char c)
|
|
||||||
{
|
|
||||||
return c == 0x20 /* space (SPC) */
|
|
||||||
|| c == 0x09 /* horizontal tab (TAB) */
|
|
||||||
|| c == 0x0a /* newline (LF) */
|
|
||||||
|| c == 0x0b /* vertical tab (VT) */
|
|
||||||
|| c == 0x0c /* feed (FF) */
|
|
||||||
|| c == 0x0d /* carriage return (CR) */
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t *it)
|
void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t *it)
|
||||||
{
|
{
|
||||||
const char* curr_char = gmio_current_char(it);
|
const char* curr_char = gmio_current_char(it);
|
||||||
|
75
src/gmio_core/internal/string_utils.h
Normal file
75
src/gmio_core/internal/string_utils.h
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** 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/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GMIO_INTERNAL_STRING_UTILS_H
|
||||||
|
#define GMIO_INTERNAL_STRING_UTILS_H
|
||||||
|
|
||||||
|
#include "../global.h"
|
||||||
|
|
||||||
|
/*! Returns non-zero if \p c is a space (for C-locale), zero otherwise */
|
||||||
|
GMIO_INLINE int gmio_clocale_isspace(char c)
|
||||||
|
{
|
||||||
|
return c == 0x20 /* space (SPC) */
|
||||||
|
|| c == 0x09 /* horizontal tab (TAB) */
|
||||||
|
|| c == 0x0a /* newline (LF) */
|
||||||
|
|| c == 0x0b /* vertical tab (VT) */
|
||||||
|
|| c == 0x0c /* feed (FF) */
|
||||||
|
|| c == 0x0d /* carriage return (CR) */
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Returns true if \p c1 compare equals to \p c2
|
||||||
|
*
|
||||||
|
* Comparison is case-insensitive
|
||||||
|
*/
|
||||||
|
GMIO_INLINE gmio_bool_t gmio_clocale_char_iequals(char c1, char c2)
|
||||||
|
{
|
||||||
|
return c1 == c2 || c1 == (c2 - 32) ? GMIO_TRUE : GMIO_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Returns 0 if \p str1 and \p str2 compare equal, non-zero otherwise
|
||||||
|
*
|
||||||
|
* Comparison is case-insensitive
|
||||||
|
*/
|
||||||
|
GMIO_INLINE int gmio_stricmp(const char* str1, const char* str2)
|
||||||
|
{
|
||||||
|
while (*str1 != 0 && *str2 != 0) {
|
||||||
|
if (gmio_clocale_char_iequals(*str1, *str2) == GMIO_FALSE)
|
||||||
|
return 1;
|
||||||
|
++str1;
|
||||||
|
++str2;
|
||||||
|
}
|
||||||
|
return *str1 == 0 && *str2 == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Returns true if \p str starts with string \p begin
|
||||||
|
*
|
||||||
|
* Comparison is case-insensitive
|
||||||
|
*/
|
||||||
|
GMIO_INLINE gmio_bool_t gmio_istarts_with(const char* str, const char* begin)
|
||||||
|
{
|
||||||
|
while (*begin != 0) {
|
||||||
|
if (*str == 0
|
||||||
|
|| gmio_clocale_char_iequals(*str, *begin) == GMIO_FALSE)
|
||||||
|
{
|
||||||
|
return GMIO_FALSE;
|
||||||
|
}
|
||||||
|
++str;
|
||||||
|
++begin;
|
||||||
|
}
|
||||||
|
return GMIO_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_STRING_UTILS_H */
|
@ -25,6 +25,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/string_parse.h"
|
#include "../gmio_core/internal/string_parse.h"
|
||||||
|
#include "../gmio_core/internal/string_utils.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -207,40 +208,6 @@ GMIO_INLINE void parsing_error_token_expected(
|
|||||||
parsing_error_msg(data, msg);
|
parsing_error_msg(data, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE gmio_bool_t gmio_clocale_char_iequals(char c1, char c2)
|
|
||||||
{
|
|
||||||
return c1 == c2 || c1 == (c2 - 32) ? GMIO_TRUE : GMIO_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Returns 0 if \p str1 and \p str2 compare equal, non-zero otherwise
|
|
||||||
*
|
|
||||||
* It assumes that <tt>len(str1) >= len(str2)</tt>
|
|
||||||
*/
|
|
||||||
GMIO_INLINE int gmio_stricmp(const char* str1, const char* str2)
|
|
||||||
{
|
|
||||||
while (*str1 != 0 && *str2 != 0) {
|
|
||||||
if (gmio_clocale_char_iequals(*str1, *str2) == GMIO_FALSE)
|
|
||||||
return 1;
|
|
||||||
++str1;
|
|
||||||
++str2;
|
|
||||||
}
|
|
||||||
return *str1 == 0 && *str2 == 0 ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
GMIO_INLINE gmio_bool_t gmio_istarts_with(const char* str, const char* begin)
|
|
||||||
{
|
|
||||||
while (*begin != 0) {
|
|
||||||
if (*str == 0
|
|
||||||
|| gmio_clocale_char_iequals(*str, *begin) == GMIO_FALSE)
|
|
||||||
{
|
|
||||||
return GMIO_FALSE;
|
|
||||||
}
|
|
||||||
++str;
|
|
||||||
++begin;
|
|
||||||
}
|
|
||||||
return GMIO_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gmio_stla_token_t parsing_find_token(
|
static gmio_stla_token_t parsing_find_token(
|
||||||
const gmio_string_buffer_t* str_buffer)
|
const gmio_string_buffer_t* str_buffer)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user