VC中使用SCRIPT 正则写的LRC歌词分析类
来源:互联网 发布:mysql不允许远程连接 编辑:程序博客网 时间:2024/04/18 14:24
#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;
al= (pMatch->GetItem(0)).bstrVal;
}
//---------------------
/*
短整型(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)
//{
//}
catch(...)
{
}
CoUninitialize();
//-----test
//CString t=delNotes((const char * )Text);
//LrcMadeList();
//::MessageBox(::GetTopWindow(::GetDesktopWindow()),GetText(), "URL CLIENT", MB_OK);
}
// //删除注释
CString LRCOBJECT::delNotes(const char* str)
{
CString m_reText;
//CoInitialize(NULL);
//-----------
try
{
IRegExpPtr regExpPtr(__uuidof(RegExp));
regExpPtr->PutGlobal(VARIANT_TRUE);
regExpPtr->PutPattern("/[/d+/:[/d/.]+/](.*)[/r/n]");
IMatchCollectionPtr matches = regExpPtr->Execute(str); //Execute方法接受的是_bstr_t类型,因此要进行(const char * )转换
//-------
IRegExpPtr IRegExpSubPtr(__uuidof(RegExp));
IRegExpSubPtr->PutGlobal(VARIANT_TRUE);
IRegExpSubPtr->PutPattern("/[/d+/:[/d/.]+/]");
IMatchCollectionPtr matches2;
//-----------------------
int m_Count=matches->GetCount();
int m_count2;
CString m_SubText;
if(m_Count>0)
{
for(int i=0;i<matches->GetCount();i++)
{
//IMatchPtr
m_SubText=(LPCTSTR)((IMatchPtr)matches->GetItem(i))->GetValue();
matches2=IRegExpSubPtr->Execute((const char *)m_SubText);
if((m_count2=matches2->GetCount())>0)
{
for(int j=0;j<m_count2;j++)
{
m_SubText.Replace((LPCTSTR)((IMatchPtr)matches2->GetItem(j))->GetValue(),"");
}
for(j=0;j<m_count2;j++)
{
m_reText+=(LPCTSTR)((IMatchPtr)matches2->GetItem(j))->GetValue()+m_SubText;
}
}
//::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_reText, "URL CLIENT", MB_OK);
}
}
IRegExpSubPtr=NULL;
matches=NULL;
matches2=NULL;
regExpPtr=NULL;
}
catch(...){};
//---------------------
//CoUninitialize();
return m_reText;
}
void LRCOBJECT::AddToList(const char * text)
{
//lrcBoxclassList
Release();
CString m_Text,m_strtmp;
lrcBox* pLrcBox;
float m_t,m_t2;
//CoInitialize(NULL);
CString debg,ttt;
try
{
IRegExpPtr regExpPtr(__uuidof(RegExp));
regExpPtr->PutGlobal(VARIANT_TRUE);
regExpPtr->PutPattern("/[([^:]+):([^/]]+)/](.*)[/r/n]");
IMatchCollectionPtr matches = regExpPtr->Execute(text);
int m_count=matches->GetCount();
ISubMatchesPtr pSubMatch;
if(m_count>0)
{
for(int i=0;i<m_count;i++)
{
pSubMatch=((IMatch2Ptr)matches->GetItem(i))->GetSubMatches();//SubMatches;
m_Text= (pSubMatch->GetItem(2)).bstrVal;
//::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_Text, "URL CLIENT", MB_OK);
m_t=float(atof((CString)(pSubMatch->GetItem(0)).bstrVal));
m_t2=float(atof((CString)(pSubMatch->GetItem(1)).bstrVal));
m_t=m_t*60 + m_t2;
pLrcBox=new lrcBox(m_t,m_Text);
//Length++;
lrcBoxclassList.AddTail(pLrcBox);
}
}
pSubMatch=NULL;
matches=NULL;
regExpPtr=NULL;
}
catch(...)
{
Release();
}
//-----------------------------
//-----------------------------
//CoUninitialize();
PaiXu();
}
void LRCOBJECT::PaiXu(void)
{
if(lrcBoxclassList.IsEmpty())
{
return;
}
bool biaoZhi=false;
lrcBox * tmp1,* tmp2,*tmp3;
//var tmp2;
int i,dangQian=(int)lrcBoxclassList.GetCount();
POSITION ps,ps2;
//---------------------
/*
CString m_text,tmp,tm;
int oo;
oo=0;
ps=lrcBoxclassList.GetHeadPosition();
while(ps != NULL)
{
tmp.Format("%d",++oo);
m_text+=tmp+" - "+((lrcBox *)lrcBoxclassList.GetNext(ps))->lrcText;
}
::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_text, "URL CLIENT", MB_OK);
*/
//----------------------------
do{
biaoZhi=0;//冒泡标志
for(i=0;i<(dangQian-1);i++){
ps= lrcBoxclassList.FindIndex(i);
ps2=lrcBoxclassList.FindIndex(i+1);
tmp1=(lrcBox*)lrcBoxclassList.GetAt(ps);
tmp2=(lrcBox*)lrcBoxclassList.GetAt(ps2);
if(tmp1->lrcTime >tmp2->lrcTime)
{//互换
tmp3=tmp1;
lrcBoxclassList.SetAt(ps,tmp2);
lrcBoxclassList.SetAt(ps2,tmp3);
biaoZhi=true;
}//if
}//for
}
while(biaoZhi);
//-------------------------------
/*
oo=0;
ps=lrcBoxclassList.GetHeadPosition();
m_text.Empty();
float uu;
while(ps != NULL)
{
tmp.Format("%d",++oo);
uu=((lrcBox *)lrcBoxclassList.GetAt(ps))->lrcTime;
tm.Format("%f",uu);
m_text+=tmp+" - " +tm+ " "+((lrcBox *)lrcBoxclassList.GetNext(ps))->lrcText;
}
::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_text, "URL CLIENT", MB_OK);
*/
}
void LRCOBJECT::LrcMadeList(void)
{
CoInitialize(NULL);
AddToList(delNotes((const char * )Text));
CoUninitialize();
}
CString LRCOBJECT::GetSoundText(void)
{
CString m_text;
if(!lrcBoxclassList.IsEmpty())
{
//lrcBox * tmp1;
POSITION pos=lrcBoxclassList.GetHeadPosition();
while(pos != NULL)
{
m_text+=((lrcBox *)lrcBoxclassList.GetNext(pos))->lrcText+" ";
}
}
return m_text;
}
void LRCOBJECT::Release(void)
{
if(lrcBoxclassList.IsEmpty())return;
int c=(int)lrcBoxclassList.GetCount();
lrcBox* pLrcBox;
for(int i=0;i<c;i++)
{
pLrcBox=lrcBoxclassList.RemoveTail();
delete pLrcBox;
}
}
#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;
al= (pMatch->GetItem(0)).bstrVal;
}
//---------------------
/*
短整型(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)
//{
//}
catch(...)
{
}
CoUninitialize();
//-----test
//CString t=delNotes((const char * )Text);
//LrcMadeList();
//::MessageBox(::GetTopWindow(::GetDesktopWindow()),GetText(), "URL CLIENT", MB_OK);
}
// //删除注释
CString LRCOBJECT::delNotes(const char* str)
{
CString m_reText;
//CoInitialize(NULL);
//-----------
try
{
IRegExpPtr regExpPtr(__uuidof(RegExp));
regExpPtr->PutGlobal(VARIANT_TRUE);
regExpPtr->PutPattern("/[/d+/:[/d/.]+/](.*)[/r/n]");
IMatchCollectionPtr matches = regExpPtr->Execute(str); //Execute方法接受的是_bstr_t类型,因此要进行(const char * )转换
//-------
IRegExpPtr IRegExpSubPtr(__uuidof(RegExp));
IRegExpSubPtr->PutGlobal(VARIANT_TRUE);
IRegExpSubPtr->PutPattern("/[/d+/:[/d/.]+/]");
IMatchCollectionPtr matches2;
//-----------------------
int m_Count=matches->GetCount();
int m_count2;
CString m_SubText;
if(m_Count>0)
{
for(int i=0;i<matches->GetCount();i++)
{
//IMatchPtr
m_SubText=(LPCTSTR)((IMatchPtr)matches->GetItem(i))->GetValue();
matches2=IRegExpSubPtr->Execute((const char *)m_SubText);
if((m_count2=matches2->GetCount())>0)
{
for(int j=0;j<m_count2;j++)
{
m_SubText.Replace((LPCTSTR)((IMatchPtr)matches2->GetItem(j))->GetValue(),"");
}
for(j=0;j<m_count2;j++)
{
m_reText+=(LPCTSTR)((IMatchPtr)matches2->GetItem(j))->GetValue()+m_SubText;
}
}
//::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_reText, "URL CLIENT", MB_OK);
}
}
IRegExpSubPtr=NULL;
matches=NULL;
matches2=NULL;
regExpPtr=NULL;
}
catch(...){};
//---------------------
//CoUninitialize();
return m_reText;
}
void LRCOBJECT::AddToList(const char * text)
{
//lrcBoxclassList
Release();
CString m_Text,m_strtmp;
lrcBox* pLrcBox;
float m_t,m_t2;
//CoInitialize(NULL);
CString debg,ttt;
try
{
IRegExpPtr regExpPtr(__uuidof(RegExp));
regExpPtr->PutGlobal(VARIANT_TRUE);
regExpPtr->PutPattern("/[([^:]+):([^/]]+)/](.*)[/r/n]");
IMatchCollectionPtr matches = regExpPtr->Execute(text);
int m_count=matches->GetCount();
ISubMatchesPtr pSubMatch;
if(m_count>0)
{
for(int i=0;i<m_count;i++)
{
pSubMatch=((IMatch2Ptr)matches->GetItem(i))->GetSubMatches();//SubMatches;
m_Text= (pSubMatch->GetItem(2)).bstrVal;
//::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_Text, "URL CLIENT", MB_OK);
m_t=float(atof((CString)(pSubMatch->GetItem(0)).bstrVal));
m_t2=float(atof((CString)(pSubMatch->GetItem(1)).bstrVal));
m_t=m_t*60 + m_t2;
pLrcBox=new lrcBox(m_t,m_Text);
//Length++;
lrcBoxclassList.AddTail(pLrcBox);
}
}
pSubMatch=NULL;
matches=NULL;
regExpPtr=NULL;
}
catch(...)
{
Release();
}
//-----------------------------
//-----------------------------
//CoUninitialize();
PaiXu();
}
void LRCOBJECT::PaiXu(void)
{
if(lrcBoxclassList.IsEmpty())
{
return;
}
bool biaoZhi=false;
lrcBox * tmp1,* tmp2,*tmp3;
//var tmp2;
int i,dangQian=(int)lrcBoxclassList.GetCount();
POSITION ps,ps2;
//---------------------
/*
CString m_text,tmp,tm;
int oo;
oo=0;
ps=lrcBoxclassList.GetHeadPosition();
while(ps != NULL)
{
tmp.Format("%d",++oo);
m_text+=tmp+" - "+((lrcBox *)lrcBoxclassList.GetNext(ps))->lrcText;
}
::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_text, "URL CLIENT", MB_OK);
*/
//----------------------------
do{
biaoZhi=0;//冒泡标志
for(i=0;i<(dangQian-1);i++){
ps= lrcBoxclassList.FindIndex(i);
ps2=lrcBoxclassList.FindIndex(i+1);
tmp1=(lrcBox*)lrcBoxclassList.GetAt(ps);
tmp2=(lrcBox*)lrcBoxclassList.GetAt(ps2);
if(tmp1->lrcTime >tmp2->lrcTime)
{//互换
tmp3=tmp1;
lrcBoxclassList.SetAt(ps,tmp2);
lrcBoxclassList.SetAt(ps2,tmp3);
biaoZhi=true;
}//if
}//for
}
while(biaoZhi);
//-------------------------------
/*
oo=0;
ps=lrcBoxclassList.GetHeadPosition();
m_text.Empty();
float uu;
while(ps != NULL)
{
tmp.Format("%d",++oo);
uu=((lrcBox *)lrcBoxclassList.GetAt(ps))->lrcTime;
tm.Format("%f",uu);
m_text+=tmp+" - " +tm+ " "+((lrcBox *)lrcBoxclassList.GetNext(ps))->lrcText;
}
::MessageBox(::GetTopWindow(::GetDesktopWindow()),m_text, "URL CLIENT", MB_OK);
*/
}
void LRCOBJECT::LrcMadeList(void)
{
CoInitialize(NULL);
AddToList(delNotes((const char * )Text));
CoUninitialize();
}
CString LRCOBJECT::GetSoundText(void)
{
CString m_text;
if(!lrcBoxclassList.IsEmpty())
{
//lrcBox * tmp1;
POSITION pos=lrcBoxclassList.GetHeadPosition();
while(pos != NULL)
{
m_text+=((lrcBox *)lrcBoxclassList.GetNext(pos))->lrcText+" ";
}
}
return m_text;
}
void LRCOBJECT::Release(void)
{
if(lrcBoxclassList.IsEmpty())return;
int c=(int)lrcBoxclassList.GetCount();
lrcBox* pLrcBox;
for(int i=0;i<c;i++)
{
pLrcBox=lrcBoxclassList.RemoveTail();
delete pLrcBox;
}
}
- VC中使用SCRIPT 正则写的LRC歌词分析类
- VC中使用SCRIPT 正则写的LRC歌词分析类
- 使用ActionScript3正则表达式分析LRC歌词
- VC++lrc歌词解析类
- LRC歌词分析函数
- LRC歌词分析函数
- VB2005使用类实现LRC歌词同步
- c# 操作Lrc歌词文件 的类
- C++ 分析歌词(LRC)文件
- C++中使用std::regex提取lrc歌词文件
- android中解析lrc歌词
- lrc歌词解析(正则表达式)与歌词卡拉ok显示的思路
- 歌词文件lrc的解析类(目前在WINCE下使用)
- 歌词同步的实现(lrc)
- Lrc歌词格式的简介
- LRC歌词分析函数增强版
- LRC歌词
- Script中使用的正则表达式摘要
- 银行自助设备详细介绍(四)——存款机
- 公司是技术人员还是市场人员更重要?
- 在login.sql文件中设置sql*plus的环境(摘自《Oracle编程艺术》)
- 智能设备 C#调用MFC DLL 传参值为汉字的解决方案 CString转存 unsigned char数组
- 北京信息工程学院、北京信息科技大学 软件工程课程设计全部代码,希望对北信的下一代有用!
- VC中使用SCRIPT 正则写的LRC歌词分析类
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- 摩羯
- 运算符++的奥秘
- 程序员
- 加密狗
- 60秒出口才
- 程序员真实写真35岁前成功的12条黄金法则.doc
- 好工作要坚持.doc