[PATCH] D29186: clang-format: [JS] do not format MPEG transport streams.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 26 09:35:55 PST 2017
mprobst created this revision.
Herald added a subscriber: klimek.
The MPEG transport stream file format also uses ".ts" as its file extension.
This change detects its specific framing format (0x47 every 189 bytes) and
simply ignores MPEG TS files.
https://reviews.llvm.org/D29186
Files:
tools/clang-format/ClangFormat.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -998,6 +998,13 @@
verifyFormat("var regex = search.match(/(?:\?|&)times=([^?&]+)/i);");
}
+TEST_F(FormatTestJS, IgnoresMpegTS) {
+ char mpegTS[200];
+ mpegTS[0] = 0x47;
+ mpegTS[188] = 0x47;
+ verifyFormat(mpegTS);
+}
+
TEST_F(FormatTestJS, TypeAnnotations) {
verifyFormat("var x: string;");
verifyFormat("var x: {a: string; b: number;} = {};");
Index: tools/clang-format/ClangFormat.cpp
===================================================================
--- tools/clang-format/ClangFormat.cpp
+++ tools/clang-format/ClangFormat.cpp
@@ -251,6 +251,14 @@
StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
FormatStyle FormatStyle =
getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());
+
+ // MPEG transport streams use the ".ts" file extension. clang-format should
+ // not attempt to format those. MPEG TS' frame format starts with 0x47 every
+ // 189 bytes - detect that and return.
+ if (AssumedFileName.endswith(".ts") && Code->getBufferSize() > 188 &&
+ Code->getBuffer()[0] == 0x47 && Code->getBuffer()[188] == 0x47)
+ return true;
+
if (SortIncludes.getNumOccurrences() != 0)
FormatStyle.SortIncludes = SortIncludes;
unsigned CursorPosition = Cursor;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29186.85930.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170126/ac9bc8a6/attachment.bin>
More information about the cfe-commits
mailing list