     (cons replacements cursor)))
 
 (defun clang-format--replace (offset length &optional text)
-  (goto-char offset)
-  (delete-char length)
-  (when text
-    (insert text)))
+  (let ((start (byte-to-position (1+ offset)))
+        (end (byte-to-position (+ 1 offset length))))
+    (goto-char start)
+    (delete-region start end)
+    (when text
+      (insert text))))
 
 ;;;###autoload
-(defun clang-format-region (start end &optional style)
+(defun clang-format-region (char-start char-end &optional style)
   "Use clang-format to format the code between START and END according to STYLE.
 If called interactively uses the region or the current statement if there
 is no active region.  If no style is given uses `clang-format-style'."

                 "-output-replacements-xml"
                 "-assume-filename" (or (buffer-file-name) "")
                 "-style" style
                 "-offset" (number-to-string (1- start))
                 "-length" (number-to-string (- end start))
                 "-cursor" (number-to-string (1- (point)))))
          (setq stderr
                (with-temp-buffer
                  (insert-file-contents temp-file)

  (unless style
    (setq style clang-format-style))

  (let ((start (1- (position-bytes char-start)))
        (end (1- (position-bytes char-end)))
        (cursor (1- (position-bytes (point))))
        (temp-buffer (generate-new-buffer " *clang-format-temp*"))
        (temp-file (make-temp-file "clang-format")))
    (unwind-protect
        (let (status stderr operations)
