• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            [原創]ATL正則表達式庫使用

            一.關鍵頭文件:
            #include <atlrx.h>
            vs2005自帶.

            VS 2008中由于將ALT項目的部分代碼剝離出去成為了獨立的開源項目,需要用到ALT中正則表達式等功能就需要手動下載。
            參考:http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=306398
            下載地址:http://www.codeplex.com/AtlServer
            把下載的東西解壓縮到一個目錄,比如c:\alt\
            在VS里面[工具]--[選項]--[項目和解決方案]--[VC++目錄],在右上角選擇[包含引用的文件]中加入c:\alt\include就OK了

            二.
            關于
            CAtlRegExp 及 GRETA      
            不支持   {m,n} 這樣的限定符
            而Boost支持

            三.
            還有一個值得注意的地方就是ATL中用大括號({})表示其子匹配
            子匹配Group從0開始.

            四.關鍵類及結構體:
            1、 CATLRegExp類
            聲明:
            template <class CharTraits=CAtlRECharTraits>
            class CAtlRegExp;
            2、 CAtlREMatchContext類
            聲明:
            template <class CharTraits=CAtlRECharTraits>
            class CAtlREMatchContext
            3.
            CAtlREMatchContext<>::MatchGroup

            //代碼1:這里請注意只用代碼環境為多字符集,非UNICODE.
            #include <iostream>
            #include 
            <afxwin.h>
            #include 
            <atlrx.h>
            using namespace std;

            int main(int argc, char* argv[]) {
                CAtlRegExp
            <> re;
                CAtlREMatchContext
            <> mc;

                
            const char* szIn = "98a76";
                
            char szMatch[128];
                memset(szMatch,
            '\0',128);
                re.Parse(
            "[0-9][0-9]");
                
            while(re.Match(szIn,&mc,&szIn)){
                    strncpy(szMatch,mc.m_Match.szStart, mc.m_Match.szEnd
            -mc.m_Match.szStart );
                    cout 
            << szMatch << endl;
                }
                
            return 0;
            }


            /*
            項目中,代碼我是這樣寫的.
                    CString strMatch;
            #ifdef _UNICODE
                    wcsncpy(strMatch.GetBuffer(mg.szEnd-mg.szStart),mg.szStart,mg.szEnd - mg.szStart);
            #else
                    strncpy(strMatch.GetBuffer(mg.szEnd-mg.szStart),mg.szStart,mg.szEnd - mg.szStart);
            #endif
                    strMatch.ReleaseBuffer();
            */




            用個MSDN上的代碼:
            http://msdn.microsoft.com/zh-cn/library/k3zs4axe(VS.80).aspx
            請注意子匹配Group 及CAtlREMatchContext<>類GetMatch()方法的使用.
            其他就不詳細講述了.
            // catlregexp_class.cpp
            #include <afx.h>
            #include 
            <atlrx.h>

            int main(int argc, char* argv[])
            {
                CAtlRegExp
            <> reUrl;
                
            // Five match groups: scheme, authority, path, query, fragment
                REParseError status = reUrl.Parse(
                    
            "({[^:/?#]+}:)?(//{[^/?#]*})?{[^?#]*}(?{[^#]*})?(#{.*})?" );

                
            if (REPARSE_ERROR_OK != status)
                {
                    
            // Unexpected error.
                    return 0;
                }

                CAtlREMatchContext
            <> mcUrl;
                
            if (!reUrl.Match(
            "http://search.microsoft.com/us/Search.asp?qu=atl&boolean=ALL#results",
                    
            &mcUrl))
                {
                    
            // Unexpected error.
                    return 0;
                }

                
            for (UINT nGroupIndex = 0; nGroupIndex < mcUrl.m_uNumGroups;
                     
            ++nGroupIndex)
                {
                    
            const CAtlREMatchContext<>::RECHAR* szStart = 0;
                    
            const CAtlREMatchContext<>::RECHAR* szEnd = 0;
                    mcUrl.GetMatch(nGroupIndex, 
            &szStart, &szEnd);

                    ptrdiff_t nLength 
            = szEnd - szStart;
                    printf_s(
            "%d: \"%.*s\"\n", nGroupIndex, nLength, szStart);
                }

                
            return 0;
            }


            posted on 2010-12-15 16:45 天下 閱讀(3101) 評論(1)  編輯 收藏 引用 所屬分類: Win32

            評論

            # re: [原創]ATL正則表達式庫使用 2011-02-28 15:01 cairuyun

            這個不錯哦 江西動漫網http://www.jxcomic.com/  回復  更多評論   

            <2010年12月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            亚洲伊人久久成综合人影院 | 久久久久人妻一区精品| 精品久久久久久国产牛牛app| 很黄很污的网站久久mimi色| 婷婷久久综合九色综合九七| 一本色道久久HEZYO无码| 俺来也俺去啦久久综合网| 久久亚洲精品视频| 污污内射久久一区二区欧美日韩 | 久久久久久a亚洲欧洲aⅴ| 久久国产三级无码一区二区| 国产欧美久久久精品影院| 国产精品久久久久久搜索| 久久精品国产精品亜洲毛片| 久久精品国产久精国产一老狼| 久久66热人妻偷产精品9| 久久亚洲高清综合| 久久婷婷五月综合国产尤物app| 久久久国产精华液| 狠狠色丁香婷婷综合久久来| 亚洲国产日韩欧美久久| 一级做a爰片久久毛片16| 人人狠狠综合久久88成人| 欧美久久久久久午夜精品| 99久久99久久| 久久精品99久久香蕉国产色戒| 亚洲欧洲久久久精品| 99久久人妻无码精品系列| 亚洲午夜久久久久久久久久| 亚洲а∨天堂久久精品| 国产高潮久久免费观看| 久久99热狠狠色精品一区| 久久香蕉国产线看观看精品yw| 国产免费久久精品99re丫y| 久久亚洲精品无码播放| 久久99精品国产麻豆婷婷| 久久99国产精品二区不卡| 精品亚洲综合久久中文字幕| 91视频国产91久久久| 久久综合久久自在自线精品自| 伊人久久大香线蕉av不卡|