Use regular expressions in ATL

Source: Internet
Author: User

The ATL is encapsulated once, so you do not need to write tedious calls every time.

 

Bool matchRegExp (const CString & strTag, const CString & strPattern, std: vector <CString> & rer)
...{
Rer. clear ();
Bool bRet = false;
ATL: CAtlRegExp <> regex;
ATL: REParseError status = regex. Parse (strPattern );
If (REPARSE_ERROR_ OK = status)
...{
CAtlREMatchContext <> mc;
Const CAtlRegExp <>:: RECHAR * pCon = strTag;
Std: vector <CString> record;
While (RegEx. Match (pcon, & Mc, & pcon ))
...{
Record. Clear ();
Record. Reserve (MC. m_unumgroups );
For (uint ngroupindex = 0; ngroupindex <MC. m_unumgroups;
++ Ngroupindex)
...{
Const catlrematchcontext <>:: RECHAR * szstart = 0;
Const CAtlREMatchContext <>:: RECHAR * szEnd = 0;
Mc. GetMatch (nGroupIndex, & szStart, & szEnd );

Ptrdiff_t nLength = szEnd-szStart;
TCHAR * strMatch = new TCHAR [nLength + 1];
StrMatch [nLength] = 0;
_ Tcsncpy (strMatch, szStart, nLength );

Record. push_back (strMatch );
Delete [] strMatch;
}
Rer. push_back (record );
If (pCon-strTag> = strTag. GetLength () // seems there is a bug in catlregexp library, I have to check this by myself.
Break;
}
}
Return RER. Size ()! = 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.