From: Saleem Abdulrasool Date: Sat, 12 Nov 2016 03:39:21 +0000 (+0000) Subject: llvm-strings: ensure that the last string is correctly printed X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=421c744b29ab1f67f39845bd2a891f7821518dce;p=llvm 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286706 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/llvm-strings/terminator-neg.test b/test/tools/llvm-strings/terminator-neg.test new file mode 100644 index 00000000000..cdcf52498f6 --- /dev/null +++ b/test/tools/llvm-strings/terminator-neg.test @@ -0,0 +1,2 @@ +RUN: echo -n abc | llvm-strings - | FileCheck -allow-empty %s +CHECK-NOT: abc diff --git a/test/tools/llvm-strings/terminator.test b/test/tools/llvm-strings/terminator.test new file mode 100644 index 00000000000..d27eeebe2e7 --- /dev/null +++ b/test/tools/llvm-strings/terminator.test @@ -0,0 +1,2 @@ +RUN: echo -n abcdefg | llvm-strings - | FileCheck %s +CHECK: abcdefg diff --git a/tools/llvm-strings/llvm-strings.cpp b/tools/llvm-strings/llvm-strings.cpp index d590b7012b6..dbabf08a52f 100644 --- a/tools/llvm-strings/llvm-strings.cpp +++ b/tools/llvm-strings/llvm-strings.cpp @@ -33,8 +33,8 @@ static cl::list 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 {