Use -lines option instead of -offset/-length. This fixes problems with files using dos newlines (<CR><LF>).
git-svn-id: svn://svn.chromium.org/llvm-project/cfe/trunk/tools/clang-format@186740 0b72dbe1-c17f-4bc7-b9db-2b4152be0356
diff --git a/clang-format.py b/clang-format.py
index 29be72e..866baf5 100644
--- a/clang-format.py
+++ b/clang-format.py
@@ -35,10 +35,7 @@
# Determine range to format.
cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
-offset = int(vim.eval('line2byte(' +
- str(vim.current.range.start + 1) + ')')) - 1
-length = int(vim.eval('line2byte(' +
- str(vim.current.range.end + 2) + ')')) - offset - 2
+lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
# Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.
startupinfo = None
@@ -48,8 +45,8 @@
startupinfo.wShowWindow = subprocess.SW_HIDE
# Call formatter.
-p = subprocess.Popen([binary, '-offset', str(offset), '-length', str(length),
- '-style', style, '-cursor', str(cursor)],
+p = subprocess.Popen([binary, '-lines', lines, '-style', style,
+ '-cursor', str(cursor)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, startupinfo=startupinfo)
stdout, stderr = p.communicate(input=text)