Index: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs
===================================================================
--- tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs	(revision 344864)
+++ tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs	(working copy)
@@ -25,6 +25,7 @@
 using System.Runtime.InteropServices;
 using System.Xml.Linq;
 using System.Linq;
+using System.Text;
 
 namespace LLVM.ClangFormat
 {
@@ -293,8 +294,8 @@
             string text = view.TextBuffer.CurrentSnapshot.GetText();
             int start = view.Selection.Start.Position.GetContainingLine().Start.Position;
             int end = view.Selection.End.Position.GetContainingLine().End.Position;
-            int length = end - start;
-            
+            int charCount = end - start;
+
             // clang-format doesn't support formatting a range that starts at the end
             // of the file.
             if (start >= text.Length && text.Length > 0)
@@ -302,7 +303,13 @@
             string path = Vsix.GetDocumentParent(view);
             string filePath = Vsix.GetDocumentPath(view);
 
-            RunClangFormatAndApplyReplacements(text, start, length, path, filePath, options, view);
+            char[] chars = text.ToCharArray();
+            int offset = Encoding.UTF8.GetByteCount(chars, 0, start);
+            int length = Encoding.UTF8.GetByteCount(chars, 0, end) - offset;
+
+            byte[] bytes = Encoding.UTF8.GetBytes(text);
+
+            RunClangFormatAndApplyReplacements(bytes, offset, length, path, filePath, options, view);
         }
 
         /// <summary>
@@ -334,14 +341,16 @@
                 text += Environment.NewLine;
             }
 
-            RunClangFormatAndApplyReplacements(text, 0, text.Length, path, filePath, options, view);
+            byte[] bytes = Encoding.UTF8.GetBytes(text);
+
+            RunClangFormatAndApplyReplacements(bytes, 0, bytes.Length, path, filePath, options, view);
         }
 
-        private void RunClangFormatAndApplyReplacements(string text, int offset, int length, string path, string filePath, OptionPageGrid options, IWpfTextView view)
+        private void RunClangFormatAndApplyReplacements(byte[] bytes, int offset, int length, string path, string filePath, OptionPageGrid options, IWpfTextView view)
         {
             try
             {
-                string replacements = RunClangFormat(text, offset, length, path, filePath, options);
+                string replacements = RunClangFormat(bytes, offset, length, path, filePath, options);
                 ApplyClangFormatReplacements(replacements, view);
             }
             catch (Exception e)
@@ -366,7 +375,7 @@
         /// 
         /// Formats the text range starting at offset of the given length.
         /// </summary>
-        private static string RunClangFormat(string text, int offset, int length, string path, string filePath, OptionPageGrid options)
+        private static string RunClangFormat(byte[] bytes, int offset, int length, string path, string filePath, OptionPageGrid options)
         {
             string vsixPath = Path.GetDirectoryName(
                 typeof(ClangFormatPackage).Assembly.Location);
@@ -414,7 +423,7 @@
             // 2. We write everything to the standard output - this cannot block, as clang-format
             //    reads the full standard input before analyzing it without writing anything to the
             //    standard output.
-            process.StandardInput.Write(text);
+            process.StandardInput.BaseStream.Write(bytes, 0, bytes.Length);
             // 3. We notify clang-format that the input is done - after this point clang-format
             //    will start analyzing the input and eventually write the output.
             process.StandardInput.Close();
@@ -441,14 +450,19 @@
             if (replacements.Length == 0)
                 return;
 
+            string text = view.TextBuffer.CurrentSnapshot.GetText();
+            byte[] bytes = Encoding.UTF8.GetBytes(text);
+
             var root = XElement.Parse(replacements);
             var edit = view.TextBuffer.CreateEdit();
             foreach (XElement replacement in root.Descendants("replacement"))
             {
-                var span = new Span(
-                    int.Parse(replacement.Attribute("offset").Value),
-                    int.Parse(replacement.Attribute("length").Value));
-                edit.Replace(span, replacement.Value);
+                int offset = int.Parse(replacement.Attribute("offset").Value);
+                int length = int.Parse(replacement.Attribute("length").Value);
+                int startPosition = Encoding.UTF8.GetCharCount(bytes, 0, offset);
+                int charsToReplace = Encoding.UTF8.GetCharCount(bytes, offset, length);
+
+                edit.Replace(startPosition, charsToReplace, replacement.Value);
             }
             edit.Apply();
         }
