aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ide/ideutils.ml9
-rw-r--r--ide/ideutils.mli2
2 files changed, 11 insertions, 0 deletions
diff --git a/ide/ideutils.ml b/ide/ideutils.ml
index 1464181f4..1d3088a64 100644
--- a/ide/ideutils.ml
+++ b/ide/ideutils.ml
@@ -403,3 +403,12 @@ let browse_keyword prerr text =
let u = Lazy.force url_for_keyword text in
browse prerr (doc_url() ^ u)
with Not_found -> prerr ("No documentation found for \""^text^"\".\n")
+
+(* This is missing in lablgtk2. This one is inefficient, n^2 I guess *)
+let glib_utf8_pos_to_offset s ~off =
+ let n = if Glib.Utf8.validate s then Glib.Utf8.length s else 0 in
+ let rec find i =
+ if i >= n then i
+ else if Glib.Utf8.offset_to_pos s ~pos:0 ~off:i >= off then i
+ else find (i+1)
+ in find 0
diff --git a/ide/ideutils.mli b/ide/ideutils.mli
index cc34a355a..56183c520 100644
--- a/ide/ideutils.mli
+++ b/ide/ideutils.mli
@@ -91,3 +91,5 @@ val io_read_all : Glib.Io.channel -> string
val run_command :
(string -> unit) -> (Unix.process_status -> unit) -> string -> unit
+
+val glib_utf8_pos_to_offset : string -> off:int -> int