Changeset 97
- Timestamp:
- 02/05/07 23:09:22 (2 years ago)
- Files:
-
- misc/configparse.d (modified) (4 diffs)
- misc/configparse.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
misc/configparse.d
r96 r97 21 21 */ 22 22 /++ 23 Config file parsing, in the style of Python's ConfigParser. 24 25 XXX: Add description of config file format. 23 Configuration file parsing, in the style of Python's ConfigParser. 24 25 Config files are divided into sections, which contain options. Section headers 26 are in the form "[section name]". Options may be in either the form "key=value" 27 or "key: value". A given line may only contain a single option or section 28 header. Whitespace is stripped from the beginnings and ends of keys and values. 29 30 Options existing before any section headers are said to be in the global 31 section. This is treated as a section named "General". It is entirely possible 32 to use config files only containing options that are in the global section, and 33 to write code which doesn't even seem to know about the ability to divide 34 options into sections. 35 36 Lines beginning with '#' or ';' are treated as comments and ignored. 26 37 +/ 27 38 module configparse; … … 33 44 import std.path : getBaseName, getDirName, join, pathsep; 34 45 import std.c.stdlib : getenv; 35 36 import std.stdio : writefln;37 46 38 47 /// Thrown when configparse is unable to parse a file. … … 313 322 return toReal(o); 314 323 } catch(ConvError e) { 315 throw new ConfigConvertError("Could not convert '"~o~"' to a real .");324 throw new ConfigConvertError("Could not convert '"~o~"' to a real in option "~section~"."~option~"."); 316 325 } 317 326 } … … 333 342 return false; 334 343 default: 335 throw new ConfigConvertError("Could not convert '"~o~"' to a boolean .");344 throw new ConfigConvertError("Could not convert '"~o~"' to a boolean in option "~section~"."~option~"."); 336 345 } 337 346 } misc/configparse.html
r96 r97 5 5 <h1>configparse</h1> 6 6 <!-- Generated by Ddoc from configparse.d --> 7 Config file parsing, in the style of Python's ConfigParser. 8 <br><br> 9 <b>XXX:</b><br> 10 Add description of config file format. 7 Configuration file parsing, in the style of Python's ConfigParser. 8 <br><br> 9 Config files are divided into sections, which contain options. Section headers 10 are in the form "[section name]". Options may be in either the form "key=value" 11 or "key: value". A given line may only contain a single option or section 12 header. Whitespace is stripped from the beginnings and ends of keys and values. 13 <br><br> 14 15 Options existing before any section headers are said to be in the global 16 section. This is treated as a section named "General". It is entirely possible 17 to use config files only containing options that are in the global section, and 18 to write code which doesn't even seem to know about the ability to divide 19 options into sections. 20 <br><br> 21 22 Lines beginning with '#' or ';' are treated as comments and ignored. 11 23 <br><br> 12 24
