• <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>

            天下

            記錄修行的印記

            [原創(chuàng)]ATL正則表達(dá)式庫使用

            一.關(guān)鍵頭文件:
            #include <atlrx.h>
            vs2005自帶.

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

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

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

            四.關(guān)鍵類及結(jié)構(gòu)體:
            1、 CATLRegExp類
            聲明:
            template <class CharTraits=CAtlRECharTraits>
            class CAtlRegExp;
            2、 CAtlREMatchContext類
            聲明:
            template <class CharTraits=CAtlRECharTraits>
            class CAtlREMatchContext
            3.
            CAtlREMatchContext<>::MatchGroup

            //代碼1:這里請注意只用代碼環(huán)境為多字符集,非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()方法的使用.
            其他就不詳細(xì)講述了.
            // 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: [原創(chuàng)]ATL正則表達(dá)式庫使用 2011-02-28 15:01 cairuyun

            這個不錯哦 江西動漫網(wǎng)http://www.jxcomic.com/  回復(fù)  更多評論   

            <2010年11月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            久久久久精品国产亚洲AV无码 | 欧美一级久久久久久久大| 久久国产高潮流白浆免费观看| 一本久久a久久精品vr综合| 色欲久久久天天天综合网| 无码精品久久久久久人妻中字| 99国产精品久久| 午夜精品久久影院蜜桃| 国产一区二区精品久久 | 性高湖久久久久久久久AAAAA| 国产成人久久精品一区二区三区 | 久久99精品久久久久久水蜜桃| 久久精品无码一区二区app| 超级97碰碰碰碰久久久久最新 | 久久人人爽人人爽人人片AV麻烦| 久久婷婷成人综合色综合| 久久中文字幕一区二区| 国产精品中文久久久久久久| 狠狠色丁香久久综合五月| 亚洲va久久久久| 狠狠色综合久久久久尤物| 亚洲国产精品无码久久久秋霞2| 久久久久久无码国产精品中文字幕| 青草国产精品久久久久久| 久久精品国产欧美日韩99热| 国产精自产拍久久久久久蜜| 99久久婷婷国产综合亚洲| 亚洲精品无码久久久久去q | 久久久久久精品免费免费自慰| 精品国产婷婷久久久| 国产欧美一区二区久久| 久久久久久亚洲AV无码专区| 精品久久久久久久久免费影院| 久久中文精品无码中文字幕| 中文字幕一区二区三区久久网站| 亚洲AV无码1区2区久久| 狠狠色丁香婷婷久久综合| 国产精品亚洲综合久久| 久久久噜噜噜久久中文字幕色伊伊| 香蕉aa三级久久毛片| 久久AV高潮AV无码AV|