]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/lablgtk/lablgtk_20000829-0.1.0/applications/browser/text.ml
Initial revision
[helm.git] / helm / DEVEL / lablgtk / lablgtk_20000829-0.1.0 / applications / browser / text.ml
diff --git a/helm/DEVEL/lablgtk/lablgtk_20000829-0.1.0/applications/browser/text.ml b/helm/DEVEL/lablgtk/lablgtk_20000829-0.1.0/applications/browser/text.ml
new file mode 100644 (file)
index 0000000..729f310
--- /dev/null
@@ -0,0 +1,16 @@
+(* $Id$ *)
+
+open GEdit
+
+let line_start ?pos (text : GEdit.text) =
+  let pos = Gaux.default text#position ~opt:pos in
+  if pos = 0 then 0 else
+  let start = max 0 (pos-256) in
+  let buffer = text#get_chars ~start ~stop:pos in
+  try start + String.rindex buffer '\n' with Not_found -> 0
+
+let line_end ?pos (text : GEdit.text) =
+  let pos = Gaux.default text#position ~opt:pos in
+  if pos = text#length then text#length else
+  let buffer = text#get_chars ~start:pos ~stop:(min text#length (pos+256)) in
+  try pos + String.index buffer '\n' with Not_found -> text#length