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

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

Issue 10254076: API cleanup, get rid of JsObject and GetProperty() methods that don`t return JsValue (Closed)
Patch Set: Slightly better Filter/Subscription constructors Created April 26, 2013, 11:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/src/FiltersCommand.cpp ('k') | shell/src/SubscriptionsCommand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <iostream> 1 #include <iostream>
2 #include <sstream> 2 #include <sstream>
3 3
4 #include "MatchesCommand.h" 4 #include "MatchesCommand.h"
5 5
6 MatchesCommand::MatchesCommand(AdblockPlus::FilterEngine& filterEngine) 6 MatchesCommand::MatchesCommand(AdblockPlus::FilterEngine& filterEngine)
7 : Command("matches"), filterEngine(filterEngine) 7 : Command("matches"), filterEngine(filterEngine)
8 { 8 {
9 } 9 }
10 10
11 void MatchesCommand::operator()(const std::string& arguments) 11 void MatchesCommand::operator()(const std::string& arguments)
12 { 12 {
13 std::istringstream argumentStream(arguments); 13 std::istringstream argumentStream(arguments);
14 std::string url; 14 std::string url;
15 argumentStream >> url; 15 argumentStream >> url;
16 std::string contentType; 16 std::string contentType;
17 argumentStream >> contentType; 17 argumentStream >> contentType;
18 std::string documentUrl; 18 std::string documentUrl;
19 argumentStream >> documentUrl; 19 argumentStream >> documentUrl;
20 if (!url.size() || !contentType.size() || !documentUrl.size()) 20 if (!url.size() || !contentType.size() || !documentUrl.size())
21 { 21 {
22 ShowUsage(); 22 ShowUsage();
23 return; 23 return;
24 } 24 }
25 25
26 AdblockPlus::FilterPtr match = filterEngine.Matches(url, contentType, document Url); 26 AdblockPlus::FilterPtr match = filterEngine.Matches(url, contentType, document Url);
27 if (!match) 27 if (!match)
28 std::cout << "No match" << std::endl; 28 std::cout << "No match" << std::endl;
29 else if (match->GetProperty("type", "") == "exception") 29 else if (match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
30 std::cout << "Whitelisted" << std::endl; 30 std::cout << "Whitelisted by " << match->GetProperty("text")->AsString() << std::endl;
31 else 31 else
32 std::cout << "Blocked" << std::endl; 32 std::cout << "Blocked by " << match->GetProperty("text")->AsString() << std: :endl;
33 } 33 }
34 34
35 std::string MatchesCommand::GetDescription() const 35 std::string MatchesCommand::GetDescription() const
36 { 36 {
37 return "Returns the first filter that matches the supplied URL"; 37 return "Returns the first filter that matches the supplied URL";
38 } 38 }
39 39
40 std::string MatchesCommand::GetUsage() const 40 std::string MatchesCommand::GetUsage() const
41 { 41 {
42 return name + " URL CONTENT_TYPE DOCUMENT_URL"; 42 return name + " URL CONTENT_TYPE DOCUMENT_URL";
43 } 43 }
OLDNEW
« no previous file with comments | « shell/src/FiltersCommand.cpp ('k') | shell/src/SubscriptionsCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld