1

以下代码片段来自 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")

我在顶层测试它,它通常会报告错误。

真挚地!

4

1 回答 1

5

在该文件的顶部注意:

let blah_of_string f tag s =
  try
    f (String.remove_spaces s 0 ((String.length s) -1))
  with Failure _ -> raise (Ocsigen_config.Config_file_error
                             ("While parsing <"^tag^"> - "^s^
                                " is not a valid value."))

let int_of_string = blah_of_string int_of_string
let float_of_string = blah_of_string float_of_string

即根本不是Pervasives.int_of_string

于 2012-07-24T06:02:25.080 回答