Skip to content

Commit

Permalink
fixed bug: values enclosed by " in a single line without \n are now p…
Browse files Browse the repository at this point in the history
…arsed correctly

they are no longer identified as multiline values.

added new feature documentation to readme
  • Loading branch information
André Gawron committed Jan 27, 2011
1 parent 6b725dd commit a7fe061
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ A typical INI file might look like this:
; some comment on section1
var1 = foo
var2 = doodle
var3 = "multiline
also possible"

[section2]

; another comment
var1 = baz
var2 = shoodle


==== Format

This describes the elements of the INI file format:

* *Sections*: Section declarations start with '[' and end with ']' as in [section1] and [section2] above. And sections start with section declarations.
* *Parameters*: The "var1 = foo" above is an example of a parameter (also known as an item). Parameters are made up of a key ('var1'), equals sign ('='), and a value ('foo').
* *Parameters*: The "var1 = foo" above is an example of a parameter (also known as an item). Parameters are made up of a key ('var1'), equals sign ('='), and a value ('foo'). Multiline is support if value of parameter is enclosed by ".
* *Comments*: All the lines starting with a ';' are assumed to be comments, and are ignored.

==== Differences
Expand All @@ -64,7 +67,7 @@ This package supports the standard INI file format described in the *Format*
section above. The following differences are also supported:

* *Comments*: The comment character can be specified when an +IniFile+ is created. The comment character must be the first non-whitespace character on a line.
* *Backslashes*: Backslashes are not supported by this package.
* *Backslashes*: Backslashes are not supported by this package. But multilines are. Enclose the param's value by ".
* <b>Duplicate parameters</b>: Duplicate parameters are allowed in a single section. The last parameter value is the one that will be stored in the +IniFile+.
* <b>Duplicate sections</b>: Duplicate sections will be merged. Parameters duplicated between to the two sections follow the duplicate parameters rule above.
* *Parameters*: The parameter separator character can be specified when an +IniFile+ is created.
Expand Down
8 changes: 4 additions & 4 deletions lib/inifile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def initialize( filename, opts = {} )

@rgxp_comment = %r/\A\s*\z|\A\s*[#{@comment}]/
@rgxp_section = %r/\A\s*\[([^\]]+)\]/o
@rgxp_param = %r/\A([^#{@param}]+)#{@param}(.*)\z/
@rgxp_param = %r/\A([^#{@param}]+)#{@param}\s*"?([^"]*)"?\z/

@rgxp_multiline_start = %r/\A(?<param>[^#{@param}]+)#{@param}\s*?"+(?<value>.*)\z/
@rgxp_multiline_value = %r/\A(?<value>.*[^"])\z/
@rgxp_multiline_end = %r/\A(?<value>.*)"\z/
@rgxp_multiline_start = %r/\A(?<param>[^#{@param}]+)#{@param}\s*"+(?<value>[^"]*)?\z/
@rgxp_multiline_value = %r/\A(?<value>[^"]*)\z/
@rgxp_multiline_end = %r/\A(?<value>[^"]*)"\z/

parse
end
Expand Down
2 changes: 1 addition & 1 deletion test/data/multiline.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ three = 3
[section_three]
three = "hello
multiline"
other = stuff
other = "stuff"

[section_four]
four = "hello
Expand Down

0 comments on commit a7fe061

Please sign in to comment.