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

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

Issue 29385742: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 2 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created March 16, 2017, 6:27 p.m.
Right Patch Set: Rebased Created April 13, 2017, 1: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 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
1 #include <cstdio> 18 #include <cstdio>
2 #include <cstdlib> 19 #include <cstdlib>
3 20
4 #include "Subscription.h" 21 #include "Subscription.h"
5 #include "DownloadableSubscription.h" 22 #include "DownloadableSubscription.h"
6 #include "UserDefinedSubscription.h" 23 #include "UserDefinedSubscription.h"
7 #include "../StringMap.h" 24 #include "../StringMap.h"
8 25
9 namespace 26 namespace
10 { 27 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 72
56 return result; 73 return result;
57 } 74 }
58 75
59 OwnedString Subscription::SerializeFilters() const 76 OwnedString Subscription::SerializeFilters() const
60 { 77 {
61 if (!mFilters.size()) 78 if (!mFilters.size())
62 return OwnedString(); 79 return OwnedString();
63 80
64 OwnedString result(u"[Subscription filters]\n"_str); 81 OwnedString result(u"[Subscription filters]\n"_str);
65 for (unsigned i = 0; i < mFilters.size(); i++) 82 for (const auto& filter : mFilters)
66 { 83 {
67 // TODO: Escape [ characters 84 // TODO: Escape [ characters
Wladimir Palant 2017/03/16 18:31:23 Not fixing this at this point because the serializ
68 result.append(mFilters[i]->GetText()); 85 result.append(filter->GetText());
69 result.append(u'\n'); 86 result.append(u'\n');
70 } 87 }
71 return result; 88 return result;
72 } 89 }
73 90
74 Subscription* Subscription::FromID(const String& id) 91 Subscription* Subscription::FromID(const String& id)
75 { 92 {
76 if (id.empty()) 93 if (id.empty())
77 { 94 {
78 // Generate a new random ID 95 // Generate a new random ID
79 unsigned seed = knownSubscriptions.size(); 96 unsigned int seed = knownSubscriptions.size();
80 OwnedString randomID(u"~user~000000"_str); 97 OwnedString randomID(u"~user~000000"_str);
81 do 98 do
82 { 99 {
83 int number = rand_r(&seed); 100 int number = rand_r(&seed);
84 for (int i = randomID.length() - 6; i < randomID.length(); i++) 101 for (int i = randomID.length() - 6; i < randomID.length(); i++)
85 { 102 {
86 randomID[i] = '0' + (number % 10); 103 randomID[i] = '0' + (number % 10);
87 number /= 10; 104 number /= 10;
88 } 105 }
89 } while (knownSubscriptions.find(randomID)); 106 } while (knownSubscriptions.find(randomID));
(...skipping 15 matching lines...) Expand all
105 122
106 // This is a hack: we looked up the entry using id but create it using 123 // This is a hack: we looked up the entry using id but create it using
107 // subscription->mID. This works because both are equal at this point. 124 // subscription->mID. This works because both are equal at this point.
108 // However, id refers to a temporary buffer which will go away. 125 // However, id refers to a temporary buffer which will go away.
109 enter_context("Adding to known subscriptions"); 126 enter_context("Adding to known subscriptions");
110 knownSubscription.assign(subscription->mID, subscription.get()); 127 knownSubscription.assign(subscription->mID, subscription.get());
111 exit_context(); 128 exit_context();
112 129
113 return subscription.release(); 130 return subscription.release();
114 } 131 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld