[llvm-commits] [llvm] r87084 - in /llvm/trunk: lib/Support/StringExtras.cpp unittests/ADT/StringRefTest.cpp

Rafael Espindola rafael.espindola at gmail.com
Thu Nov 12 20:55:09 PST 2009


Author: rafael
Date: Thu Nov 12 22:55:09 2009
New Revision: 87084

URL: http://llvm.org/viewvc/llvm-project?rev=87084&view=rev
Log:
Distinguish "a," from "a". The first one splits into "a" + "" and the second one into
"a" + 0.

Modified:
    llvm/trunk/lib/Support/StringExtras.cpp
    llvm/trunk/unittests/ADT/StringRefTest.cpp

Modified: llvm/trunk/lib/Support/StringExtras.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringExtras.cpp?rev=87084&r1=87083&r2=87084&view=diff

==============================================================================
--- llvm/trunk/lib/Support/StringExtras.cpp (original)
+++ llvm/trunk/lib/Support/StringExtras.cpp Thu Nov 12 22:55:09 2009
@@ -63,8 +63,10 @@
                             bool KeepEmpty) const {
   StringRef rest = *this;
 
+  // rest.data() is used to distinguish cases like "a," that splits into
+  // "a" + "" and "a" that splits into "a" + 0.
   for (int splits = 0;
-       rest.size() != 0 && (MaxSplit < 0 || splits < MaxSplit);
+       rest.data() != NULL && (MaxSplit < 0 || splits < MaxSplit);
        ++splits) {
     std::pair<llvm::StringRef, llvm::StringRef> p = rest.split(Separators);
 
@@ -72,7 +74,7 @@
       A.push_back(p.first);
     rest = p.second;
   }
-
-  if (rest.size() != 0 || KeepEmpty)
+  // If we have a tail left, add it.
+  if (rest.data() != NULL && (rest.size() != 0 || KeepEmpty))
     A.push_back(rest);
 }

Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=87084&r1=87083&r2=87084&view=diff

==============================================================================
--- llvm/trunk/unittests/ADT/StringRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Thu Nov 12 22:55:09 2009
@@ -143,6 +143,11 @@
   StringRef(",").split(parts, ",", -1, true);
   EXPECT_TRUE(parts == expected);
 
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back("b");
+  StringRef("a,b").split(parts, ",", -1, true);
+  EXPECT_TRUE(parts == expected);
+
   // Test MaxSplit
   expected.clear(); parts.clear();
   expected.push_back("a,,b,c");





More information about the llvm-commits mailing list