#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;
}
//---------------------
/*
短整型(int)
i = atoi(temp);
长整型(long)
l = atol(temp);
浮点(double)
d = atof(temp);
*/
regExpPtr-PutPattern("[offset:(-?d+)]");
matches = regExpPtr-Execute((const char * )Text); //用指针要出错
if(matches-GetCount()0)
{
pMatch=((IMatch2Ptr)matches-GetItem(0))-GetSubMatches();//SubMatches;
by= (pMatch-GetItem(0)).bstrVal;
try
{
oTime=float(atof(by));
}catch(...){};
}
//-----------------------------------------
regExpPtr-PutPattern("[by:([^[]:]+)]");
matches = regExpPtr-Execute((const char * )Text); //用指针要出错
if(matches-GetCount()0)
{
pMatch=((IMatch2Ptr)matches-GetItem(0))-GetSubMatches();//SubMatches;
by= (pMatch-GetItem(0)).bstrVal;
}
regExpPtr-PutPattern("[d+:[d.]+]");
matches = regExpPtr-Execute((const char * )Text); //用指针要出错
if(matches-GetCount()0)
{
isLrcFile=TRUE;
}
else
{
isLrcFile=FALSE;
}
pMatch=NULL;
matches=NULL;
regExpPtr=NULL;
//"[d+:[d.]+]"
}
//catch(_com_error& e)
//{
/