added qse_mbscmp()/qse_wcscmp() and related functions while doing similar things for character class handling

This commit is contained in:
2011-03-25 22:36:43 +00:00
parent 794b0f8c47
commit c3f6340f9e
14 changed files with 629 additions and 323 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: chr.h 356 2010-09-07 12:29:25Z hyunghwan.chung $
* $Id: chr.h 413 2011-03-25 04:36:43Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -42,71 +42,156 @@ enum qse_ccls_id_t
QSE_CCLS_PUNCT
};
typedef enum qse_ccls_id_t qse_ccls_id_t;
typedef qse_ccls_id_t qse_mccls_id_t;
typedef qse_ccls_id_t qse_wccls_id_t;
#define QSE_MCCLS_UPPER QSE_CCLS_UPPER
#define QSE_MCCLS_LOWER QSE_CCLS_LOWER
#define QSE_MCCLS_ALPHA QSE_CCLS_ALPHA
#define QSE_MCCLS_DIGIT QSE_CCLS_DIGIT
#define QSE_MCCLS_XDIGIT QSE_CCLS_XDIGIT
#define QSE_MCCLS_ALNUM QSE_CCLS_ALNUM
#define QSE_MCCLS_SPACE QSE_CCLS_SPACE
#define QSE_MCCLS_PRINT QSE_CCLS_PRINT
#define QSE_MCCLS_GRAPH QSE_CCLS_GRAPH
#define QSE_MCCLS_CNTRL QSE_CCLS_CNTRL
#define QSE_MCCLS_PUNCT QSE_CCLS_PUNCT
#define QSE_WCCLS_UPPER QSE_CCLS_UPPER
#define QSE_WCCLS_LOWER QSE_CCLS_LOWER
#define QSE_WCCLS_ALPHA QSE_CCLS_ALPHA
#define QSE_WCCLS_DIGIT QSE_CCLS_DIGIT
#define QSE_WCCLS_XDIGIT QSE_CCLS_XDIGIT
#define QSE_WCCLS_ALNUM QSE_CCLS_ALNUM
#define QSE_WCCLS_SPACE QSE_CCLS_SPACE
#define QSE_WCCLS_PRINT QSE_CCLS_PRINT
#define QSE_WCCLS_GRAPH QSE_CCLS_GRAPH
#define QSE_WCCLS_CNTRL QSE_CCLS_CNTRL
#define QSE_WCCLS_PUNCT QSE_CCLS_PUNCT
#ifdef USE_STDC
# if defined(QSE_CHAR_IS_MCHAR)
# include <ctype.h>
# define QSE_ISUPPER(c) isupper(c)
# define QSE_ISLOWER(c) islower(c)
# define QSE_ISALPHA(c) isalpha(c)
# define QSE_ISDIGIT(c) isdigit(c)
# define QSE_ISXDIGIT(c) isxdigit(c)
# define QSE_ISALNUM(c) isalnum(c)
# define QSE_ISSPACE(c) isspace(c)
# define QSE_ISPRINT(c) isprint(c)
# define QSE_ISGRAPH(c) isgraph(c)
# define QSE_ISCNTRL(c) iscntrl(c)
# define QSE_ISPUNCT(c) ispunct(c)
# define QSE_TOUPPER(c) toupper(c)
# define QSE_TOLOWER(c) tolower(c)
# elif defined(QSE_CHAR_IS_WCHAR)
# include <wctype.h>
# define QSE_ISUPPER(c) iswupper(c)
# define QSE_ISLOWER(c) iswlower(c)
# define QSE_ISALPHA(c) iswalpha(c)
# define QSE_ISDIGIT(c) iswdigit(c)
# define QSE_ISXDIGIT(c) iswxdigit(c)
# define QSE_ISALNUM(c) iswalnum(c)
# define QSE_ISSPACE(c) iswspace(c)
# define QSE_ISPRINT(c) iswprint(c)
# define QSE_ISGRAPH(c) iswgraph(c)
# define QSE_ISCNTRL(c) iswcntrl(c)
# define QSE_ISPUNCT(c) iswpunct(c)
# define QSE_TOUPPER(c) towupper(c)
# define QSE_TOLOWER(c) towlower(c)
# else
# error Unsupported character type
# endif
# include <ctype.h>
# include <wctype.h>
#
# define QSE_ISUPPER(c) isupper(c)
# define QSE_ISLOWER(c) islower(c)
# define QSE_ISALPHA(c) isalpha(c)
# define QSE_ISDIGIT(c) isdigit(c)
# define QSE_ISXDIGIT(c) isxdigit(c)
# define QSE_ISALNUM(c) isalnum(c)
# define QSE_ISSPACE(c) isspace(c)
# define QSE_ISPRINT(c) isprint(c)
# define QSE_ISGRAPH(c) isgraph(c)
# define QSE_ISCNTRL(c) iscntrl(c)
# define QSE_ISPUNCT(c) ispunct(c)
# define QSE_TOUPPER(c) toupper(c)
# define QSE_TOLOWER(c) tolower(c)
#
# define QSE_ISUPPER(c) iswupper(c)
# define QSE_ISLOWER(c) iswlower(c)
# define QSE_ISALPHA(c) iswalpha(c)
# define QSE_ISDIGIT(c) iswdigit(c)
# define QSE_ISXDIGIT(c) iswxdigit(c)
# define QSE_ISALNUM(c) iswalnum(c)
# define QSE_ISSPACE(c) iswspace(c)
# define QSE_ISPRINT(c) iswprint(c)
# define QSE_ISGRAPH(c) iswgraph(c)
# define QSE_ISCNTRL(c) iswcntrl(c)
# define QSE_ISPUNCT(c) iswpunct(c)
# define QSE_TOUPPER(c) towupper(c)
# define QSE_TOLOWER(c) towlower(c)
#else
# define QSE_ISUPPER(c) (qse_ccls_is(c,QSE_CCLS_UPPER))
# define QSE_ISLOWER(c) (qse_ccls_is(c,QSE_CCLS_LOWER))
# define QSE_ISALPHA(c) (qse_ccls_is(c,QSE_CCLS_ALPHA))
# define QSE_ISDIGIT(c) (qse_ccls_is(c,QSE_CCLS_DIGIT))
# define QSE_ISXDIGIT(c) (qse_ccls_is(c,QSE_CCLS_XDIGIT))
# define QSE_ISALNUM(c) (qse_ccls_is(c,QSE_CCLS_ALNUM))
# define QSE_ISSPACE(c) (qse_ccls_is(c,QSE_CCLS_SPACE))
# define QSE_ISPRINT(c) (qse_ccls_is(c,QSE_CCLS_PRINT))
# define QSE_ISGRAPH(c) (qse_ccls_is(c,QSE_CCLS_GRAPH))
# define QSE_ISCNTRL(c) (qse_ccls_is(c,QSE_CCLS_CNTRL))
# define QSE_ISPUNCT(c) (qse_ccls_is(c,QSE_CCLS_PUNCT))
# define QSE_TOUPPER(c) (qse_ccls_to(c,QSE_CCLS_UPPER))
# define QSE_TOLOWER(c) (qse_ccls_to(c,QSE_CCLS_LOWER))
# define QSE_ISMUPPER(c) (qse_mccls_is(c,QSE_CCLS_UPPER))
# define QSE_ISMLOWER(c) (qse_mccls_is(c,QSE_CCLS_LOWER))
# define QSE_ISMALPHA(c) (qse_mccls_is(c,QSE_CCLS_ALPHA))
# define QSE_ISMDIGIT(c) (qse_mccls_is(c,QSE_CCLS_DIGIT))
# define QSE_ISMXDIGIT(c) (qse_mccls_is(c,QSE_CCLS_XDIGIT))
# define QSE_ISMALNUM(c) (qse_mccls_is(c,QSE_CCLS_ALNUM))
# define QSE_ISMSPACE(c) (qse_mccls_is(c,QSE_CCLS_SPACE))
# define QSE_ISMPRINT(c) (qse_mccls_is(c,QSE_CCLS_PRINT))
# define QSE_ISMGRAPH(c) (qse_mccls_is(c,QSE_CCLS_GRAPH))
# define QSE_ISMCNTRL(c) (qse_mccls_is(c,QSE_CCLS_CNTRL))
# define QSE_ISMPUNCT(c) (qse_mccls_is(c,QSE_CCLS_PUNCT))
# define QSE_TOMUPPER(c) (qse_mccls_to(c,QSE_CCLS_UPPER))
# define QSE_TOMLOWER(c) (qse_mccls_to(c,QSE_CCLS_LOWER))
#
# define QSE_ISWUPPER(c) (qse_wccls_is(c,QSE_CCLS_UPPER))
# define QSE_ISWLOWER(c) (qse_wccls_is(c,QSE_CCLS_LOWER))
# define QSE_ISWALPHA(c) (qse_wccls_is(c,QSE_CCLS_ALPHA))
# define QSE_ISWDIGIT(c) (qse_wccls_is(c,QSE_CCLS_DIGIT))
# define QSE_ISWXDIGIT(c) (qse_wccls_is(c,QSE_CCLS_XDIGIT))
# define QSE_ISWALNUM(c) (qse_wccls_is(c,QSE_CCLS_ALNUM))
# define QSE_ISWSPACE(c) (qse_wccls_is(c,QSE_CCLS_SPACE))
# define QSE_ISWPRINT(c) (qse_wccls_is(c,QSE_CCLS_PRINT))
# define QSE_ISWGRAPH(c) (qse_wccls_is(c,QSE_CCLS_GRAPH))
# define QSE_ISWCNTRL(c) (qse_wccls_is(c,QSE_CCLS_CNTRL))
# define QSE_ISWPUNCT(c) (qse_wccls_is(c,QSE_CCLS_PUNCT))
# define QSE_TOWUPPER(c) (qse_wccls_to(c,QSE_CCLS_UPPER))
# define QSE_TOWLOWER(c) (qse_wccls_to(c,QSE_CCLS_LOWER))
#endif
#ifdef QSE_CHAR_IS_MCHAR
# define QSE_ISUPPER(c) QSE_ISMUPPER(c)
# define QSE_ISLOWER(c) QSE_ISMLOWER(c)
# define QSE_ISALPHA(c) QSE_ISMALPHA(c)
# define QSE_ISDIGIT(c) QSE_ISMDIGIT(c)
# define QSE_ISXDIGIT(c) QSE_ISMXDIGIT(c)
# define QSE_ISALNUM(c) QSE_ISMALNUM(c)
# define QSE_ISSPACE(c) QSE_ISMSPACE(c)
# define QSE_ISPRINT(c) QSE_ISMPRINT(c)
# define QSE_ISGRAPH(c) QSE_ISMGRAPH(c)
# define QSE_ISCNTRL(c) QSE_ISMCNTRL(c)
# define QSE_ISPUNCT(c) QSE_ISMPUNCT(c)
# define QSE_TOUPPER(c) QSE_TOMUPPER(c)
# define QSE_TOLOWER(c) QSE_TOMLOWER(c)
#else
# define QSE_ISUPPER(c) QSE_ISWUPPER(c)
# define QSE_ISLOWER(c) QSE_ISWLOWER(c)
# define QSE_ISALPHA(c) QSE_ISWALPHA(c)
# define QSE_ISDIGIT(c) QSE_ISWDIGIT(c)
# define QSE_ISXDIGIT(c) QSE_ISWXDIGIT(c)
# define QSE_ISALNUM(c) QSE_ISWALNUM(c)
# define QSE_ISSPACE(c) QSE_ISWSPACE(c)
# define QSE_ISPRINT(c) QSE_ISWPRINT(c)
# define QSE_ISGRAPH(c) QSE_ISWGRAPH(c)
# define QSE_ISCNTRL(c) QSE_ISWCNTRL(c)
# define QSE_ISPUNCT(c) QSE_ISWPUNCT(c)
# define QSE_TOUPPER(c) QSE_TOWUPPER(c)
# define QSE_TOLOWER(c) QSE_TOWLOWER(c)
#endif
#ifdef __cplusplus
extern "C" {
#endif
qse_bool_t qse_ccls_is (
qse_cint_t c,
qse_ccls_id_t type
qse_bool_t qse_mccls_is (
qse_mcint_t c,
qse_mccls_id_t type
);
qse_cint_t qse_ccls_to (
qse_cint_t c,
qse_ccls_id_t type
qse_bool_t qse_wccls_is (
qse_wcint_t c,
qse_wccls_id_t type
);
qse_mcint_t qse_mccls_to (
qse_mcint_t c,
qse_mccls_id_t type
);
qse_wcint_t qse_wccls_to (
qse_wcint_t c,
qse_wccls_id_t type
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_ccls_is(c,type) qse_mccls_is(c,type);
# define qse_ccls_to(c,type) qse_mccls_to(c,type);
#else
# define qse_ccls_is(c,type) qse_wccls_is(c,type);
# define qse_ccls_to(c,type) qse_wccls_to(c,type);
#endif
/**
* The qse_mblen() function scans a multibyte sequence to get the number of
* bytes needed to form a wide character. It does not scan more than @a mblen

View File

@ -1,5 +1,5 @@
/*
* $Id: fio.h 402 2011-03-18 15:07:21Z hyunghwan.chung $
* $Id: fio.h 413 2011-03-25 04:36:43Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -78,7 +78,7 @@ enum qse_fio_mode_t
QSE_FIO_XOTH = 00001 /* can be executed by others */
};
#if defined (_WIN32)
#if defined(_WIN32)
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* qse_fio_hnd_t;
#elif defined(__OS2__)

View File

@ -1,5 +1,5 @@
/*
* $Id: sll.h 356 2010-09-07 12:29:25Z hyunghwan.chung $
* $Id: sll.h 413 2011-03-25 04:36:43Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -133,8 +133,8 @@ struct qse_sll_node_t
#define QSE_SLL_HEAD(sll) ((sll)->head)
#define QSE_SLL_TAIL(sll) ((sll)->tail)
#define QSE_SLL_SIZE(sll) ((const qse_size_t)(sll)->size)
#define QSE_SLL_SCALE(sll) ((const int)(sll)->scale)
#define QSE_SLL_SIZE(sll) ((sll)->size)
#define QSE_SLL_SCALE(sll) ((sll)->scale)
/**
* The QSE_SLL_DPTR macro gets the data pointer in a node.

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h 411 2011-03-24 14:20:55Z hyunghwan.chung $
* $Id: str.h 413 2011-03-25 04:36:43Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -473,37 +473,67 @@ qse_size_t qse_strxncat (
qse_size_t len
);
int qse_strcmp (
const qse_char_t* s1,
const qse_char_t* s2
int qse_mbscmp (
const qse_mchar_t* s1,
const qse_mchar_t* s2
);
int qse_strxcmp (
const qse_char_t* s1,
qse_size_t len1,
const qse_char_t* s2
int qse_wcscmp (
const qse_wchar_t* s1,
const qse_wchar_t* s2
);
int qse_strxncmp (
const qse_char_t* s1,
qse_size_t len1,
const qse_char_t* s2,
qse_size_t len2
int qse_mbsxcmp (
const qse_mchar_t* s1,
qse_size_t ln1,
const qse_mchar_t* s2
);
int qse_strcasecmp (
const qse_char_t* s1,
const qse_char_t* s2
int qse_wcsxcmp (
const qse_wchar_t* s1,
qse_size_t ln1,
const qse_wchar_t* s2
);
int qse_strxcasecmp (
const qse_char_t* s1,
qse_size_t len,
const qse_char_t* s2
int qse_mbsxncmp (
const qse_mchar_t* s1,
qse_size_t ln1,
const qse_mchar_t* s2,
qse_size_t ln2
);
int qse_wcsxncmp (
const qse_wchar_t* s1,
qse_size_t ln1,
const qse_wchar_t* s2,
qse_size_t ln2
);
int qse_mbscasecmp (
const qse_mchar_t* s1,
const qse_mchar_t* s2
);
int qse_wcscasecmp (
const qse_wchar_t* s1,
const qse_wchar_t* s2
);
int qse_mbsxcasecmp (
const qse_mchar_t* s1,
qse_size_t ln,
const qse_mchar_t* s2
);
int qse_wcsxcasecmp (
const qse_wchar_t* s1,
qse_size_t ln,
const qse_wchar_t* s2
);
/**
* The qse_strxncasecmp() function compares characters at the same position
* The qse_mbsxncasecmp() function compares characters at the same position
* in each string after converting them to the same case temporarily.
* It accepts two strings and a character class handler. A string is
* represented by its beginning pointer and length.
@ -514,7 +544,7 @@ int qse_strxcasecmp (
*
* The following code snippet compares "foo" and "FoO" case-insenstively.
* @code
* qse_strxncasecmp (QSE_T("foo"), 3, QSE_T("FoO"), 3);
* qse_mbsxncasecmp (QSE_MT("foo"), 3, QSE_MT("FoO"), 3);
* @endcode
*
* @return 0 if two strings are equal,
@ -522,13 +552,59 @@ int qse_strxcasecmp (
* -1 if the second string is larger.
*
*/
int qse_strxncasecmp (
const qse_char_t* s1, /**< pointer to the first string */
qse_size_t len1, /**< length of the first string */
const qse_char_t* s2, /**< pointer to the second string */
qse_size_t len2 /**< length of the second string */
int qse_mbsxncasecmp (
const qse_mchar_t* s1, /**< pointer to the first string */
qse_size_t ln1, /**< length of the first string */
const qse_mchar_t* s2, /**< pointer to the second string */
qse_size_t ln2 /**< length of the second string */
);
/**
* The qse_wcsxncasecmp() function compares characters at the same position
* in each string after converting them to the same case temporarily.
* It accepts two strings and a character class handler. A string is
* represented by its beginning pointer and length.
*
* For two strings to be equal, they need to have the same length and all
* characters in the first string must be equal to their counterpart in the
* second string.
*
* The following code snippet compares "foo" and "FoO" case-insenstively.
* @code
* qse_wcsxncasecmp (QSE_WT("foo"), 3, QSE_WT("FoO"), 3);
* @endcode
*
* @return 0 if two strings are equal,
* a positive number if the first string is larger,
* -1 if the second string is larger.
*
*/
int qse_wcsxncasecmp (
const qse_wchar_t* s1, /**< pointer to the first string */
qse_size_t ln1, /**< length of the first string */
const qse_wchar_t* s2, /**< pointer to the second string */
qse_size_t ln2 /**< length of the second string */
);
#ifdef QSE_CHAR_IS_MCHAR
# define qse_strcmp(s1,s2) qse_mbscmp(s1,s2)
# define qse_strxcmp(s1,ln1,s2) qse_mbsxcmp(s1,ln1,s2)
# define qse_strxncmp(s1,ln1,s2,ln2) qse_mbsxncmp(s1,ln1,s2,ln2)
# define qse_strcasecmp(s1,s2) qse_mbscasecmp(s1,s2)
# define qse_strxcasecmp(s1,ln1,s2) qse_mbsxcasecmp(s1,ln1,s2)
# define qse_strxncasecmp(s1,ln1,s2,ln2) qse_mbsxncasecmp(s1,ln1,s2,ln2)
#else
# define qse_strcmp(s1,s2) qse_wcscmp(s1,s2)
# define qse_strxcmp(s1,ln1,s2) qse_wcsxcmp(s1,ln1,s2)
# define qse_strxncmp(s1,ln1,s2,ln2) qse_wcsxncmp(s1,ln1,s2,ln2)
# define qse_strcasecmp(s1,s2) qse_wcscasecmp(s1,s2)
# define qse_strxcasecmp(s1,ln1,s2) qse_wcsxcasecmp(s1,ln1,s2)
# define qse_strxncasecmp(s1,ln1,s2,ln2) qse_wcsxncasecmp(s1,ln1,s2,ln2)
#endif
qse_char_t* qse_strdup (
const qse_char_t* str,
qse_mmgr_t* mmgr