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

Side by Side Diff: compiled/subscription/Subscription.cpp

Issue 29721753: Issue 6180 - use ABP_TEXT everywhere in order to let String be a UTF-8 string (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git@adb2678354813ce5b6de095072954c5a784a7bc4
Patch Set: Created March 13, 2018, 6:20 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 /* 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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 int Subscription::IndexOfFilter(const Filter& filter) 54 int Subscription::IndexOfFilter(const Filter& filter)
55 { 55 {
56 for (Filters::size_type i = 0; i < mFilters.size(); i++) 56 for (Filters::size_type i = 0; i < mFilters.size(); i++)
57 if (mFilters[i] == &filter) 57 if (mFilters[i] == &filter)
58 return i; 58 return i;
59 return -1; 59 return -1;
60 } 60 }
61 61
62 OwnedString Subscription::Serialize() const 62 OwnedString Subscription::Serialize() const
63 { 63 {
64 OwnedString result(u"[Subscription]\nurl="_str); 64 OwnedString result(ABP_TEXT("[Subscription]\nurl="_str));
65 result.append(mID); 65 result.append(mID);
66 result.append(u'\n'); 66 result.append(ABP_TEXT('\n'));
67 if (!mTitle.empty()) 67 if (!mTitle.empty())
68 { 68 {
69 result.append(u"title="_str); 69 result.append(ABP_TEXT("title="_str));
70 result.append(mTitle); 70 result.append(mTitle);
71 result.append(u'\n'); 71 result.append(ABP_TEXT('\n'));
72 } 72 }
73 if (mDisabled) 73 if (mDisabled)
74 result.append(u"disabled=true\n"_str); 74 result.append(ABP_TEXT("disabled=true\n"_str));
75 75
76 return result; 76 return result;
77 } 77 }
78 78
79 OwnedString Subscription::SerializeFilters() const 79 OwnedString Subscription::SerializeFilters() const
80 { 80 {
81 if (!mFilters.size()) 81 if (!mFilters.size())
82 return OwnedString(); 82 return OwnedString();
83 83
84 OwnedString result(u"[Subscription filters]\n"_str); 84 OwnedString result(ABP_TEXT("[Subscription filters]\n"_str));
85 for (const auto& filter : mFilters) 85 for (const auto& filter : mFilters)
86 { 86 {
87 // TODO: Escape [ characters 87 // TODO: Escape [ characters
88 result.append(filter->GetText()); 88 result.append(filter->GetText());
89 result.append(u'\n'); 89 result.append(ABP_TEXT('\n'));
90 } 90 }
91 return result; 91 return result;
92 } 92 }
93 93
94 Subscription* Subscription::FromID(const String& id) 94 Subscription* Subscription::FromID(const String& id)
95 { 95 {
96 if (id.empty()) 96 if (id.empty())
97 { 97 {
98 // Generate a new random ID 98 // Generate a new random ID
99 std::mt19937 gen(knownSubscriptions.size()); 99 std::mt19937 gen(knownSubscriptions.size());
100 OwnedString randomID(u"~user~000000"_str); 100 OwnedString randomID(ABP_TEXT("~user~000000"_str));
101 do 101 do
102 { 102 {
103 int number = gen(); 103 int number = gen();
104 for (String::size_type i = randomID.length() - 6; i < randomID.length(); i ++) 104 for (String::size_type i = randomID.length() - 6; i < randomID.length(); i ++)
105 { 105 {
106 randomID[i] = '0' + (number % 10); 106 randomID[i] = ABP_TEXT('0') + (number % 10);
107 number /= 10; 107 number /= 10;
108 } 108 }
109 } while (knownSubscriptions.find(randomID)); 109 } while (knownSubscriptions.find(randomID));
110 return FromID(randomID); 110 return FromID(randomID);
111 } 111 }
112 112
113 auto knownSubscription = knownSubscriptions.find(id); 113 auto knownSubscription = knownSubscriptions.find(id);
114 if (knownSubscription) 114 if (knownSubscription)
115 { 115 {
116 knownSubscription->second->AddRef(); 116 knownSubscription->second->AddRef();
117 return knownSubscription->second; 117 return knownSubscription->second;
118 } 118 }
119 119
120 SubscriptionPtr subscription; 120 SubscriptionPtr subscription;
121 if (!id.empty() && id[0] == '~') 121 if (!id.empty() && id[0] == ABP_TEXT('~'))
122 subscription = SubscriptionPtr(new UserDefinedSubscription(id), false); 122 subscription = SubscriptionPtr(new UserDefinedSubscription(id), false);
123 else 123 else
124 subscription = SubscriptionPtr(new DownloadableSubscription(id), false); 124 subscription = SubscriptionPtr(new DownloadableSubscription(id), false);
125 125
126 // This is a hack: we looked up the entry using id but create it using 126 // This is a hack: we looked up the entry using id but create it using
127 // subscription->mID. This works because both are equal at this point. 127 // subscription->mID. This works because both are equal at this point.
128 // However, id refers to a temporary buffer which will go away. 128 // However, id refers to a temporary buffer which will go away.
129 enter_context("Adding to known subscriptions"); 129 enter_context("Adding to known subscriptions");
130 knownSubscription.assign(subscription->mID, subscription.get()); 130 knownSubscription.assign(subscription->mID, subscription.get());
131 exit_context(); 131 exit_context();
132 132
133 return subscription.release(); 133 return subscription.release();
134 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld