breaking: Allow a Recorder to return an error
When a Recorder's Add method is called, allow it to return an error.
This is a breaking change to go-ini to support cases where a recorder
fails (e.g., when streaming key-value pairs). This can be used to break
out of a recording loop, though go-ini won't do anything to detect
specific cases of this.
When a recorder returns an error, the reader will always wrap that
error in a RecordingError.
Also add an Unwrap method to SyntaxError to support error unwrapping.
Use errors.Is when comparing error values
This is an update to use errors.Is where relevant so that error
wrapping is accounted for on cases like EOF.
Add CircleCI
Replaces Travis CI with CircleCI.
Closes #1.
Add go.mod, import line
Change-Id: I580b486f7a7dd92b0169e81b58f8d4f1e5f130f1
Update .gitreview
Change-Id: I3fa17cead5f47eed3a17ff66e1cb1d54c8d5c0c5
Fix format strings in tests
Identified by go vet:
- ini_test.go:37: missing argument for Errorf("%q"): format reads
arg 3, have only 2 args
- values_test.go:75: possible formatting directive in Log call
Change-Id: Ic11995579e36d0c0c9dcab3e64f224980902e624
Add comments for most exported names
Covers exported functions, types, variables, and constants.
This has one code change, in that it changes ReadINI to use
a bytes.Reader instead of a bytes.Buffer. This is primarily to avoid
giving the decoder only a reader type without also providing a writer,
but also because it just makes more sense.
Given that ReadINI is a pre-rewrite function kept around for
compatibility, it's not the most urgent function present. In spite of
that, test readers now include a bytes.Reader in addition to
bytes.Buffer, strings.Reader, and so on.
Change-Id: I6cc240f4ec1a9e57801d05d5f1eca8e65dad1b4b
Handle case where EOF is the first error seen
Previously, a completely empty stream (i.e., EOF on first read) would
result in an unexpected EOF. This should've been a non-error, since
reading nothing just means nothing's been decoded -- i.e., no values,
nothing wrong.
Change-Id: Id762e57eaa2d73c21633cca5081cf0c089730731
Add WithPrefix method to Values
Convenience function for looking up all keys with a prefix, since
that's a useful case.
Change-Id: I272f4d967f30801659a97f247bd277f757dc990d
Rewrite INI parser
- Now slightly more like Git's config behavior, but not quote.
All section names are now lowercase except for quoted sections (i.e.,
those in double quotes). Raw-quoted section names aren't supported
right now just because that seems like it may not be worth doing. By
default, readers are still case sensitive, but this can be changed to
force lower- or upper-casing of unquoted section names.
- Double-quotes are now escape-able with "" (e.g., "foo ""bar"" baz" is
a valid string).
- Keys may now contain a wider range of characters. This means that
some tests that were previously supposed to fail are no longer
allowed to fail.
- Although not yet something you can explicitly use, the INI decoder
does rely on io.Reader behavior to function. In addition, the decoder
has its own internal snapshot of the True string it'll use for bare
keys.
- Syntax errors are hopefully clearer and are explained where possible.
- Recorder is now used in place of map[string][]string when using the
Reader. Values is intended to be compatible with it.
- Where map[string][]string occurs elsewhere, Values is used, because
this provides a slightly easier means of interacting with the
resulting map.
- Hex codes are supported in double-quoted strings (this includes
section headers, which really need to be handled as a shared read
function or something).
- Coverage went up a bit, but this isn't really a measure of whether the
coverage is actually useful. So, grain of salt.
- The old ReadINI function still works more or less as intended. Its
behavior can be changed by modifying the DefaultReader.
Performance has probably gone down, and allocations probably went up
(still testing that), but overall it seems reasonable to take an
improvement in implementation over performance here, since it's not
like you're going to be mass-reading INI files somewhere.
Change-Id: Ie5ddae9266274f896db0c45ce5b377509b7ba804
Add .travis.yml file
To enable CI testing.
Change-Id: If19e3235c20e19cf92db0af8be481a35f78c9a86
Add raw quotes
These differ from Go's raw quotes in that you can escape the quote mark
by using `` -- this seemed reasonable enough to support.
Should consider adding the same escape sequence to regular quotes.
Ideally, this should be slightly less annoying than dealing with
escaping quotes and backslashes, but if your values have control
characters in them, you'll need to endure the regular quotes.
This breaks existing uses of `s in INI files, since those are currently
considered a regular, unquoted value. I'm personally OK with this
'cause it isn't an issue for me and nobody else is using this package
right now (that I'm aware of).
Change-Id: Ie9f52e645445bc0503c48728d005ac47f539a78d
Add support git-config like values
Basically, makes it possible to have lines like
[thing "section"]
key = value1
key = value2
That evaluates to thing.section.key = [value1, value2].
As a result, this changes the result format to being more like
url.Values or what have you where it's a map of strings to slices of
strings. So, you can define multiple values for something.
Fairly useful, but weird.
Change-Id: I0feed4827069bbc1a878cbdae8560c51b38189c7
Add .gitreview file
Change-Id: Ic2733d7481414dc000a5b1a2f43d228c927714bd
Allow periods in keys
Because for some reason they're not allowed and that's really weird.
Change-Id: Ibbb2360164a527580c7f81c667d122c16880da63