Source

ocaml-indent / pos.ml

The default branch has multiple heads

Diff from to
                pos_cnum = 0 }
 
   let columns p = p.pos_cnum - p.pos_bol
+
+  (* ignore filename *)
+  let compare p1 p2 = compare p1.pos_cnum p2.pos_cnum
+
+  let compare_lines_cols p (lines, cols) =
+    match Pervasives.compare p.pos_lnum lines with
+    | -1 -> -1
+    | 1 -> 1
+    | 0 ->
+        let p_cols = p.pos_cnum - p.pos_bol in
+        Pervasives.compare p_cols cols
+    | _ -> assert false
 end
 
 module Region = struct
   let move_chars diff (p,p') = 
     { p  with pos_cnum = p .pos_cnum + diff },
     { p' with pos_cnum = p'.pos_cnum + diff } 
+
+  let contain (start, end_) pos = 
+    match Position.compare start pos, Position.compare pos end_ with
+    | (-1 | 0), (-1 | 0) -> `In
+    | _, 1 -> `Out_right
+    | -1, _ -> `Out_left
+    | _ -> assert false
+
+  let contain_lines_cols (start, end_) l_c = 
+    match Position.compare_lines_cols start l_c, Position.compare_lines_cols end_ l_c with
+    | (-1 | 0), (1 | 0) -> `In
+    | _, -1 -> `Out_right
+    | -1, _ -> `Out_left
+    | _ -> assert false
 end