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"
|
#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>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef GMIO_STRINGUTILS_CTYPE_H
|
#ifdef GMIO_STRINGUTILS_CTYPE_H
|
||||||
# include <ctype.h>
|
# include <ctype.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*! Returns non-zero if \p c is a space (for C-locale), zero otherwise */
|
int gmio_clocale_isspace(char c)
|
||||||
GMIO_INLINE int gmio_clocale_isspace(char c)
|
|
||||||
{
|
{
|
||||||
/* 0x20 : space (SPC)
|
/* 0x20 : space (SPC)
|
||||||
* 0x09 : horizontal tab (TAB)
|
* 0x09 : horizontal tab (TAB)
|
||||||
@ -61,7 +104,7 @@ GMIO_INLINE int gmio_clocale_isspace(char c)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE int gmio_clocale_isdigit(char c)
|
int gmio_clocale_isdigit(char c)
|
||||||
{
|
{
|
||||||
static const unsigned char digit_chars[] = {
|
static const unsigned char digit_chars[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
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];
|
return digit_chars[(unsigned char)c];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns non-zero if \p c is an uppercase letter (for C-locale), zero
|
int gmio_clocale_isupper(char c)
|
||||||
* otherwise */
|
|
||||||
GMIO_INLINE int gmio_clocale_isupper(char c)
|
|
||||||
{
|
{
|
||||||
#if defined(GMIO_STRINGUTILS_DIRECT_TESTS)
|
#if defined(GMIO_STRINGUTILS_DIRECT_TESTS)
|
||||||
/* TODO: eliminate branch */
|
/* TODO: eliminate branch */
|
||||||
@ -116,9 +157,7 @@ GMIO_INLINE int gmio_clocale_isupper(char c)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns non-zero if \p c is a lowercase letter (for C-locale), zero
|
int gmio_clocale_islower(char c)
|
||||||
* otherwise */
|
|
||||||
GMIO_INLINE int gmio_clocale_islower(char c)
|
|
||||||
{
|
{
|
||||||
#if defined(GMIO_STRINGUTILS_DIRECT_TESTS)
|
#if defined(GMIO_STRINGUTILS_DIRECT_TESTS)
|
||||||
/* TODO: eliminate branch */
|
/* TODO: eliminate branch */
|
||||||
@ -148,8 +187,7 @@ GMIO_INLINE int gmio_clocale_islower(char c)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the lowercase letter converted to uppercase */
|
char gmio_clocale_toupper(char c)
|
||||||
GMIO_INLINE char gmio_clocale_toupper(char c)
|
|
||||||
{
|
{
|
||||||
static const char table_toupper[128] = {
|
static const char table_toupper[128] = {
|
||||||
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,0x09,0x0A, 0 , 0 ,0x0D, 0 , 0 ,
|
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];
|
return table_toupper[(unsigned char)c];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the uppercase letter converted to lowercase */
|
char gmio_clocale_tolower(char c)
|
||||||
GMIO_INLINE char gmio_clocale_tolower(char c)
|
|
||||||
{
|
{
|
||||||
static const char table_tolower[128] = {
|
static const char table_tolower[128] = {
|
||||||
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,0x09,0x0A, 0 , 0 ,0x0D, 0 , 0 ,
|
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];
|
return table_tolower[(unsigned char)c];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns true if \p c1 compare equals to \p c2
|
gmio_bool_t gmio_clocale_char_iequals(char c1, char c2)
|
||||||
*
|
|
||||||
* Comparison is case-insensitive
|
|
||||||
*/
|
|
||||||
GMIO_INLINE gmio_bool_t gmio_clocale_char_iequals(char c1, char c2)
|
|
||||||
{
|
{
|
||||||
/* TODO: eliminate branch */
|
/* TODO: eliminate branch */
|
||||||
return c1 == c2 || (gmio_clocale_toupper(c1) == gmio_clocale_toupper(c2));
|
return c1 == c2 || (gmio_clocale_toupper(c1) == gmio_clocale_toupper(c2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns 0 if \p str1 and \p str2 compare equal, non-zero otherwise
|
int gmio_stricmp(const char* str1, const char* str2)
|
||||||
*
|
|
||||||
* Comparison is case-insensitive
|
|
||||||
*/
|
|
||||||
GMIO_INLINE int gmio_stricmp(const char* str1, const char* str2)
|
|
||||||
{
|
{
|
||||||
while (*str1 != 0 && *str2 != 0) {
|
while (*str1 != 0 && *str2 != 0) {
|
||||||
if (!gmio_clocale_char_iequals(*str1, *str2))
|
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;
|
return *str1 == 0 && *str2 == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns true if \p str starts with string \p begin
|
gmio_bool_t gmio_istarts_with(const char* str, const char* begin)
|
||||||
*
|
|
||||||
* Comparison is case-insensitive
|
|
||||||
*/
|
|
||||||
GMIO_INLINE gmio_bool_t gmio_istarts_with(const char* str, const char* begin)
|
|
||||||
{
|
{
|
||||||
while (*begin != 0) {
|
while (*begin != 0) {
|
||||||
if (*str == 0
|
if (*str == 0 || !gmio_clocale_char_iequals(*str, *begin))
|
||||||
|| gmio_clocale_char_iequals(*str, *begin) == GMIO_FALSE)
|
|
||||||
{
|
|
||||||
return GMIO_FALSE;
|
return GMIO_FALSE;
|
||||||
}
|
|
||||||
++str;
|
++str;
|
||||||
++begin;
|
++begin;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user