gmio_core/internal: separate declaration/definition in string_utils.h
This commit is contained in:
parent
0981f63658
commit
e4b7753fea
@ -18,14 +18,57 @@
|
||||
|
||||
#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);
|
||||
|
||||
/*! Returns non-zero if \p c is a digit (for C-locale), zero otherwise */
|
||||
GMIO_INLINE int gmio_clocale_isdigit(char c);
|
||||
|
||||
/*! Returns non-zero if \p c is an uppercase letter (for C-locale), zero
|
||||
* otherwise */
|
||||
GMIO_INLINE int gmio_clocale_isupper(char c);
|
||||
|
||||
/*! Returns non-zero if \p c is a lowercase letter (for C-locale), zero
|
||||
* otherwise */
|
||||
GMIO_INLINE int gmio_clocale_islower(char c);
|
||||
|
||||
/*! Returns the lowercase letter converted to uppercase */
|
||||
GMIO_INLINE char gmio_clocale_toupper(char c);
|
||||
|
||||
/*! Returns the uppercase letter converted to lowercase */
|
||||
GMIO_INLINE char gmio_clocale_tolower(char c);
|
||||
|
||||
/*! 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);
|
||||
|
||||
/*! 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);
|
||||
|
||||
/*! 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);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* -- Implementation
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef GMIO_STRINGUTILS_CTYPE_H
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
/*! Returns non-zero if \p c is a space (for C-locale), zero otherwise */
|
||||
GMIO_INLINE int gmio_clocale_isspace(char c)
|
||||
int gmio_clocale_isspace(char c)
|
||||
{
|
||||
/* 0x20 : space (SPC)
|
||||
* 0x09 : horizontal tab (TAB)
|
||||
@ -61,7 +104,7 @@ GMIO_INLINE int gmio_clocale_isspace(char c)
|
||||
#endif
|
||||
}
|
||||
|
||||
GMIO_INLINE int gmio_clocale_isdigit(char c)
|
||||
int gmio_clocale_isdigit(char c)
|
||||
{
|
||||
static const unsigned char digit_chars[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -84,9 +127,7 @@ GMIO_INLINE int gmio_clocale_isdigit(char c)
|
||||
return digit_chars[(unsigned char)c];
|
||||
}
|
||||
|
||||
/*! Returns non-zero if \p c is an uppercase letter (for C-locale), zero
|
||||
* otherwise */
|
||||
GMIO_INLINE int gmio_clocale_isupper(char c)
|
||||
int gmio_clocale_isupper(char c)
|
||||
{
|
||||
#if defined(GMIO_STRINGUTILS_DIRECT_TESTS)
|
||||
/* TODO: eliminate branch */
|
||||
@ -116,9 +157,7 @@ GMIO_INLINE int gmio_clocale_isupper(char c)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! Returns non-zero if \p c is a lowercase letter (for C-locale), zero
|
||||
* otherwise */
|
||||
GMIO_INLINE int gmio_clocale_islower(char c)
|
||||
int gmio_clocale_islower(char c)
|
||||
{
|
||||
#if defined(GMIO_STRINGUTILS_DIRECT_TESTS)
|
||||
/* TODO: eliminate branch */
|
||||
@ -148,8 +187,7 @@ GMIO_INLINE int gmio_clocale_islower(char c)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! Returns the lowercase letter converted to uppercase */
|
||||
GMIO_INLINE char gmio_clocale_toupper(char c)
|
||||
char gmio_clocale_toupper(char c)
|
||||
{
|
||||
static const char table_toupper[128] = {
|
||||
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,0x09,0x0A, 0 , 0 ,0x0D, 0 , 0 ,
|
||||
@ -164,8 +202,7 @@ GMIO_INLINE char gmio_clocale_toupper(char c)
|
||||
return table_toupper[(unsigned char)c];
|
||||
}
|
||||
|
||||
/*! Returns the uppercase letter converted to lowercase */
|
||||
GMIO_INLINE char gmio_clocale_tolower(char c)
|
||||
char gmio_clocale_tolower(char c)
|
||||
{
|
||||
static const char table_tolower[128] = {
|
||||
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,0x09,0x0A, 0 , 0 ,0x0D, 0 , 0 ,
|
||||
@ -180,21 +217,13 @@ GMIO_INLINE char gmio_clocale_tolower(char c)
|
||||
return table_tolower[(unsigned char)c];
|
||||
}
|
||||
|
||||
/*! 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)
|
||||
gmio_bool_t gmio_clocale_char_iequals(char c1, char c2)
|
||||
{
|
||||
/* TODO: eliminate branch */
|
||||
return c1 == c2 || (gmio_clocale_toupper(c1) == gmio_clocale_toupper(c2));
|
||||
}
|
||||
|
||||
/*! 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)
|
||||
int gmio_stricmp(const char* str1, const char* str2)
|
||||
{
|
||||
while (*str1 != 0 && *str2 != 0) {
|
||||
if (!gmio_clocale_char_iequals(*str1, *str2))
|
||||
@ -205,18 +234,11 @@ GMIO_INLINE int gmio_stricmp(const char* str1, const char* 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)
|
||||
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)
|
||||
{
|
||||
if (*str == 0 || !gmio_clocale_char_iequals(*str, *begin))
|
||||
return GMIO_FALSE;
|
||||
}
|
||||
++str;
|
||||
++begin;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user