Thursday, December 14, 2006

CAtlRegExp Match access violation

if the string you want to match (not the regular expression string) contains characters with code >= 128 then CAtlRegExp::Match() method fails. Here is the fix suggested here: http://groups-beta.google.com/group/microsoft.public.vc.atl/msg/b525c84477676c4f Hi, I was running in the same problem with german umlauts. The algorithm seems to be buggy. To word around that, copy the file C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlrx.h to your project path and make the following changes and include it in your cpp: Line 637 New code:
unsigned char* usz = (unsigned char *) sz;
size_t u = (size_t) *usz;

instead of Old code:
size_t u = (size_t) *sz; and Line 1181 New code:
unsigned char uchStart = chStart;
unsigned char uchEnd = chEnd;
for (int i=uchStart; i<=uchEnd; i++)

instead of Old code:
for (int i=chStart; i<=chEnd; i++) With these changes everthing should work fine. Good luck! Michael

1 comment:

Anonymous said...

You can greatly improve the class performance if you cache the object.
For example, if you know you will be Match-ing several times the same regular expression, in order to improve performance, you need to keep the CAtlRegExp object seperately, Parse() once and Match() every time you need.


CAtlRegExp<> rx;

void InitOnce()
{
rx.Parse(..);
}

void Do1()
{
rx.Match()
}

void Do2()
{
rx.Match()
}

main()
{
InitOnce();
Do1();
Do2();

...
}