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

Side by Side Diff: compiled/String.h

Issue 29595633: Issue 5870 - Implement the new ElemHideEmulation filter type (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Reworked the strings const. String::find() from a String::value_type* Created Feb. 1, 2018, 8:36 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/filter/ElemHideBase.h » ('j') | no next file with comments »
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
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 size_type find(value_type c, size_type pos = 0) const 129 size_type find(value_type c, size_type pos = 0) const
130 { 130 {
131 for (size_type i = pos; i < length(); ++i) 131 for (size_type i = pos; i < length(); ++i)
132 if (mBuf[i] == c) 132 if (mBuf[i] == c)
133 return i; 133 return i;
134 return npos; 134 return npos;
135 } 135 }
136 136
137 size_type find(const String& str, size_type pos = 0) const 137 size_type find(const String& str, size_type pos = 0) const
138 { 138 {
139 if (pos > LENGTH_MASK || pos + str.length() > length()) 139 return find(str.mBuf, pos, str.length());
140 }
141
142 size_type find(const value_type* str, size_type pos, size_type count) const
143 {
144 if (pos > LENGTH_MASK || pos + count > length())
140 return npos; 145 return npos;
141 146
142 if (!str.length()) 147 if (!count)
143 return pos; 148 return pos;
144 149
145 for (; pos + str.length() <= length(); ++pos) 150 for (; pos + count <= length(); ++pos)
146 { 151 {
147 if (mBuf[pos] == str[0] && 152 if (mBuf[pos] == str[0] &&
148 std::memcmp(mBuf + pos, str.mBuf, sizeof(value_type) * str.length()) = = 0) 153 std::memcmp(mBuf + pos, str, sizeof(value_type) * count) == 0)
149 { 154 {
150 return pos; 155 return pos;
151 } 156 }
152 } 157 }
153 158
154 return npos; 159 return npos;
155 } 160 }
156 161
157 size_type rfind(value_type c, size_type pos = npos) const 162 size_type rfind(value_type c, size_type pos = npos) const
158 { 163 {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 445 }
441 } 446 }
442 }; 447 };
443 448
444 #ifdef INSIDE_TESTS 449 #ifdef INSIDE_TESTS
445 inline std::ostream& operator<<(std::ostream& os, const OwnedString& str) 450 inline std::ostream& operator<<(std::ostream& os, const OwnedString& str)
446 { 451 {
447 return os << static_cast<const String&>(str); 452 return os << static_cast<const String&>(str);
448 } 453 }
449 #endif 454 #endif
OLDNEW
« no previous file with comments | « no previous file | compiled/filter/ElemHideBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld