summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-format/clang-format.py
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-12-10 00:54:13 +0000
committerVedant Kumar <vsk@apple.com>2016-12-10 00:54:13 +0000
commit0972da7870d7bf9a3ac1d47246db5c62f28e671a (patch)
tree32235e0316268aacd808e6d2a73c445b5fe55020 /clang/tools/clang-format/clang-format.py
parent2402b95db010e80f76804f07e0f59ffcae42fbdb (diff)
downloadbcm5719-llvm-0972da7870d7bf9a3ac1d47246db5c62f28e671a.tar.gz
bcm5719-llvm-0972da7870d7bf9a3ac1d47246db5c62f28e671a.zip
[clang-format] Another attempt at python 3 compatibility
The entries in vim.current.buffer appear to be decoded strings, which means that python3 won't allow invoking 'decode' on them. Keep the old behavior when running under python2, but skip the error-inducing decode step with python3.. llvm-svn: 289308
Diffstat (limited to 'clang/tools/clang-format/clang-format.py')
-rw-r--r--clang/tools/clang-format/clang-format.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py
index aded301781b..ae8a6ebf74e 100644
--- a/clang/tools/clang-format/clang-format.py
+++ b/clang/tools/clang-format/clang-format.py
@@ -29,6 +29,7 @@ from __future__ import print_function
import difflib
import json
+import platform
import subprocess
import sys
import vim
@@ -48,10 +49,15 @@ fallback_style = None
if vim.eval('exists("g:clang_format_fallback_style")') == "1":
fallback_style = vim.eval('g:clang_format_fallback_style')
+def get_buffer(encoding):
+ if platform.python_version_tuple()[0] == '3':
+ return vim.current.buffer
+ return [ line.decode(encoding) for line in vim.current.buffer ]
+
def main():
# Get the current text.
encoding = vim.eval("&encoding")
- buf = [ line.decode(encoding) for line in vim.current.buffer ]
+ buf = get_buffer(encoding)
text = '\n'.join(buf)
# Determine range to format.
OpenPOWER on IntegriCloud