You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/02/12 11:20:12 UTC

[2/5] mesos git commit: Fixed a bug in strings::split when n=1.

Fixed a bug in strings::split when n=1.


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9d020470
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9d020470
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9d020470

Branch: refs/heads/master
Commit: 9d020470f7fefb7b257912e8a0dfddae8e5fbe86
Parents: e6fdd5d
Author: Benjamin Mahler <be...@gmail.com>
Authored: Thu Feb 11 13:46:00 2016 +0100
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Feb 12 10:33:28 2016 +0100

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/strings.hpp          | 14 ++++++--------
 .../libprocess/3rdparty/stout/tests/strings_tests.cpp |  8 ++++++++
 2 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9d020470/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
index 015eecd..ae3b6eb 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
@@ -171,24 +171,22 @@ inline std::vector<std::string> split(
     const std::string& delims,
     const Option<size_t>& maxTokens = None())
 {
-  std::vector<std::string> tokens;
   size_t offset = 0;
+  std::vector<std::string> tokens;
 
   while (maxTokens.isNone() || maxTokens.get() > 0) {
     size_t next = s.find_first_of(delims, offset);
-    if (next == std::string::npos) {
+
+    // Finish splitting if this is the last token,
+    // or we've found enough tokens.
+    if (next == std::string::npos ||
+        (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1)) {
       tokens.push_back(s.substr(offset));
       break;
     }
 
     tokens.push_back(s.substr(offset, next - offset));
     offset = next + 1;
-
-    // Finish splitting if we've found enough tokens.
-    if (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1) {
-      tokens.push_back(s.substr(offset));
-      break;
-    }
   }
 
   return tokens;

http://git-wip-us.apache.org/repos/asf/mesos/blob/9d020470/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
index 8e7d3ee..877dc70 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
@@ -288,6 +288,14 @@ TEST(StringsTest, SplitNZero)
 }
 
 
+TEST(StringsTest, SplitNOne)
+{
+  vector<string> tokens = strings::split("foo,bar,,,", ",", 1);
+  ASSERT_EQ(1u, tokens.size());
+  EXPECT_EQ("foo,bar,,,", tokens[0]);
+}
+
+
 TEST(StringsTest, SplitNDelimOnlyString)
 {
   vector<string> tokens = strings::split(",,,", ",", 2);