Class ConfigParser.rawConfigParser


class rawConfigParser : object .. end
Primary interface class for configuarion files.

Usage example:


  let cp = new rawConfigParser in
  cp#readfile "app.conf";
  print_endline cp#get "sect1" "opt1";
  let calc = (cp#getint "sect1" "intopt1") + (cp#getint "sect1" "intopt2")
  


method maingetdata : string -> string -> string
method sections : string list
Returns a list of the sections in your configuration file. Never includes the always-present section DEFAULT.
method add_section : string -> unit
Adds a new empty section. Raises ConfigParser.DuplicateSectionError if the section already exists. cp#add_section "foo" will add the section named "foo" to the object cp.
method has_section : string -> bool
Find out whether the given section exists. cp#has_section "foo" will return true if that section is present.
method options : string -> string list
Returns a list of the names of all the options present in the given section.
method has_option : string -> string -> bool
Lets you determine whether a given options is present. Example: cp#has_option "sectname" "optname".
method readfile : string -> unit
Parses the file with the name given and adds its contents to this parser object. If any options are duplicated, the options in the file override the existing options.
method readchan : Pervasives.in_channel -> unit
Parses the input channel given and adds its contents to the object in the same manner as readfile.
method readstring : string -> unit
Parses the given string and adds its contents to the object in the same manner as readfile.
method get : ?default:string -> string -> string -> string
Returns the content of the requested option as a string. Example: cp#get "sectname" "optname". If optname cannot be found in the given section sectname, searches for that option name in the section DEFAULT. If it is still not found there and the optional default argument is given, return that; otherwise, raises Not_found. The other get* functions share this behavior.
method getint : ?default:int -> string -> string -> int
Returns the content of the requestied option as an int.
method getfloat : ?default:float -> string -> string -> float
Returns the content of the requested option as a float.
method getbool : ?default:bool -> string -> string -> bool
Returns the content of the requested option as a bool.
method items : string -> (string * string) list
Returns a list of (optionname, value) pairs representing the content of the given section.
method set : string -> string -> string -> unit
Sets the option to a new value, replacing an existing one if it exists. Example: cp#set "sectname" "optname" "newvalue"
method to_string : string
Returns a string that could be later parsed back into the content represented by this object.
method writefile : string -> unit
Writes the content of the object out to the given filename.
method writechan : Pervasives.out_channel -> unit
Writes the content of the object to the given output channel.
method remove_option : string -> string -> bool
Removes the given option. Returns true if something was removed; false otherwise. Example: cp#remove_option "sectname" "optname"
method remove_section : string -> bool
Removes the entire given section. Cannot be used to remove the DEFAULT section. Returns true if something was removed; false otherwise.
method optionxform : string -> string
Used to convert an option string to a standardized format. This is intended to be overridden in subclasses. Note that the implementation must return the same value each time it is called, and calling it with an already-converted value must return that same value. The default implementation is method optionxform oname = String.lowercase oname.