struct
type _ t =
| Int: int -> int t
| String: string -> string t
| Bool: bool -> bool t
let to_shell: type a. a t -> string =
function
| Int i -> sprintf "%d" i
| String s ->
with_buffer begin fun str ->
String.iter s ~f:(fun c ->
Char.code c |> sprintf "%03o" |> str
);
end |> fst
| Bool true -> "true"
| Bool false -> "false"
module String = struct
let easy_to_escape s =
String.for_all s
~f:(function
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '-' | '_' | '*' | '&' | '^'
| '=' | '+' | '%' | '$' | '"' | '\'' | '/' | '#' | '@' | '!' | ' '
| '~' | '`' | '\\' | '|' | '?' | '>' | '<' | '.' | ',' | ':' | ';'
| '{' | '}' | '(' | ')' | '[' | ']' -> true
| other -> false)
let impossible_to_escape_for_variable = String.exists ~f:((=) '\x00')
end
end