Cleaned up regex.cpp
fixed strlen problem in regex many other things related to cleanup of regex.cpp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25047 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9965cadbde
commit
c5feba0ea3
@ -52,9 +52,10 @@
|
||||
|
||||
#include "wx/regex.h"
|
||||
|
||||
#ifdef wx_wchar
|
||||
#define regerror wx_regerror
|
||||
#define regfree wx_regfree
|
||||
#if wxUSE_UNICODE
|
||||
# if !defined(wxUSE_BUILTIN_REGEX)
|
||||
# error "Unicode not supported with system regex, please reconfigure with --with-regex=builtin"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -141,32 +142,25 @@ wxRegExImpl::~wxRegExImpl()
|
||||
|
||||
wxString wxRegExImpl::GetErrorMsg(int errorcode) const
|
||||
{
|
||||
wxString msg;
|
||||
wxString szError;
|
||||
|
||||
// first get the string length needed
|
||||
int len = regerror(errorcode, &m_RegEx, NULL, 0);
|
||||
if ( len > 0 )
|
||||
{
|
||||
len++;
|
||||
char* szcmbError = new char[++len];
|
||||
|
||||
#ifdef wx_wchar
|
||||
wxCharBuffer buf(len);
|
||||
(void)regerror(errorcode, &m_RegEx, szcmbError, len);
|
||||
|
||||
(void)regerror(errorcode, &m_RegEx, (char *)buf.data(), len);
|
||||
|
||||
msg = wxString(buf.data(), wxConvLibc);
|
||||
#else
|
||||
(void)regerror(errorcode, &m_RegEx, msg.GetWriteBuf(len), len);
|
||||
|
||||
msg.UngetWriteBuf();
|
||||
#endif
|
||||
szError = wxConvertMB2WX(szcmbError);
|
||||
delete [] szcmbError;
|
||||
}
|
||||
else // regerror() returned 0
|
||||
{
|
||||
msg = _("unknown error");
|
||||
szError = _("unknown error");
|
||||
}
|
||||
|
||||
return msg;
|
||||
return szError;
|
||||
}
|
||||
|
||||
bool wxRegExImpl::Compile(const wxString& expr, int flags)
|
||||
@ -189,12 +183,8 @@ bool wxRegExImpl::Compile(const wxString& expr, int flags)
|
||||
flagsRE |= REG_NEWLINE;
|
||||
|
||||
|
||||
// compile it
|
||||
#ifdef wx_wchar
|
||||
int errorcode = wx_regcomp(&m_RegEx, expr, expr.Length(), flagsRE);
|
||||
#else
|
||||
int errorcode = regcomp(&m_RegEx, expr.mb_str(), flagsRE);
|
||||
#endif
|
||||
|
||||
int errorcode = regcomp(&m_RegEx, expr, flagsRE);
|
||||
|
||||
if ( errorcode )
|
||||
{
|
||||
@ -269,12 +259,7 @@ bool wxRegExImpl::Matches(const wxChar *str, int flags) const
|
||||
}
|
||||
|
||||
// do match it
|
||||
#ifdef wx_wchar
|
||||
rm_detail_t rd;
|
||||
int rc = wx_regexec(&self->m_RegEx, str, wxStrlen(str), &rd, m_nMatches, m_Matches, flagsRE);
|
||||
#else
|
||||
int rc = regexec(&self->m_RegEx, wxConvertWX2MB(str), m_nMatches, m_Matches, flagsRE);
|
||||
#endif
|
||||
int rc = regexec(&self->m_RegEx, str, m_nMatches, m_Matches, flagsRE);
|
||||
|
||||
switch ( rc )
|
||||
{
|
||||
@ -487,38 +472,4 @@ int wxRegEx::Replace(wxString *pattern,
|
||||
return m_impl->Replace(pattern, replacement, maxMatches);
|
||||
}
|
||||
|
||||
#ifdef wx_wchar
|
||||
|
||||
/** Locale functions */
|
||||
|
||||
extern "C" {
|
||||
|
||||
int wx_isdigit(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsdigit((unsigned char) c));}
|
||||
int wx_isalpha(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsalpha((unsigned char) c));}
|
||||
int wx_isalnum(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsalnum((unsigned char) c));}
|
||||
int wx_isupper(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsupper((unsigned char) c));}
|
||||
int wx_islower(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIslower((unsigned char) c));}
|
||||
int wx_isgraph(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsgraph((unsigned char) c));}
|
||||
int wx_ispunct(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIspunct((unsigned char) c));}
|
||||
int wx_isspace(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsspace((unsigned char) c));}
|
||||
|
||||
wx_wchar wx_toupper(wx_wchar c)
|
||||
{
|
||||
if (c >= 0 && c <= UCHAR_MAX)
|
||||
return wxToupper((unsigned char) c);
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
wx_wchar wx_tolower(wx_wchar c)
|
||||
{
|
||||
if (c >= 0 && c <= UCHAR_MAX)
|
||||
return wxTolower((unsigned char) c);
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // wxUSE_REGEX
|
||||
|
@ -53,10 +53,44 @@
|
||||
int char_and_wchar_strncmp (const char* cp, const wx_wchar* wp, size_t nNum)
|
||||
{
|
||||
while(*cp++ == (const char)*wp++ && --nNum){}
|
||||
|
||||
return nNum;
|
||||
}
|
||||
|
||||
int wx_isdigit(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsdigit((unsigned char) c));}
|
||||
int wx_isalpha(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsalpha((unsigned char) c));}
|
||||
int wx_isalnum(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsalnum((unsigned char) c));}
|
||||
int wx_isupper(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsupper((unsigned char) c));}
|
||||
int wx_islower(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIslower((unsigned char) c));}
|
||||
int wx_isgraph(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsgraph((unsigned char) c));}
|
||||
int wx_ispunct(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIspunct((unsigned char) c));}
|
||||
int wx_isspace(wx_wchar c) {return (c >= 0 && c <= UCHAR_MAX && wxIsspace((unsigned char) c));}
|
||||
|
||||
wx_wchar wx_toupper(wx_wchar c)
|
||||
{
|
||||
if (c >= 0 && c <= UCHAR_MAX)
|
||||
return wxToupper((unsigned char) c);
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
wx_wchar wx_tolower(wx_wchar c)
|
||||
{
|
||||
if (c >= 0 && c <= UCHAR_MAX)
|
||||
return wxTolower((unsigned char) c);
|
||||
return c;
|
||||
}
|
||||
|
||||
int wx_strlen(const wx_wchar* szString)
|
||||
{
|
||||
/*
|
||||
Generic -- note that some clib functions also test for eol character '^Z'
|
||||
|
||||
int nLength = 0;
|
||||
for (; *(szString + nLength) != '\0'; nLength++);
|
||||
return nLength;
|
||||
*/
|
||||
return szString == NULL ? 0 : wxStrlen_(szString);
|
||||
}
|
||||
/* ASCII character-name table */
|
||||
|
||||
static struct cname
|
||||
|
@ -188,6 +188,7 @@ extern int wx_ispunct(wx_wchar c);
|
||||
extern int wx_isspace(wx_wchar c);
|
||||
extern wx_wchar wx_toupper(wx_wchar c);
|
||||
extern wx_wchar wx_tolower(wx_wchar c);
|
||||
extern int wx_strlen(const wx_wchar* szString);
|
||||
static int nmcces(struct vars *);
|
||||
static int nleaders(struct vars *);
|
||||
static struct cvec *allmcces(struct vars *, struct cvec *);
|
||||
@ -296,18 +297,7 @@ regcomp(regex_t *re,
|
||||
const chr *string,
|
||||
int flags)
|
||||
{
|
||||
|
||||
size_t nLen = 0;
|
||||
chr* s2 = (chr*) string;
|
||||
|
||||
if (string && *string)
|
||||
{
|
||||
while(*++s2);
|
||||
}
|
||||
|
||||
nLen = ((s2 - string) / sizeof(chr));
|
||||
|
||||
return wx_regcomp(re, string, nLen, flags);
|
||||
return wx_regcomp(re, string, wx_strlen(string), flags);
|
||||
}
|
||||
int
|
||||
wx_regcomp(regex_t *re,
|
||||
|
@ -44,6 +44,7 @@ extern "C" {
|
||||
WXWINDOWS CUSTOM
|
||||
*****************************/
|
||||
#ifndef _REGEX_CUSTOM_H_
|
||||
# define wxUSE_BUILTIN_REGEX
|
||||
# define wx_wchar wxChar
|
||||
/* FreeBSD, Watcom and DMars require this, CW doesn't have nor need it. */
|
||||
/* Others also don't seem to need it. If you have an error related to */
|
||||
|
@ -172,17 +172,7 @@ regexec(regex_t *re,
|
||||
int flags)
|
||||
{
|
||||
rm_detail_t det;
|
||||
size_t nLen = 0;
|
||||
chr* s2 = (chr*) string;
|
||||
|
||||
if (string && *string)
|
||||
{
|
||||
while(*++s2);
|
||||
}
|
||||
|
||||
nLen = ((s2 - string) / sizeof(chr));
|
||||
|
||||
return wx_regexec(re, string, nLen, &det, nmatch, pmatch, flags);
|
||||
return wx_regexec(re, string, wx_strlen(string), &det, nmatch, pmatch, flags);
|
||||
}
|
||||
int
|
||||
wx_regexec(regex_t *re,
|
||||
|
Loading…
Reference in New Issue
Block a user