以下代码片段来自 ocsigen 源。我不明白用两个参数调用的“int_of_string”:
try
let dppos = String.index ss':'
and len = String.length ss in
let host = String.sub ss 0 dppos
and port =
match String.sub ss (dppos+1) ((len - dppos) - 1) with
"*" -> None
| p -> Some (int_of_string "host" p)
in host, port
with
| Not_found -> ss, None
| Failure _ ->
raise (Config_file_error "bad port number")
我在顶层测试它,它通常会报告错误。
真挚地!