(** Shared string utility functions. Centralizes whitespace handling to avoid duplication across prescan, lexer, and normalization modules. *) (** Strip leading whitespace (spaces and tabs). *) let lstrip s = let len = String.length s in let i = ref 0 in while !i < len && (s.[!i] = ' ' || s.[!i] = '\t') do incr i done; if !i = 0 then s else String.sub s !i (len - !i) (** Strip trailing whitespace (spaces, tabs, and carriage returns). *) let rstrip s = let len = String.length s in let i = ref (len - 1) in while !i >= 0 && (s.[!i] = ' ' || s.[!i] = '\t' || s.[!i] = '\r') do decr i done; if !i = len - 1 then s else String.sub s 0 (!i + 1) (** Strip both leading and trailing whitespace. *) let strip s = lstrip (rstrip s)