📄 strfilter.cpp
字号:
// StrFilterBase.cpp: implementation of the CStrFilter class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "StrFilter.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CStrFilter::CStrFilter()
{
}
CStrFilter::~CStrFilter()
{
}
const CStrFilter & CStrFilter::operator=(CStrFilter & str)
{
Format( "%s", str );
m_markID = m_markID;
m_reLeft = str.m_reLeft;
m_reRight= str.m_reRight;
m_markIDArray.Copy( str.m_markIDArray );
m_markStrArray.Copy( str.m_markStrArray );
return *this;
}
const CString & CStrFilter::operator=(CString & str)
{
Format( "%s", str );
return *this;
}
const CString & CStrFilter::operator = (const char * str)
{
Format( "%s", str );
return *this;
}
void CStrFilter::AddMark(const char * mark, UINT id)
{
m_markStrArray.Add( mark );
m_markIDArray.Add( id );
}
void CStrFilter::RemoveAllMark()
{
m_markStrArray.RemoveAll();
m_markIDArray.RemoveAll();
}
BOOL CStrFilter::Separate()
{
int i;
int size = m_markStrArray.GetSize();
for( i = 0; i < size; i++ )
{
if( Separate( m_markStrArray[i] ) )
{//已找到标志并成功分离出字串
m_markID = m_markIDArray[i];
return TRUE;
}
}
return FALSE;
}
BOOL CStrFilter::Separate(char mark)
{
int i;
i = Find( mark );
if( i < 0 )
{
return FALSE;
}
if( i == 0 )
{
m_reLeft.Empty();
}
else
{
m_reLeft = Left( i );
}
i = GetLength() - i - 1;
if( i <= 0 )
{
m_reRight.Empty();
}
else
{
m_reRight = Right( i );
}
return TRUE;
}
BOOL CStrFilter::Separate(const char * mark)
{
int i;
i = Find( mark );
if( i < 0 )
{
return FALSE;
}
if( i == 0 )
{
m_reLeft.Empty();
}
else
{
m_reLeft = Left( i );
}
i = GetLength() - i - strlen( mark );
if( i <= 0 )
{
m_reRight.Empty();
}
else
{
m_reRight = Right( i );
}
return TRUE;
}
BOOL CStrFilter::SeparateAll(char mark, CStringArray & strArray)
{
BOOL re = FALSE;
while( Separate( mark ) )
{
if( !m_reLeft.IsEmpty() )
{
strArray.Add( m_reLeft );
}
*this = m_reRight;
re = TRUE;
}
if( !m_reRight.IsEmpty() )
{
strArray.Add( m_reRight );
}
return re;
}
BOOL CStrFilter::SeparateAll( const char * mark, CStringArray & strArray)
{
BOOL re = FALSE;
while( Separate( mark ) )
{
if( !m_reLeft.IsEmpty() )
{
strArray.Add( m_reLeft );
}
*this = m_reRight;
re = TRUE;
}
if( !m_reRight.IsEmpty() )
{
strArray.Add( m_reRight );
}
return re;
}
//过滤%AA形式的HEX字符,指接在str中修改
BOOL CStrFilter::ConvertURLHex()
{
char * str = GetBuffer( GetLength() );//取得本字串的地址
//pS0:源串指针 pS1:新串指针
char * pS0, *pS1;
char hex1, hex2;
int re = 0;
int i;
pS0 = pS1 = str;
while( 1 )
{
//复制非HEX编码的字串,直到碰到% or 0,跳出循环后pS0指向% or 0
for( i = 0; ; i++ )
{
if( pS0[i] == '%' || pS0[i] == '\0' )
{
if( i > 0 )
{
memcpy( pS1, pS0, i );
pS0 += i;
pS1 += i;
}
break;
}
}
if( *pS0 == '\0' )
{
break;
}
//此时pS0指向形如%AA的HEX编码
pS0++; //使pS0指向第一个HEX编码
hex1 = *(pS0++); //第一个HEX
hex2 = *(pS0++); //第二个HEX
if( hex1 >= '0' && hex1 <= '9' )
{
hex1 = hex1 - '0';
}
else
{//字符
hex1 &= ~0x20;//强制为大写
if( hex1 >= 'A' && hex1 <= 'F' )
{
hex1 = (hex1 - 'A') + 10;
}
else
{//错误编码的标志
hex1 = 17;
}
}
if( hex2 >= '0' && hex2 <= '9' )
{
hex2 = hex2 - '0';
}
else
{
hex2 &= ~0x20;//强制为大写
if( hex2 >= 'A' && hex2 <= 'F' )
{
hex2 = (hex2 - 'A') + 10;
}
else
{//错误编码的标志
hex2 = 17;
}
}
if( hex1 == 17 || hex2 == 17 )
{//非法编码,设置返回标志,原样复制
re = 1;
memcpy( pS1, pS0-3, 3 );
pS1 += 3;
}
else
{//解码HEX
*(pS1++) = (hex1<<4) + hex2;
}
}
*(pS1) = '\0';
ReleaseBuffer();
return (re == 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -