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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/String.h ('k') | meson.build » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/String.cpp
diff --git a/compiled/String.cpp b/compiled/String.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..38f458a432978d7c516ce07f796c77428d6a31ec
--- /dev/null
+++ b/compiled/String.cpp
@@ -0,0 +1,48 @@
+/*
+* This file is part of Adblock Plus <https://adblockplus.org/>,
+* Copyright (C) 2006-present eyeo GmbH
+*
+* Adblock Plus is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 3 as
+* published by the Free Software Foundation.
+*
+* Adblock Plus is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "String.h"
+
+ABP_NS_BEGIN
+
+DependentString TrimSpaces(const String& value)
+{
+ String::size_type start = 0;
+ auto end = value.length();
+ for (; start < end; ++start)
+ {
+ 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.
+ break;
+ }
+ for (; end > start; --end)
+ {
+ if (value[end - 1] > u' ')
+ break;
+ }
+ return DependentString(value, start, end - start);
+}
+
+std::pair<DependentString, DependentString> SplitString(const String& value, String::size_type separatorPos)
+{
+ const auto secondBeginPos = separatorPos < String::npos ? separatorPos + 1 : String::npos;
+ return {
+ DependentString{value, 0, separatorPos},
+ DependentString{value, secondBeginPos, value.length() - secondBeginPos}
+ };
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.
+}
+
+ABP_NS_END
« 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