llvm-strings: ensure that the last string is correctly printed
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 12 Nov 2016 03:39:21 +0000 (03:39 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 12 Nov 2016 03:39:21 +0000 (03:39 +0000)
We would ignore the last string that appeared if the file ended with a printable
character.  Ensure that we get the last string.

llvm-svn: 286706

llvm/test/tools/llvm-strings/terminator-neg.test [new file with mode: 0644]
llvm/test/tools/llvm-strings/terminator.test [new file with mode: 0644]
llvm/tools/llvm-strings/llvm-strings.cpp

diff --git a/llvm/test/tools/llvm-strings/terminator-neg.test b/llvm/test/tools/llvm-strings/terminator-neg.test
new file mode 100644 (file)
index 0000000..cdcf524
--- /dev/null
@@ -0,0 +1,2 @@
+RUN: echo -n abc | llvm-strings - | FileCheck -allow-empty %s
+CHECK-NOT: abc
diff --git a/llvm/test/tools/llvm-strings/terminator.test b/llvm/test/tools/llvm-strings/terminator.test
new file mode 100644 (file)
index 0000000..d27eeeb
--- /dev/null
@@ -0,0 +1,2 @@
+RUN: echo -n abcdefg | llvm-strings - | FileCheck %s
+CHECK: abcdefg
index d590b70..dbabf08 100644 (file)
@@ -33,8 +33,8 @@ static cl::list<std::string> InputFileNames(cl::Positional,
                                             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, StringRef Contents) {
       S = nullptr;
     }
   }
+  if (S && E - S > 3)
+    OS << StringRef(S, E - S) << '\n';
 }
 
 namespace {