let check_str_bounds loc ~pos ~len (str : bigstring) = if pos < 0 then invalid_arg (loc ^ ": pos < 0"); if len < 0 then invalid_arg (loc ^ ": len < 0"); let str_len = Array1.dim str in let pos_len = pos + len in if pos_len > str_len then invalid_arg (loc ^ ": pos + len > str_len"); pos_len - 1