removed qse_ccls_t and related functions and added qse_strtrm()
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: chr.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
|
||||
* $Id: chr.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -136,22 +136,4 @@ qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_id_t type)
|
||||
#error unsupported character type
|
||||
#endif
|
||||
|
||||
static qse_bool_t ccls_is (void* data, qse_cint_t c, qse_ccls_id_t type)
|
||||
{
|
||||
return qse_ccls_is (c, type);
|
||||
}
|
||||
|
||||
static qse_cint_t ccls_to (void* data, qse_cint_t c, qse_ccls_id_t type)
|
||||
{
|
||||
return qse_ccls_to (c, type);
|
||||
}
|
||||
|
||||
static qse_ccls_t ccls =
|
||||
{
|
||||
ccls_is,
|
||||
ccls_to,
|
||||
QSE_NULL
|
||||
};
|
||||
|
||||
qse_ccls_t* qse_ccls = &ccls;
|
||||
|
||||
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* $Id: chr.h 97 2009-03-10 10:39:18Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_LIB_CMN_CHR_H_
|
||||
#define _QSE_LIB_CMN_CHR_H_
|
||||
|
||||
#include <qse/cmn/chr.h>
|
||||
|
||||
#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
|
||||
|
||||
#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))
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rex.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
|
||||
* $Id: rex.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -17,8 +17,8 @@
|
||||
*/
|
||||
|
||||
#include <qse/cmn/rex.h>
|
||||
#include <qse/cmn/chr.h>
|
||||
#include "mem.h"
|
||||
#include "chr.h"
|
||||
|
||||
#ifdef DEBUG_REX
|
||||
#include <qse/bas/sio.h>
|
||||
@ -113,7 +113,6 @@ struct builder_t
|
||||
struct matcher_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_ccls_t* ccls;
|
||||
|
||||
struct
|
||||
{
|
||||
@ -230,18 +229,66 @@ static const qse_byte_t* match_occurrences (
|
||||
static qse_bool_t __test_charset (
|
||||
matcher_t* matcher, const qse_byte_t* p, qse_size_t csc, qse_char_t c);
|
||||
|
||||
static qse_bool_t cc_isalnum (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isalpha (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isblank (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_iscntrl (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isdigit (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isgraph (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_islower (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isprint (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_ispunct (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isspace (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isupper (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isxdigit (qse_ccls_t* ccls, qse_char_t c);
|
||||
static qse_bool_t cc_isalnum (qse_char_t c)
|
||||
{
|
||||
return QSE_ISALNUM (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isalpha (qse_char_t c)
|
||||
{
|
||||
return QSE_ISALPHA (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isblank (qse_char_t c)
|
||||
{
|
||||
return c == QSE_T(' ') || c == QSE_T('\t');
|
||||
}
|
||||
|
||||
static qse_bool_t cc_iscntrl (qse_char_t c)
|
||||
{
|
||||
return QSE_ISCNTRL (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isdigit (qse_char_t c)
|
||||
{
|
||||
return QSE_ISDIGIT (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isgraph (qse_char_t c)
|
||||
{
|
||||
return QSE_ISGRAPH (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_islower (qse_char_t c)
|
||||
{
|
||||
return QSE_ISLOWER (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isprint (qse_char_t c)
|
||||
{
|
||||
return QSE_ISPRINT (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_ispunct (qse_char_t c)
|
||||
{
|
||||
return QSE_ISPUNCT (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isspace (qse_char_t c)
|
||||
{
|
||||
return QSE_ISSPACE (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isupper (qse_char_t c)
|
||||
{
|
||||
return QSE_ISUPPER (c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isxdigit (qse_char_t c)
|
||||
{
|
||||
return QSE_ISXDIGIT (c);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
XXX
|
||||
@ -254,7 +301,7 @@ struct __char_class_t
|
||||
{
|
||||
const qse_char_t* name;
|
||||
qse_size_t name_len;
|
||||
qse_bool_t (*func) (qse_ccls_t* ccls, qse_char_t c);
|
||||
qse_bool_t (*func) (qse_char_t c);
|
||||
};
|
||||
|
||||
static struct __char_class_t __char_class[] =
|
||||
@ -349,7 +396,7 @@ void* qse_buildrex (
|
||||
}
|
||||
|
||||
int qse_matchrex (
|
||||
qse_mmgr_t* mmgr, qse_ccls_t* ccls, qse_size_t depth,
|
||||
qse_mmgr_t* mmgr, qse_size_t depth,
|
||||
void* code, int option,
|
||||
const qse_char_t* str, qse_size_t len,
|
||||
const qse_char_t** match_ptr, qse_size_t* match_len, int* errnum)
|
||||
@ -360,7 +407,6 @@ int qse_matchrex (
|
||||
/*const qse_char_t* match_ptr_zero = QSE_NULL;*/
|
||||
|
||||
matcher.mmgr = mmgr;
|
||||
matcher.ccls = ccls;
|
||||
|
||||
/* store the source string */
|
||||
matcher.match.str.ptr = str;
|
||||
@ -1393,7 +1439,7 @@ static const qse_byte_t* match_ord_char (
|
||||
ubound = cp->ubound;
|
||||
|
||||
cc = *(qse_char_t*)p; p += QSE_SIZEOF(cc);
|
||||
if (matcher->ignorecase) cc = QSE_CCLS_TOUPPER(matcher->ccls, cc);
|
||||
if (matcher->ignorecase) cc = QSE_TOUPPER(cc);
|
||||
|
||||
/* merge the same consecutive codes
|
||||
* for example, a{1,10}a{0,10} is shortened to a{1,20} */
|
||||
@ -1402,7 +1448,7 @@ static const qse_byte_t* match_ord_char (
|
||||
while (p < mat->branch_end &&
|
||||
cp->cmd == ((const code_t*)p)->cmd)
|
||||
{
|
||||
if (QSE_CCLS_TOUPPER (matcher->ccls, *(qse_char_t*)(p+QSE_SIZEOF(*cp))) != cc) break;
|
||||
if (QSE_TOUPPER (*(qse_char_t*)(p+QSE_SIZEOF(*cp))) != cc) break;
|
||||
|
||||
lbound += ((const code_t*)p)->lbound;
|
||||
ubound += ((const code_t*)p)->ubound;
|
||||
@ -1444,7 +1490,7 @@ static const qse_byte_t* match_ord_char (
|
||||
QSE_T("match_ord_char: <ignorecase> %c %c\n"),
|
||||
cc, mat->match_ptr[si]);
|
||||
#endif
|
||||
if (cc != QSE_CCLS_TOUPPER (matcher->ccls, mat->match_ptr[si])) break;
|
||||
if (cc != QSE_TOUPPER (mat->match_ptr[si])) break;
|
||||
si++;
|
||||
}
|
||||
}
|
||||
@ -1507,7 +1553,7 @@ static const qse_byte_t* match_charset (
|
||||
if (&mat->match_ptr[si] >= matcher->match.str.end) break;
|
||||
|
||||
c = mat->match_ptr[si];
|
||||
if (matcher->ignorecase) c = QSE_CCLS_TOUPPER(matcher->ccls, c);
|
||||
if (matcher->ignorecase) c = QSE_TOUPPER(c);
|
||||
|
||||
n = __test_charset (matcher, p, cshdr->csc, c);
|
||||
if (cp->negate) n = !n;
|
||||
@ -1772,7 +1818,7 @@ static qse_bool_t __test_charset (
|
||||
{
|
||||
c1 = *(const qse_char_t*)p;
|
||||
if (matcher->ignorecase)
|
||||
c1 = QSE_CCLS_TOUPPER(matcher->ccls, c1);
|
||||
c1 = QSE_TOUPPER(c1);
|
||||
#ifdef DEBUG_REX
|
||||
qse_dprintf (
|
||||
QSE_T("match_charset: <one> %c %c\n"), c, c1);
|
||||
@ -1787,8 +1833,8 @@ static qse_bool_t __test_charset (
|
||||
|
||||
if (matcher->ignorecase)
|
||||
{
|
||||
c1 = QSE_CCLS_TOUPPER(matcher->ccls, c1);
|
||||
c2 = QSE_CCLS_TOUPPER(matcher->ccls, c2);
|
||||
c1 = QSE_TOUPPER(c1);
|
||||
c2 = QSE_TOUPPER(c2);
|
||||
}
|
||||
#ifdef DEBUG_REX
|
||||
qse_dprintf (
|
||||
@ -1804,8 +1850,7 @@ static qse_bool_t __test_charset (
|
||||
QSE_T("match_charset: <class> %c %s\n"),
|
||||
c, __char_class[c1].name);
|
||||
#endif
|
||||
if (__char_class[c1].func (
|
||||
matcher->ccls, c)) return QSE_TRUE;
|
||||
if (__char_class[c1].func(c)) return QSE_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1819,66 +1864,6 @@ static qse_bool_t __test_charset (
|
||||
return QSE_FALSE;
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isalnum (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISALNUM (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isalpha (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISALPHA (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isblank (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return c == QSE_T(' ') || c == QSE_T('\t');
|
||||
}
|
||||
|
||||
static qse_bool_t cc_iscntrl (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISCNTRL (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isdigit (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISDIGIT (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isgraph (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISGRAPH (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_islower (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISLOWER (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isprint (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISPRINT (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_ispunct (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISPUNCT (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isspace (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISSPACE (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isupper (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISUPPER (ccls, c);
|
||||
}
|
||||
|
||||
static qse_bool_t cc_isxdigit (qse_ccls_t* ccls, qse_char_t c)
|
||||
{
|
||||
return QSE_CCLS_ISXDIGIT (ccls, c);
|
||||
}
|
||||
|
||||
#if 0
|
||||
#define DPRINTF awk->prmfns.misc.dprintf
|
||||
#define DCUSTOM awk->prmfns.misc.custom_data
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_bas.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
|
||||
* $Id: str_bas.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
#include "chr.h"
|
||||
#include <qse/cmn/chr.h>
|
||||
#include "mem.h"
|
||||
|
||||
qse_size_t qse_strlen (const qse_char_t* str)
|
||||
@ -401,21 +401,20 @@ int qse_strxncmp (
|
||||
return (s2 < end2)? -1: 0;
|
||||
}
|
||||
|
||||
int qse_strcasecmp (
|
||||
const qse_char_t* s1, const qse_char_t* s2, qse_ccls_t* ccls)
|
||||
int qse_strcasecmp (const qse_char_t* s1, const qse_char_t* s2)
|
||||
{
|
||||
while (QSE_CCLS_TOUPPER(ccls,*s1) == QSE_CCLS_TOUPPER(ccls,*s2))
|
||||
while (QSE_TOUPPER(*s1) == QSE_TOUPPER(*s2))
|
||||
{
|
||||
if (*s1 == QSE_C('\0')) return 0;
|
||||
s1++, s2++;
|
||||
}
|
||||
|
||||
return (QSE_CCLS_TOUPPER(ccls,*s1) > QSE_CCLS_TOUPPER(ccls,*s2))? 1: -1;
|
||||
return (QSE_TOUPPER(*s1) > QSE_TOUPPER(*s2))? 1: -1;
|
||||
}
|
||||
|
||||
int qse_strxncasecmp (
|
||||
const qse_char_t* s1, qse_size_t len1,
|
||||
const qse_char_t* s2, qse_size_t len2, qse_ccls_t* ccls)
|
||||
const qse_char_t* s2, qse_size_t len2)
|
||||
{
|
||||
qse_char_t c1, c2;
|
||||
const qse_char_t* end1 = s1 + len1;
|
||||
@ -423,10 +422,10 @@ int qse_strxncasecmp (
|
||||
|
||||
while (s1 < end1)
|
||||
{
|
||||
c1 = QSE_CCLS_TOUPPER (ccls, *s1);
|
||||
c1 = QSE_TOUPPER (*s1);
|
||||
if (s2 < end2)
|
||||
{
|
||||
c2 = QSE_CCLS_TOUPPER (ccls, *s2);
|
||||
c2 = QSE_TOUPPER (*s2);
|
||||
if (c1 > c2) return 1;
|
||||
if (c1 < c2) return -1;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str_utl.c 83 2009-02-24 14:05:17Z hyunghwan.chung $
|
||||
* $Id: str_utl.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -17,9 +17,13 @@
|
||||
*/
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
#include "chr.h"
|
||||
#include <qse/cmn/chr.h>
|
||||
|
||||
int qse_strspltr (
|
||||
#define ISSPACE(c) \
|
||||
((c) == QSE_T(' ') || (c) == QSE_T('\t') || (c) == QSE_T('\n') || \
|
||||
(c) == QSE_T('\r') || (c) == QSE_T('\v') && (c) == QSE_T('\f'))
|
||||
|
||||
int qse_strspltrn (
|
||||
qse_char_t* s, const qse_char_t* delim,
|
||||
qse_char_t lquote, qse_char_t rquote,
|
||||
qse_char_t escape, const qse_char_t* trset)
|
||||
@ -302,5 +306,26 @@ int qse_strspl (
|
||||
qse_char_t* s, const qse_char_t* delim,
|
||||
qse_char_t lquote, qse_char_t rquote, qse_char_t escape)
|
||||
{
|
||||
return qse_strspltr (s, delim, lquote, rquote, escape, QSE_NULL);
|
||||
return qse_strspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
|
||||
}
|
||||
|
||||
qse_char_t* qse_strtrm (qse_char_t* str, int opt)
|
||||
{
|
||||
qse_char_t* p = str;
|
||||
qse_char_t* s = QSE_NULL, * e = QSE_NULL;
|
||||
|
||||
while (*p != QSE_T('\0'))
|
||||
{
|
||||
if (!QSE_ISSPACE(*p))
|
||||
{
|
||||
if (s == QSE_NULL) s = p;
|
||||
e = p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
if (opt & QSE_STRTRM_RIGHT) e[1] = QSE_T('\0');
|
||||
if (opt & QSE_STRTRM_LEFT) str = s;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
Reference in New Issue
Block a user