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: Replace GetElementHidingRules by a domain-specific GetElementHidingSelectors Created April 5, 2013, 12:22 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
(Empty)
1 #include <iostream>
2 #include <sstream>
3
4 #include "FiltersCommand.h"
5
6 namespace
7 {
8 typedef std::vector<AdblockPlus::Filter*> FilterList;
9
10 void ShowFilterList(const FilterList& filters)
11 {
12 for (FilterList::const_iterator it = filters.begin();
13 it != filters.end(); it++)
14 {
15 std::cout << (*it)->GetProperty("text", "(no text)") << " - " <<
16 (*it)->GetProperty("type", "(no type)") << std::endl;
17 }
18 }
19 }
20
21 FiltersCommand::FiltersCommand(
22 AdblockPlus::FilterEngine& filterEngine)
Felix Dahlke 2013/04/06 05:17:05 This fits in one line, no need to wrap.
23 : Command("filters"), filterEngine(filterEngine)
24 {
25 }
26
27 void FiltersCommand::operator()(const std::string& arguments)
28 {
29 std::istringstream argumentStream(arguments);
30 std::string action;
31 argumentStream >> action;
32 if (!action.size())
33 {
34 ShowFilters();
35 return;
36 }
37
38 if (action == "add")
39 {
40 std::string text;
41 std::getline(argumentStream, text);
42 if (text.size())
43 AddFilter(text);
44 else
45 ShowUsage();
46 }
47 else if (action == "remove")
48 {
49 std::string text;
50 std::getline(argumentStream, text);
51 if (text.size())
52 RemoveFilter(text);
53 else
54 ShowUsage();
55 }
56 else
57 throw NoSuchCommandError(name + " " + action);
58 }
59
60 std::string FiltersCommand::GetDescription() const
61 {
62 return "List and manage custom filters";
63 }
64
65 std::string FiltersCommand::GetUsage() const
66 {
67 return name + " [add FILTER|remove FILTER]";
68 }
69
70 void FiltersCommand::ShowFilters()
71 {
72 ShowFilterList(filterEngine.GetListedFilters());
73 }
74
75 void FiltersCommand::AddFilter(const std::string& text)
76 {
77 AdblockPlus::Filter& filter = filterEngine.GetFilter(text);
78 filter.AddToList();
79 }
80
81 void FiltersCommand::RemoveFilter(const std::string& text)
82 {
83 AdblockPlus::Filter& filter = filterEngine.GetFilter(text);
84 if (!filter.IsListed())
85 {
86 std::cout << "No such filter '" << text << "'" << std::endl;
87 return;
88 }
89 filter.RemoveFromList();
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld