[OCaml] Org mode parser.
1
(** Shared string utility functions.
2
3
Centralizes whitespace handling to avoid duplication across prescan, lexer,
4
and normalization modules. *)
5
6
(** Strip leading whitespace (spaces and tabs). *)
7
let lstrip s =
8
let len = String.length s in
9
let i = ref 0 in
10
while !i < len && (s.[!i] = ' ' || s.[!i] = '\t') do
11
incr i
12
done;
13
if !i = 0 then s else String.sub s !i (len - !i)
14
15
(** Strip trailing whitespace (spaces, tabs, and carriage returns). *)
16
let rstrip s =
17
let len = String.length s in
18
let i = ref (len - 1) in
19
while !i >= 0 && (s.[!i] = ' ' || s.[!i] = '\t' || s.[!i] = '\r') do
20
decr i
21
done;
22
if !i = len - 1 then s else String.sub s 0 (!i + 1)
23
24
(** Strip both leading and trailing whitespace. *)
25
let strip s = lstrip (rstrip s)
26