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

Side by Side Diff: compiled/String.h

Issue 29556737: Issue 5141 - Convert filter match to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 26, 2017, 9:34 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
« no previous file with comments | « no previous file | compiled/String.cpp » ('j') | compiled/filter/Filter.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 #pragma once 18 #pragma once
19 19
20 #include <algorithm> 20 #include <algorithm>
21 #include <cstddef> 21 #include <cstddef>
22 #include <cstring> 22 #include <cstring>
23 #include <type_traits> 23 #include <type_traits>
24 #include <vector>
24 25
25 #include "debug.h" 26 #include "debug.h"
26 #include "library.h" 27 #include "library.h"
28 #include "intrusive_ptr.h"
29 #include "bindings/runtime.h"
27 30
28 inline void String_assert_writable(bool isWritable); 31 inline void String_assert_writable(bool isWritable);
29 32
33 class OwnedString;
34 class ReMatchResults;
35
30 class String 36 class String
31 { 37 {
32 friend class DependentString; 38 friend class DependentString;
33 friend class OwnedString; 39 friend class OwnedString;
34 40
35 public: 41 public:
36 typedef char16_t value_type; 42 typedef char16_t value_type;
37 typedef size_t size_type; 43 typedef size_t size_type;
38 44
39 // Type flags, stored in the top 2 bits of the mLen member 45 // Type flags, stored in the top 2 bits of the mLen member
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // This should be more efficient with a lookup table but I couldn't measur e 190 // This should be more efficient with a lookup table but I couldn't measur e
185 // any performance difference. 191 // any performance difference.
186 if (currChar >= u'A' && currChar <= u'Z') 192 if (currChar >= u'A' && currChar <= u'Z')
187 mBuf[i] = currChar + u'a' - u'A'; 193 mBuf[i] = currChar + u'a' - u'A';
188 else if (currChar >= 128) 194 else if (currChar >= 128)
189 { 195 {
190 mBuf[i] = CharToLower(currChar); 196 mBuf[i] = CharToLower(currChar);
191 } 197 }
192 } 198 }
193 } 199 }
200
201 OwnedString substr(size_type pos, size_type len = npos) const;
202 bool match(int id, ReMatchResults*) const;
hub 2017/09/26 21:48:59 String API that mimic JS string API.
194 }; 203 };
195 204
196 class DependentString : public String 205 class DependentString : public String
197 { 206 {
198 public: 207 public:
199 explicit DependentString() 208 explicit DependentString()
200 : String(nullptr, 0, INVALID) 209 : String(nullptr, 0, INVALID)
201 { 210 {
202 } 211 }
203 212
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (negative) 407 if (negative)
399 mBuf[pos++] = '-'; 408 mBuf[pos++] = '-';
400 409
401 for (int i = size - 1; i >= 0; i--) 410 for (int i = size - 1; i >= 0; i--)
402 { 411 {
403 mBuf[pos + i] = '0' + (num % 10); 412 mBuf[pos + i] = '0' + (num % 10);
404 num /= 10; 413 num /= 10;
405 } 414 }
406 } 415 }
407 }; 416 };
417
418 // Utility class to get match from JS code in library.js
419 class ReMatchResults : public ref_counted
hub 2017/09/26 21:48:59 This it the hack to be able to get the array of st
sergei 2017/10/02 12:02:32 I thin it's fine, I had experienced a demand in so
420 {
421 public:
422 void BINDINGS_EXPORTED push(OwnedString&& s)
423 {
424 candidates.push_back(s);
425 }
426 std::vector<OwnedString> candidates;
427 };
OLDNEW
« no previous file with comments | « no previous file | compiled/String.cpp » ('j') | compiled/filter/Filter.h » ('J')

Powered by Google App Engine
This is Rietveld