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

Delta Between Two Patch Sets: compiled/subscription/Subscription.cpp

Issue 29548581: Issue 4128, 5138 - Add Parser and Serializer implemented in C++ Base URL: https://github.com/adblockplus/adblockpluscore.git
Left Patch Set: Created Sept. 18, 2017, 5:23 p.m.
Right Patch Set: rebase Created March 7, 2018, 12:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/subscription/Subscription.h ('k') | compiled/subscription/UserDefinedSubscription.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <cstdio> 18 #include <cstdio>
19 #include <cstdlib> 19 #include <cstdlib>
20 #include <random>
20 21
21 #include "Subscription.h" 22 #include "Subscription.h"
22 #include "DownloadableSubscription.h" 23 #include "DownloadableSubscription.h"
23 #include "UserDefinedSubscription.h" 24 #include "UserDefinedSubscription.h"
24 #include "../StringMap.h" 25 #include "../StringMap.h"
26
27 ABP_NS_USING
25 28
26 namespace 29 namespace
27 { 30 {
28 StringMap<Subscription*> knownSubscriptions(16); 31 StringMap<Subscription*> knownSubscriptions(16);
29 } 32 }
30 33
31 Subscription::Subscription(Type type, const String& id, const KeyValues& propert ies) 34 Subscription::Subscription(Type type, const String& id, const KeyValues& propert ies)
32 : mID(id), mType(type), mDisabled(false), mListed(false) 35 : mID(id), mType(type), mDisabled(false), mListed(false)
33 { 36 {
34 annotate_address(this, "Subscription"); 37 annotate_address(this, "Subscription");
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 result.append(u"disabled=true\n"_str); 92 result.append(u"disabled=true\n"_str);
90 93
91 return result; 94 return result;
92 } 95 }
93 96
94 SubscriptionPtr Subscription::FromProperties(const String& id, const KeyValues& keyValues) 97 SubscriptionPtr Subscription::FromProperties(const String& id, const KeyValues& keyValues)
95 { 98 {
96 if (id.empty()) 99 if (id.empty())
97 { 100 {
98 // Generate a new random ID 101 // Generate a new random ID
99 unsigned int seed = knownSubscriptions.size(); 102 std::mt19937 gen(knownSubscriptions.size());
100 OwnedString randomID(u"~user~000000"_str); 103 OwnedString randomID(u"~user~000000"_str);
101 do 104 do
102 { 105 {
103 int number = rand_r(&seed); 106 int number = gen();
104 for (int i = randomID.length() - 6; i < randomID.length(); i++) 107 for (String::size_type i = randomID.length() - 6; i < randomID.length(); i ++)
105 { 108 {
106 randomID[i] = '0' + (number % 10); 109 randomID[i] = '0' + (number % 10);
107 number /= 10; 110 number /= 10;
108 } 111 }
109 } while (knownSubscriptions.find(randomID)); 112 } while (knownSubscriptions.find(randomID));
110 return FromProperties(randomID, keyValues); 113 return FromProperties(randomID, keyValues);
111 } 114 }
112 115
113 auto knownSubscription = knownSubscriptions.find(id); 116 auto knownSubscription = knownSubscriptions.find(id);
114 if (knownSubscription) 117 if (knownSubscription)
(...skipping 23 matching lines...) Expand all
138 return FromProperties(*id, properties); 141 return FromProperties(*id, properties);
139 } 142 }
140 143
141 const String* Subscription::findPropertyValue(const Subscription::KeyValues& pro perties, const String& propertyName) 144 const String* Subscription::findPropertyValue(const Subscription::KeyValues& pro perties, const String& propertyName)
142 { 145 {
143 for (const auto& property : properties) 146 for (const auto& property : properties)
144 if (property.first == propertyName) 147 if (property.first == propertyName)
145 return &property.second; 148 return &property.second;
146 return nullptr; 149 return nullptr;
147 } 150 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld