龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC中使用SCRIPT 正则写的LRC歌词分析类

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
#include "StdAfx.h" #include ".lrcobject.h" #include comdef.h LRCOBJECT::LRCOBJECT(const char * text) : ar(_T("")) , by(_T("")) , al(_T("")) , ti(_T("")) , oTime(0) , isLrcFile(FALSE) { Text=text; steLrcTi(); } LRCOBJECT::LRCOBJECT(void) {

#include "StdAfx.h"
#include ".lrcobject.h"
#include   <comdef.h>

LRCOBJECT::LRCOBJECT(const char * text)
: ar(_T(""))
, by(_T(""))
, al(_T(""))
, ti(_T(""))
, oTime(0)

, isLrcFile(FALSE)
{
    Text=text;
    steLrcTi();
}

LRCOBJECT::LRCOBJECT(void)
{
}

LRCOBJECT::~LRCOBJECT(void)
{
    Release();
}
// //查找添加LRC标题

void LRCOBJECT::steLrcTi(void)
{
    CoInitialize(NULL);
    try{
        IRegExpPtr regExpPtr(__uuidof(RegExp));
        regExpPtr->PutGlobal(VARIANT_TRUE);
        regExpPtr->PutPattern("[ti:([^[]:]+)]");
        IMatchCollectionPtr matches = regExpPtr->Execute((const char * )Text); //Execute方法接受的是_bstr_t类型,因此要进行(const char * )转换
        ISubMatchesPtr pMatch;
        if(matches->GetCount() >0 )
        {
            //IMatch2Ptr类型才有GetSubMatches()方法,因此,要进行显式的类型转换
            pMatch=((IMatch2Ptr)matches->GetItem(0))->GetSubMatches();//SubMatches;
            //pMatch->GetItem(0)返回是_variant_t类型,_variant_t类型的属性bstrVal是BSTR类型
            ti= (pMatch->GetItem(0)).bstrVal;
        }
        //--------------------------------------------------
        regExpPtr->PutPattern("[ar:([^[]:]+)]");
        matches = regExpPtr->Execute((const char * )Text);
        if(matches->GetCount()>0)
        {
            pMatch=((IMatch2Ptr)matches->GetItem(0))->GetSubMatches();//SubMatches;
            ar= (pMatch->GetItem(0)).bstrVal;
        }
        //-----------------------------------------
        regExpPtr->PutPattern("[al:([^[]:]+)]");
        matches = regExpPtr->Execute((const char * )Text); //用指针要出错
        if(matches->GetCount()>0)
        {
            pMatch=((IMatch2Ptr)matches->GetItem(0))->GetSubMatches();//SubMatches;

精彩图集

赞助商链接