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.

llvm-svn: 286706
This commit is contained in:
Saleem Abdulrasool 2016-11-12 03:39:21 +00:00
parent 73caa383e6
commit b89c12e248
3 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,2 @@
RUN: echo -n abc | llvm-strings - | FileCheck -allow-empty %s
CHECK-NOT: abc

View File

@ -0,0 +1,2 @@
RUN: echo -n abcdefg | llvm-strings - | FileCheck %s
CHECK: abcdefg

View 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 {