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

Side by Side Diff: compiled/String.cpp

Issue 29712634: Noissue - add SplitString and TrimSpaces helpers (Closed) Base URL: github.com:adblockplus/adblockpluscore
Patch Set: Created March 1, 2018, 2:57 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 | « compiled/String.h ('k') | meson.build » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present 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
18 #include "String.h"
19
20 ABP_NS_BEGIN
21
22 DependentString TrimSpaces(const String& value)
23 {
24 String::size_type start = 0;
25 auto end = value.length();
26 for (; start < end; ++start)
27 {
28 if (value[start] > u' ')
hub 2018/03/01 18:40:07 we could write this loop as `for (; start < end &&
sergei 2018/03/01 21:14:12 Yes, but I rather wanted to separate that comparis
hub 2018/03/01 22:15:44 Acknowledged.
29 break;
30 }
31 for (; end > start; --end)
32 {
33 if (value[end - 1] > u' ')
34 break;
35 }
36 return DependentString(value, start, end - start);
37 }
38
39 std::pair<DependentString, DependentString> SplitString(const String& value, Str ing::size_type separatorPos)
40 {
41 const auto secondBeginPos = separatorPos < String::npos ? separatorPos + 1 : S tring::npos;
42 return {
43 DependentString{value, 0, separatorPos},
44 DependentString{value, secondBeginPos, value.length() - secondBeginPos}
45 };
hub 2018/03/01 18:40:07 what if secondBeginPos > value.length() ? since si
sergei 2018/03/01 21:14:12 value.length(), secondBeginPos and len (the third
hub 2018/03/01 22:15:44 Acknowledged.
46 }
47
48 ABP_NS_END
OLDNEW
« no previous file with comments | « compiled/String.h ('k') | meson.build » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld