Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginFilter.cpp

Issue 5750789393874944: [IE] First round of ATL removal (Closed)
Patch Set: Created June 20, 2014, 9:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/plugin/PluginFilter.cpp
===================================================================
--- a/src/plugin/PluginFilter.cpp
+++ b/src/plugin/PluginFilter.cpp
@@ -13,6 +13,8 @@
#include "PluginSystem.h"
#include "PluginClass.h"
#include "mlang.h"
+#include "PluginUtil.h"
+#include "COM_Client.h"
#include "..\shared\CriticalSection.h"
@@ -25,7 +27,8 @@
// CFilterElementHideAttrSelector
// ============================================================================
-CFilterElementHideAttrSelector::CFilterElementHideAttrSelector() : m_type(TYPE_NONE), m_pos(POS_NONE), m_bstrAttr(NULL)
+CFilterElementHideAttrSelector::CFilterElementHideAttrSelector()
+ : m_type(TYPE_NONE), m_pos(POS_NONE)
{
}
@@ -33,7 +36,7 @@
{
m_type = filter.m_type;
m_pos = filter.m_pos;
- m_bstrAttr = filter.m_bstrAttr;
+ m_attr_name = filter.m_attr_name;
m_value = filter.m_value;
}
@@ -47,139 +50,159 @@
// CFilterElementHide
// ============================================================================
-CFilterElementHide::CFilterElementHide(const CString& filterText) : m_filterText(filterText), m_type(ETraverserComplexType::TRAVERSER_TYPE_ERROR)
+CFilterElementHide::CFilterElementHide(const std::wstring & filterText)
+ : m_filterText(filterText), m_type(ETraverserComplexType::TRAVERSER_TYPE_ERROR)
{
// Find tag name, class or any (*)
- CString filterString = filterText;
+ std::wstring filter( filterText );
- TCHAR firstTag = filterString.GetAt(0);
+ wchar_t first_char = filterText[0];
// Any tag
- if (firstTag == '*')
+ if (first_char == L'*')
{
- filterString = filterString.Mid(1);
+ filter.erase( 0, 1 );
}
// Any tag (implicitely)
- else if (firstTag == '[' || firstTag == '.' || firstTag == '#')
+ else if (first_char == L'[' || first_char == L'.' || first_char == L'#')
{
}
// Real tag
- else if (isalnum(firstTag))
+ else if (isalnum(first_char))
{
//TODO: Add support for descendant selectors
- int pos = filterString.FindOneOf(L".#[(");
-
- if (pos < 0)
- pos = filterString.GetLength();
- m_tag = filterString.Left(pos).MakeLower();
-
- filterString = filterString.Mid(pos);
+ size_t pos = filter.find_first_of( L".#[(" );
+ if ( pos == std::wstring::npos )
+ {
+ m_tag = filter;
+ filter = L"";
+ }
+ else
+ {
+ m_tag = filter.substr( 0, pos );
+ filter.erase( 0, pos );
+ }
+ ABP::util::to_lower( m_tag );
}
// Error
else
{
DEBUG_FILTER("Filter::Error parsing selector:" + filterText + " (invalid tag)");
- throw std::runtime_error(CStringA("Filter::Error parsing selector:" + filterText + " (invalid tag)").GetString());
+ throw std::runtime_error( "Filter::Error parsing selector:" + ABP::debug::narrow( filterText ) + " (invalid tag)" );
}
// Find Id and class name
- if (!filterString.IsEmpty())
+ if ( !filter.empty() )
{
- TCHAR firstId = filterString.GetAt(0);
+ first_char = filter[0];
// Id
- if (firstId == '#')
+ if (first_char == L'#')
{
- int pos = filterString.Find('[');
- if (pos < 0)
+ filter.erase( 0, 1 );
+ size_t pos = filter.find( L'[' );
+ if ( pos == std::wstring::npos )
{
- pos = filterString.GetLength();
+ m_tagId = filter;
+ filter = L"";
}
- m_tagId = filterString.Mid(1, pos - 1);
- filterString = filterString.Mid(pos);
- pos = m_tagId.Find(L".");
- if (pos > 0)
+ else
{
- m_tagClassName = m_tagId.Mid(pos + 1);
- m_tagId = m_tagId.Left(pos);
+ m_tagId = filter.substr( 0, pos );
+ filter = filter.erase( 0, pos );
+ pos = m_tagId.find( L"." );
+ if ( pos != std::wstring::npos )
+ {
+ m_tagClassName = m_tagId.substr( pos + 1 );
+ m_tagId = m_tagId.erase( pos );
+ }
}
}
// Class name
- else if (firstId == '.')
+ else if (first_char == L'.')
{
- int pos = filterString.Find('[');
- if (pos < 0)
+ filter.erase( 0, 1 );
+ size_t pos = filter.find( L'[' );
+ if ( pos == std::wstring::npos )
{
- pos = filterString.GetLength();
+ m_tagClassName = filter;
+ filter = L"";
}
- m_tagClassName = filterString.Mid(1, pos - 1);
- filterString = filterString.Mid(pos);
+ else
+ {
+ m_tagClassName = filter.substr( 0, pos );
+ filter = filter.erase( 0, pos );
+ }
}
}
- char chAttrStart = '[';
- char chAttrEnd = ']';
+ while ( !filter.empty() )
+ {
+ if ( filter[0] != L'[' )
+ {
+ DEBUG_FILTER( L"Filter::Error parsing selector:" + filterText + L" (more data)" );
+ throw std::runtime_error( "Filter::Error parsing selector:" + ABP::debug::narrow( filterText ) + " (more data)" );
+ }
+ size_t pos = filter.find( L']' ) ;
+ if ( pos == std::wstring::npos )
+ {
+ DEBUG_FILTER( L"Filter::Error parsing selector:" + filterText + L" (more data)" );
+ throw std::runtime_error( "Filter::Error parsing selector:" + ABP::debug::narrow( filterText ) + " (more data)" );
+ }
- while (!filterString.IsEmpty())
- {
- if (filterString.GetAt(0) != chAttrStart)
- {
- DEBUG_FILTER("Filter::Error parsing selector:" + filterText + " (more data)");
- throw std::runtime_error(CStringA("Filter::Error parsing selector:" + filterText + " (more data)").GetString());
- }
- int endPos = filterString.Find(']') ;
- if (endPos < 0)
- {
- DEBUG_FILTER("Filter::Error parsing selector:" + filterText + " (more data)");
- throw std::runtime_error(CStringA("Filter::Error parsing selector:" + filterText + " (more data)").GetString());
- }
-
CFilterElementHideAttrSelector attrSelector;
- CString arg = filterString.Mid(1, endPos - 1);
- filterString = filterString.Mid(endPos + 1);
+ std::wstring arg = filter.substr( 1, pos - 1 );
+ filter.erase( 0, pos + 1 );
- int delimiterPos = arg.Find('=');
- if (delimiterPos > 0)
+ size_t delimiterPos = arg.find( '=' );
+ if ( delimiterPos != std::wstring::npos )
{
- attrSelector.m_value = arg.Mid(delimiterPos + 1);
- if (attrSelector.m_value.GetLength() >= 2 && attrSelector.m_value.GetAt(0) == '\"' && attrSelector.m_value.GetAt(attrSelector.m_value.GetLength() - 1) == '\"')
+ attrSelector.m_value = arg.substr( delimiterPos + 1 );
+ if (attrSelector.m_value.length() >= 2 && attrSelector.m_value[0] == L'\"' && attrSelector.m_value[attrSelector.m_value.length() - 1] == L'\"')
{
- attrSelector.m_value = attrSelector.m_value.Mid(1, attrSelector.m_value.GetLength() - 2);
+ attrSelector.m_value = attrSelector.m_value.substr(1, attrSelector.m_value.length() - 2);
}
- if (arg.GetAt(delimiterPos - 1) == '^')
+ /*
+ * Parse the type of match for an attribute selector.
+ *
+ * Support of standard exact match (no match type character)
+ * Support for IE-specific match types prefix (^), substring (*), and suffix ($)
+ * No support for standard space-separated list (~) or hyphen (|)
+ */
+ wchar_t match_type = arg[ delimiterPos - 1 ];
+ if ( match_type == L'^' )
{
- attrSelector.m_bstrAttr = arg.Left(delimiterPos - 1);
+ attrSelector.m_attr_name = arg.substr( 0, delimiterPos - 1 );
attrSelector.m_pos = CFilterElementHideAttrPos::STARTING;
}
- else if (arg.GetAt(delimiterPos - 1) == '*')
+ else if ( match_type == L'*' )
{
- attrSelector.m_bstrAttr = arg.Left(delimiterPos - 1);
+ attrSelector.m_attr_name = arg.substr( 0, delimiterPos - 1 );
attrSelector.m_pos = CFilterElementHideAttrPos::ANYWHERE;
}
- else if (arg.GetAt(delimiterPos - 1) == '$')
+ else if ( match_type == L'$' )
{
- attrSelector.m_bstrAttr = arg.Left(delimiterPos - 1);
+ attrSelector.m_attr_name = arg.substr( 0, delimiterPos - 1 );
attrSelector.m_pos = CFilterElementHideAttrPos::ENDING;
}
else
{
- attrSelector.m_bstrAttr = arg.Left(delimiterPos);
+ attrSelector.m_attr_name = arg.substr( 0, delimiterPos );
attrSelector.m_pos = CFilterElementHideAttrPos::EXACT;
}
}
- CString tag = attrSelector.m_bstrAttr;
- if (tag == "style")
+ if ( attrSelector.m_attr_name == L"style" )
{
attrSelector.m_type = CFilterElementHideAttrType::STYLE;
- attrSelector.m_value.MakeLower();
+ ABP::util::to_lower( attrSelector.m_value );
}
- else if (tag == "id")
+ else if ( attrSelector.m_attr_name == L"id" )
{
attrSelector.m_type = CFilterElementHideAttrType::ID;
}
- else if (tag == "class")
+ else if ( attrSelector.m_attr_name == L"class" )
{
attrSelector.m_type = CFilterElementHideAttrType::CLASS;
}
@@ -188,10 +211,10 @@
}
// End check
- if (!filterString.IsEmpty())
+ if ( !filter.empty() )
{
DEBUG_FILTER("Filter::Error parsing selector:" + filterFile + "/" + filterText + " (more data)")
- throw new std::runtime_error(CStringA("Filter::Error parsing selector:" + filterText + " (more data)").GetString());
+ throw new std::runtime_error( "Filter::Error parsing selector:" + ABP::debug::narrow( filterText ) + " (more data)" );
}
}
@@ -238,31 +261,28 @@
bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const
{
- HRESULT hr;
+ Wrapper::HTML_Element element( pEl );
- if (!m_tagId.IsEmpty())
+ if (!m_tagId.empty())
{
- CComBSTR id;
- hr = pEl->get_id(&id);
- if ((hr != S_OK) || (id != CComBSTR(m_tagId)))
+ std::wstring id;
+ if ( !element.id( id ) || !id.empty() )
{
return false;
}
}
- if (!m_tagClassName.IsEmpty())
+ if (!m_tagClassName.empty())
{
- CComBSTR classNameBSTR;
- hr = pEl->get_className(&classNameBSTR);
- if (hr == S_OK)
+ std::wstring class_names;
+ if ( element.class_name( class_names ) )
{
- CString className = classNameBSTR;
- int start = 0;
- CString specificClass;
+ size_t start = 0;
+ std::wstring specific_class;
bool foundMatch = false;
- while ((specificClass = className.Tokenize(L" ", start)) != L"")
+ while ((specific_class = ABP::util::extract_token( class_names, start, L" ")) != L"")
{
// TODO: Consider case of multiple classes. (m_tagClassName can be something like "foo.bar")
- if (specificClass == m_tagClassName)
+ if (specific_class == m_tagClassName)
{
foundMatch = true;
}
@@ -273,12 +293,10 @@
}
}
}
- if (!m_tag.IsEmpty())
+ if (!m_tag.empty())
{
- CComBSTR tagName;
- tagName.ToLower();
- hr = pEl->get_tagName(&tagName);
- if ((hr != S_OK) || (tagName != CComBSTR(m_tag)))
+ std::wstring tag_name;
+ if ( ! element.tag_name( tag_name ) || tag_name != m_tag )
{
return false;
}
@@ -288,56 +306,38 @@
for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_attributeSelectors.begin();
attrIt != m_attributeSelectors.end(); ++ attrIt)
{
- CString value;
+ std::wstring value;
bool attrFound = false;
if (attrIt->m_type == CFilterElementHideAttrType::STYLE)
{
CComPtr<IHTMLStyle> pStyle;
if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
{
- CComBSTR bstrStyle;
-
- if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle)
+ Wrapper::HTML_Style style( pStyle );
+ if ( style.CSS_text( value ) && !value.empty() )
{
- value = bstrStyle;
- value.MakeLower();
+ ABP::util::to_lower( value );
attrFound = true;
}
}
}
else if (attrIt->m_type == CFilterElementHideAttrType::CLASS)
{
- CComBSTR bstrClassNames;
- if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames)
+ if ( element.class_name( value ) && !value.empty() )
{
- value = bstrClassNames;
attrFound = true;
}
}
else if (attrIt->m_type == CFilterElementHideAttrType::ID)
{
- CComBSTR bstrId;
- if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
+ if ( element.id( value ) && !value.empty() )
{
- value = bstrId;
attrFound = true;
}
}
else
{
Eric 2014/08/05 17:00:38 The old way. Explicit type conversions, and you ha
- CComVariant vAttr;
- if (SUCCEEDED(pEl->getAttribute(attrIt->m_bstrAttr, 0, &vAttr)))
- {
- attrFound = true;
- if (vAttr.vt == VT_BSTR)
- {
- value = vAttr.bstrVal;
- }
- else if (vAttr.vt == VT_I4)
- {
- value.Format(L"%u", vAttr.iVal);
- }
- }
+ attrFound = element.attribute( attrIt->m_attr_name, value );
}
if (attrFound)
@@ -350,20 +350,35 @@
}
else if (attrIt->m_pos == CFilterElementHideAttrPos::STARTING)
{
- if (value.Left(attrIt->m_value.GetLength()) != attrIt->m_value)
+ if ( !ABP::util::begins_with( value, attrIt->m_value ) )
+ {
return false;
+ }
}
else if (attrIt->m_pos == CFilterElementHideAttrPos::ENDING)
{
- if (value.Right(attrIt->m_value.GetLength()) != attrIt->m_value)
+ size_t match_length = attrIt->m_value.length();
+ size_t value_length = value.length();
+ // If the length of the value is less than that of the target match string, there can't possibly be a match.
+ if ( value_length < match_length )
+ {
return false;
+ }
+ // Assert value_length >= match_length
+ // Assert value_length - match_length >= 0
+ if ( value.compare( value_length - match_length, match_length, attrIt->m_value ) != 0 )
+ {
+ return false;
+ }
}
else if (attrIt->m_pos == CFilterElementHideAttrPos::ANYWHERE)
{
- if (value.Find(attrIt->m_value) < 0)
+ if ( value.find( attrIt->m_value) == std::wstring::npos )
+ {
return false;
+ }
}
- else if (attrIt->m_value.IsEmpty())
+ else if (attrIt->m_value.empty())
{
return true;
}
@@ -420,54 +435,52 @@
// CPluginFilter
// ============================================================================
-CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath)
+CPluginFilter::CPluginFilter()
{
- m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT";
- m_contentMapText[CFilter::contentTypeObject] = "OBJECT";
- m_contentMapText[CFilter::contentTypeImage] = "IMAGE";
- m_contentMapText[CFilter::contentTypeScript] = "SCRIPT";
- m_contentMapText[CFilter::contentTypeOther] = "OTHER";
- m_contentMapText[CFilter::contentTypeUnknown] = "OTHER";
- m_contentMapText[CFilter::contentTypeSubdocument] = "SUBDOCUMENT";
- m_contentMapText[CFilter::contentTypeStyleSheet] = "STYLESHEET";
- m_contentMapText[CFilter::contentTypeXmlHttpRequest] = "XMLHTTPREQUEST";
+ m_contentMapText[CFilter::contentTypeDocument] = L"DOCUMENT";
+ m_contentMapText[CFilter::contentTypeObject] = L"OBJECT";
+ m_contentMapText[CFilter::contentTypeImage] = L"IMAGE";
+ m_contentMapText[CFilter::contentTypeScript] = L"SCRIPT";
+ m_contentMapText[CFilter::contentTypeOther] = L"OTHER";
+ m_contentMapText[CFilter::contentTypeUnknown] = L"OTHER";
+ m_contentMapText[CFilter::contentTypeSubdocument] = L"SUBDOCUMENT";
+ m_contentMapText[CFilter::contentTypeStyleSheet] = L"STYLESHEET";
+ m_contentMapText[CFilter::contentTypeXmlHttpRequest] = L"XMLHTTPREQUEST";
ClearFilters();
}
-bool CPluginFilter::AddFilterElementHide(CString filterText)
+bool CPluginFilter::AddFilterElementHide( std::wstring filterText )
{
+ std::wstring filter_text = filterText;
-
- DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile);
+ DEBUG_FILTER( L"Input: " + filterText + L" filterFile" + filterFile );
CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
-
- CString filterString = filterText;
// Create filter descriptor
std::auto_ptr<CFilterElementHide> filter;
- CString wholeFilterString = filterString;
- TCHAR separatorChar;
+ wchar_t separatorChar;
do
{
- int chunkEnd = filterText.FindOneOf(L"+>");
- if (chunkEnd > 0)
+ size_t separator_pos = filter_text.find_first_of( L"+>" );
+ if ( separator_pos != std::wstring::npos )
{
- separatorChar = filterText.GetAt(chunkEnd);
+ separatorChar = filter_text[ separator_pos ];
}
else
{
- chunkEnd = filterText.GetLength();
+ separator_pos = filter_text.length();
separatorChar = L'\0';
}
- CString filterChunk = filterText.Left(chunkEnd).TrimRight();
+ std::wstring filter_chunk = filter_text.substr( 0, separator_pos );
+ ABP::util::trim_trailing( filter_chunk );
+
std::auto_ptr<CFilterElementHide> filterParent(filter);
-
- filter.reset(new CFilterElementHide(filterChunk));
+ filter.reset( new CFilterElementHide( filter_chunk ) );
if (filterParent.get() != 0)
{
@@ -476,7 +489,9 @@
if (separatorChar != L'\0') // complex selector
{
- filterText = filterText.Mid(chunkEnd + 1).TrimLeft();
+ filter_text.erase( 0, separator_pos + 1 );
+ ABP::util::trim_leading( filter_text );
+
if (separatorChar == '+')
filter->m_type = CFilterElementHide::TRAVERSER_TYPE_IMMEDIATE;
else if (separatorChar == '>')
@@ -484,17 +499,17 @@
}
else // Terminating element (simple selector)
{
- if (!filter->m_tagId.IsEmpty())
+ if (!filter->m_tagId.empty())
{
m_elementHideTagsId.insert(std::make_pair(std::make_pair(filter->m_tag, filter->m_tagId), *filter));
}
- else if (!filter->m_tagClassName.IsEmpty())
+ else if (!filter->m_tagClassName.empty())
{
m_elementHideTagsClass.insert(std::make_pair(std::make_pair(filter->m_tag, filter->m_tagClassName), *filter));
}
else
{
- std::pair<CString, CFilterElementHide> pair = std::make_pair(filter->m_tag, *filter);
+ std::pair< std::wstring, CFilterElementHide> pair = std::make_pair(filter->m_tag, *filter);
m_elementHideTags.insert(pair);
}
}
@@ -504,28 +519,19 @@
return true;
}
-bool CPluginFilter::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent) const
+bool CPluginFilter::IsElementHidden(const std::wstring & tag, IHTMLElement* pEl, const std::wstring & domain, const std::wstring & indent) const
{
- CString id;
- CComBSTR bstrId;
- if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
- {
- id = bstrId;
- }
+ Wrapper::HTML_Element element( pEl );
+ std::wstring id;
+ element.id( id );
- CString classNames;
- CComBSTR bstrClassNames;
- if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames)
- {
- classNames = bstrClassNames;
- }
+ std::wstring class_names;
+ element.class_name( class_names );
CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
- CString domainTest = domain;
-
// Search tag/id filters
- if (!id.IsEmpty())
+ if (!id.empty())
{
std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideTagsNamed::const_iterator> idItEnum =
m_elementHideTagsId.equal_range(std::make_pair(tag, id));
@@ -535,21 +541,21 @@
{
#ifdef ENABLE_DEBUG_RESULT
DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second.m_filterText)
- CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filterText);
+ CPluginDebug::DebugResultHiding(tag, std::wstring( L"id:" ) + id, idIt->second.m_filterText);
#endif
return true;
}
}
// Search general id
- idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id));
+ idItEnum = m_elementHideTagsId.equal_range(std::make_pair(L"", id));
for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; idIt != idItEnum.second; idIt ++)
{
if (idIt->second.IsMatchFilterElementHide(pEl))
{
#ifdef ENABLE_DEBUG_RESULT
DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m_filterText)
- CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filterText);
+ CPluginDebug::DebugResultHiding(tag, std::wstring( L"id:" ) + id, idIt->second.m_filterText);
#endif
return true;
}
@@ -557,14 +563,14 @@
}
// Search tag/className filters
- if (!classNames.IsEmpty())
+ if ( !class_names.empty() )
{
- int pos = 0;
- CString className = classNames.Tokenize(L" \t\n\r", pos);
- while (pos >= 0)
+ size_t class_names_pos = 0;
+ std::wstring class_name = ABP::util::extract_token( class_names, class_names_pos, L" \t\n\r" );
+ while ( !class_name.empty() )
{
std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideTagsNamed::const_iterator> classItEnum =
- m_elementHideTagsClass.equal_range(std::make_pair(tag, className));
+ m_elementHideTagsClass.equal_range( std::make_pair( tag, class_name ) );
for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.first; classIt != classItEnum.second; ++classIt)
{
@@ -572,28 +578,28 @@
{
#ifdef ENABLE_DEBUG_RESULT
DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt->second.m_filterText)
- CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt->second.m_filterText);
+ CPluginDebug::DebugResultHiding(tag, std::wstring( L"class:" ) + class_name, classIt->second.m_filterText);
#endif
return true;
}
}
// Search general class name
- classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", className));
+ classItEnum = m_elementHideTagsClass.equal_range(std::make_pair(L"", class_name));
for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.first; classIt != classItEnum.second; ++ classIt)
{
if (classIt->second.IsMatchFilterElementHide(pEl))
{
#ifdef ENABLE_DEBUG_RESULT
DEBUG_HIDE_EL(indent + "HideEl::Found (?/class) filter:" + classIt->second.m_filterText)
- CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt->second.m_filterText);
+ CPluginDebug::DebugResultHiding(tag, std::wstring( L"class:" ) + class_name, classIt->second.m_filterText);
#endif
return true;
}
}
// Next class name
- className = classNames.Tokenize(L" \t\n\r", pos);
+ class_name = ABP::util::extract_token( class_names, class_names_pos, L" \t\n\r" );
}
}
@@ -606,7 +612,7 @@
{
#ifdef ENABLE_DEBUG_RESULT
DEBUG_HIDE_EL(indent + "HideEl::Found (tag) filter:" + tagIt->second.m_filterText)
- CPluginDebug::DebugResultHiding(tag, "-", tagIt->second.m_filterText);
+ CPluginDebug::DebugResultHiding(tag, L"-", tagIt->second.m_filterText);
#endif
return true;
}
@@ -634,9 +640,10 @@
{
for (std::vector<std::wstring>::iterator it = filters.begin(); it < filters.end(); ++it)
{
- CString filter((*it).c_str());
+ std::wstring filter( *it );
+ ABP::util::trim( filter );
// If the line is not commented out
- if (!filter.Trim().IsEmpty() && filter.GetAt(0) != '!' && filter.GetAt(0) != '[')
+ if ( !filter.empty() && filter[0] != '!' && filter[0] != '[')
{
int filterType = 0;
@@ -644,7 +651,7 @@
try
{
- AddFilterElementHide(filter);
+ AddFilterElementHide( filter );
}
catch(...)
{
@@ -679,23 +686,24 @@
}
}
-bool CPluginFilter::ShouldBlock(CString src, int contentType, const CString& domain, bool addDebug) const
+bool CPluginFilter::ShouldBlock( std::wstring src, int contentType, const std::wstring & domain, bool addDebug) const
{
// We should not block the empty string, so all filtering does not make sense
// Therefore we just return
- if (src.Trim().IsEmpty())
+ ABP::util::trim( src );
+ if (src.empty())
{
return false;
}
CPluginSettings* settings = CPluginSettings::GetInstance();
- CString type;
+ std::wstring type;
if (addDebug)
{
- type = "OTHER";
+ type = L"OTHER";
- std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType);
+ std::map< int, std::wstring >::const_iterator it = m_contentMapText.find(contentType);
if (it != m_contentMapText.end())
{
type = it->second;
@@ -703,14 +711,14 @@
}
CPluginClient* client = CPluginClient::GetInstance();
- if (client->Matches(std::wstring(src), std::wstring(type), std::wstring(domain)))
+ if (client->Matches(std::wstring(src), type, std::wstring(domain)))
{
if (addDebug)
{
- DEBUG_FILTER("Filter::ShouldBlock " + type + " YES")
+ DEBUG_FILTER( L"Filter::ShouldBlock " + type + L" YES" )
#ifdef ENABLE_DEBUG_RESULT
- CPluginDebug::DebugResultBlocking(type, src, domain);
+ CPluginDebug::DebugResultBlocking( type, src, domain);
#endif
}
return true;

Powered by Google App Engine
This is Rietveld