[PATCH] D117897: [split-file] Respect input file's line endings
Chris Bieneman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 16:45:33 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13fa17db3a72: [split-file] Respect input file's line endings (authored by beanz).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117897/new/
https://reviews.llvm.org/D117897
Files:
llvm/.gitattributes
llvm/test/tools/split-file/Inputs/basic-aa.crlf
llvm/test/tools/split-file/Inputs/basic-bb.crlf
llvm/test/tools/split-file/basic.crlf.test
llvm/tools/split-file/split-file.cpp
Index: llvm/tools/split-file/split-file.cpp
===================================================================
--- llvm/tools/split-file/split-file.cpp
+++ llvm/tools/split-file/split-file.cpp
@@ -71,6 +71,7 @@
static int handle(MemoryBuffer &inputBuf, StringRef input) {
DenseMap<StringRef, Part> partToBegin;
StringRef lastPart, separator;
+ StringRef EOL = inputBuf.getBuffer().detectEOL();
for (line_iterator i(inputBuf, /*SkipBlanks=*/false, '\0'); !i.is_at_eof();) {
const int64_t lineNo = i.line_number();
const StringRef line = *i++;
@@ -128,7 +129,7 @@
Part &part = keyValue.second;
for (int64_t i = 0; i != part.leadingLines; ++i)
- (*f).os().write('\n');
+ (*f).os() << EOL;
if (part.begin)
(*f).os().write(part.begin, part.end - part.begin);
outputFiles.push_back(std::move(f));
Index: llvm/test/tools/split-file/basic.crlf.test
===================================================================
--- /dev/null
+++ llvm/test/tools/split-file/basic.crlf.test
@@ -0,0 +1,10 @@
+#--- aa
+aa
+;--- bb
+bb
+;--- end
+
+# RUN: rm -rf %t
+# RUN: split-file --leading-lines %s %t
+# RUN: diff %S/Inputs/basic-aa.crlf %t/aa
+# RUN: diff %S/Inputs/basic-bb.crlf %t/bb
Index: llvm/test/tools/split-file/Inputs/basic-bb.crlf
===================================================================
--- /dev/null
+++ llvm/test/tools/split-file/Inputs/basic-bb.crlf
@@ -0,0 +1,4 @@
+
+
+
+bb
Index: llvm/test/tools/split-file/Inputs/basic-aa.crlf
===================================================================
--- /dev/null
+++ llvm/test/tools/split-file/Inputs/basic-aa.crlf
@@ -0,0 +1,2 @@
+
+aa
Index: llvm/.gitattributes
===================================================================
--- llvm/.gitattributes
+++ llvm/.gitattributes
@@ -25,3 +25,5 @@
test/tools/llvm-strings/radix.test text eol=lf
test/tools/split-file/basic.test text eol=lf
test/tools/split-file/Inputs/basic-*.txt eol=lf
+test/tools/split-file/basic.crlf.test text eol=crlf
+test/tools/split-file/Inputs/basic-*.crlf eol=crlf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117897.402134.patch
Type: text/x-patch
Size: 2066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220122/e7799cc4/attachment.bin>
More information about the llvm-commits
mailing list