[llvm] r286706 - llvm-strings: ensure that the last string is correctly printed

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 19:39:22 PST 2016


Author: compnerd
Date: Fri Nov 11 21:39:21 2016
New Revision: 286706

URL: http://llvm.org/viewvc/llvm-project?rev=286706&view=rev
Log:
llvm-strings: ensure that the last string is correctly printed

We would ignore the last string that appeared if the file ended with a printable
character.  Ensure that we get the last string.

Added:
    llvm/trunk/test/tools/llvm-strings/
    llvm/trunk/test/tools/llvm-strings/terminator-neg.test
    llvm/trunk/test/tools/llvm-strings/terminator.test
Modified:
    llvm/trunk/tools/llvm-strings/llvm-strings.cpp

Added: llvm/trunk/test/tools/llvm-strings/terminator-neg.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-strings/terminator-neg.test?rev=286706&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-strings/terminator-neg.test (added)
+++ llvm/trunk/test/tools/llvm-strings/terminator-neg.test Fri Nov 11 21:39:21 2016
@@ -0,0 +1,2 @@
+RUN: echo -n abc | llvm-strings - | FileCheck -allow-empty %s
+CHECK-NOT: abc

Added: llvm/trunk/test/tools/llvm-strings/terminator.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-strings/terminator.test?rev=286706&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-strings/terminator.test (added)
+++ llvm/trunk/test/tools/llvm-strings/terminator.test Fri Nov 11 21:39:21 2016
@@ -0,0 +1,2 @@
+RUN: echo -n abcdefg | llvm-strings - | FileCheck %s
+CHECK: abcdefg

Modified: llvm/trunk/tools/llvm-strings/llvm-strings.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-strings/llvm-strings.cpp?rev=286706&r1=286705&r2=286706&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-strings/llvm-strings.cpp (original)
+++ llvm/trunk/tools/llvm-strings/llvm-strings.cpp Fri Nov 11 21:39:21 2016
@@ -33,8 +33,8 @@ static cl::list<std::string> InputFileNa
                                             cl::ZeroOrMore);
 
 static void dump(raw_ostream &OS, StringRef Contents) {
-  const char *S = nullptr;
-  for (const char *P = Contents.begin(), *E = Contents.end(); P < E; ++P) {
+  const char *P = nullptr, *E = nullptr, *S = nullptr;
+  for (P = Contents.begin(), E = Contents.end(); P < E; ++P) {
     if (std::isgraph(*P) || std::isblank(*P)) {
       if (S == nullptr)
         S = P;
@@ -44,6 +44,8 @@ static void dump(raw_ostream &OS, String
       S = nullptr;
     }
   }
+  if (S && E - S > 3)
+    OS << StringRef(S, E - S) << '\n';
 }
 
 namespace {




More information about the llvm-commits mailing list