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

Side by Side Diff: shell/src/FiltersCommand.cpp

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Addressed review comments Created April 8, 2013, 1:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <iostream> 1 #include <iostream>
2 #include <sstream> 2 #include <sstream>
3 3
4 #include "FiltersCommand.h" 4 #include "FiltersCommand.h"
5 5
6 namespace 6 namespace
7 { 7 {
8 typedef std::vector<AdblockPlus::Filter*> FilterList; 8 typedef std::vector<AdblockPlus::FilterPtr> FilterList;
9 9
10 void ShowFilterList(const FilterList& filters) 10 void ShowFilterList(const FilterList& filters)
11 { 11 {
12 for (FilterList::const_iterator it = filters.begin(); 12 for (FilterList::const_iterator it = filters.begin();
13 it != filters.end(); it++) 13 it != filters.end(); it++)
14 { 14 {
15 std::string type;
16 switch ((*it)->GetProperty("type", -1))
17 {
18 case AdblockPlus::BLOCKING_RULE:
19 type = "blocking";
20 break;
21 case AdblockPlus::EXCEPTION_RULE:
22 type = "exception";
23 break;
24 case AdblockPlus::ELEMHIDE_RULE:
25 type = "elemhide";
26 break;
27 case AdblockPlus::ELEMHIDE_EXCEPTION_RULE:
28 type = "elemhideexception";
29 break;
30 case AdblockPlus::COMMENT_RULE:
31 type = "comment";
32 break;
33 case AdblockPlus::INVALID_RULE:
34 type = "invalid";
35 break;
36 default:
37 type = "(unknown type)";
38 break;
39 }
15 std::cout << (*it)->GetProperty("text", "(no text)") << " - " << 40 std::cout << (*it)->GetProperty("text", "(no text)") << " - " <<
16 (*it)->GetProperty("type", "(no type)") << std::endl; 41 type << std::endl;
17 } 42 }
18 } 43 }
19 } 44 }
20 45
21 FiltersCommand::FiltersCommand( 46 FiltersCommand::FiltersCommand(AdblockPlus::FilterEngine& filterEngine)
22 AdblockPlus::FilterEngine& filterEngine)
23 : Command("filters"), filterEngine(filterEngine) 47 : Command("filters"), filterEngine(filterEngine)
24 { 48 {
25 } 49 }
26 50
27 void FiltersCommand::operator()(const std::string& arguments) 51 void FiltersCommand::operator()(const std::string& arguments)
28 { 52 {
29 std::istringstream argumentStream(arguments); 53 std::istringstream argumentStream(arguments);
30 std::string action; 54 std::string action;
31 argumentStream >> action; 55 argumentStream >> action;
32 if (!action.size()) 56 if (!action.size())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void FiltersCommand::RemoveFilter(const std::string& text) 105 void FiltersCommand::RemoveFilter(const std::string& text)
82 { 106 {
83 AdblockPlus::Filter& filter = filterEngine.GetFilter(text); 107 AdblockPlus::Filter& filter = filterEngine.GetFilter(text);
84 if (!filter.IsListed()) 108 if (!filter.IsListed())
85 { 109 {
86 std::cout << "No such filter '" << text << "'" << std::endl; 110 std::cout << "No such filter '" << text << "'" << std::endl;
87 return; 111 return;
88 } 112 }
89 filter.RemoveFromList(); 113 filter.RemoveFromList();
90 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld