Commit Graph

193 Commits

Author SHA1 Message Date
ToruNiina
a76c5b385f refactor: replace mut-ref by take-and-move pattern 2024-03-20 22:40:46 +09:00
ToruNiina
1c2c710ec9 refactor: add comment 2024-01-04 21:18:47 +09:00
ToruNiina
8e214ec411 fix: limit value recursion in array/inl-table
to avoid parse_value/parse_array recursion
2024-01-04 20:45:35 +09:00
ToruNiina
dfc625f38d fix: #229 do not move temporary object 2023-10-10 23:49:51 +09:00
ToruNiina
ce941c318b fix: prevent windows minmax macro 2023-02-12 20:27:14 +09:00
ToruNiina
51587338cd fix: avoid overflow at postproc of the last loop 2023-02-12 18:50:46 +09:00
ToruNiina
418bfe9117 fix: cast explicitly to avoid un/signed comparison 2023-02-12 16:44:18 +09:00
ToruNiina
15346114ef fix: allow long binary integer and leading zeros 2023-02-12 16:22:23 +09:00
ToruNiina
f9b224c222 fix: reopening table implicitly defined by aot 2023-02-12 02:55:03 +09:00
Toru Niina
75daa2dde0
Merge pull request #208 from cxw42/issue199-nonutf-string
Fix address-sanitizer error when parsing literal strings having invalid UTF-8 characters
2023-02-11 23:46:53 +09:00
Chris White
a2f884b11e fix: parse_ml_literal_string() properly issues invalid-utf8 errors
Fix the same out-of-bounds read as in parse_literal_string().
2023-01-14 18:32:40 -05:00
Chris White
e3639d2bbc fix: parse_literal_string() properly issues invalid-utf8 errors
When creating the inner iterator, make sure it points into the same
vector as the outer iterator.  Otherwise, attempts to reset the iterator
wind up causing it to read out-of-bounds.

Fixes #199.
2023-01-14 18:32:40 -05:00
Chris White
626b0e6b95 fix: Correct function names in error messages
- fix error messages that referred to the wrong functions.
- parse_key(): remove "detail::" from the only error message that had
  it, for consistency with the other error messages in that function
2023-01-14 18:24:17 -05:00
Moritz Klammler
e064a5c371 Avoid unnecessary copies of parser result
The 'result' class has unwrap() and unwrap_err() member functions
overloaded for const lvalue and rvalue *this to avoid an unnecessarily
copying the to-be unwrapped object of its containing object is going to
be discarded anyway.  Alas, the parse() function toml/parser.hpp file
stored the parse result in a local `const` variable so, although the
unwrap call would have been the last use of the object in each case, the
unnecessary copy would still be made.  This patch removes the `const`
and adds a std::move() to actually benefit from the already implemented
optimization.
2022-09-29 19:02:52 +02:00
ToruNiina
b02aaed4fc fix: use fs::path, not fs::path::string() result 2022-09-29 21:28:35 +09:00
Lukáš Hrázký
6c2c804eff fix: Improve error handling of ifstream a bit
Set the exceptions mask so that exceptions are thrown when an I/O error
occurs. Also throw the same exception type when the opening fails.
2022-09-08 17:05:15 +02:00
Lukáš Hrázký
021d84623c chore: De-duplicate code for parse(std::filesystem::path) 2022-09-08 17:05:15 +02:00
Lukáš Hrázký
bf9c9d620d feat: Add a parse(FILE *) interface
The fstream classes are notorious for their non-existent error handling.

This adds a C-style fILE * IO (fopen(), etc.) alternative interface, so
that if a user needs reliable error handling, they can use that, albeit
more inconvenient, but more robust approach.
2022-09-08 17:05:11 +02:00
ToruNiina
8e95891af1 fix: report an error if a table is inserted to aot 2022-06-22 21:48:37 +09:00
ToruNiina
1ba3be38d0 fix: point the beginning of value in err msg 2022-06-08 01:33:10 +09:00
ToruNiina
12d0dbc6f4 fix: throw if number cannot be read losslessly
it throws when strtoll and strtof that are internally called fail
2022-06-08 00:39:04 +09:00
Giel van Schijndel
aff6f0f574 fix: don't force a copy of std::string fname when moving is an option
Taking this parameter by const reference forces us to copy it (because
we know we're going to store it). Taking it by r-value reference would
suggest that we _might_ take ownership over it and would also force the
user to make a copy if they wish to retain the original value.

Taking this parameter by value however clearly gives us ownership of its
content without forcing a copy if it's implicit conversion from
`const char*` or explicitly handed over to us by the user via std::move.
2022-06-02 14:39:10 +02:00
ToruNiina
dde351ea40 feat: add escape sequence of ESC
as an unreleased feature
2022-03-16 22:39:52 +09:00
ToruNiina
e60442c6db fix: check if re-open dotkey by a table
like:
```
a.b.c = "foo"
[a.b] # this is invalid
d = "bar"
```
2022-03-12 18:22:01 +09:00
ToruNiina
cc1cc27613 fix: disallow merging dotted key and inline table
current code mistakenly allows the following TOML file.
```toml
a.b = 42       # table "a" is defined here, implicitly
a = {c = 3.14} # table "a" is overwritten here
```
But we need to allow the following (structually similar) TOML file.
```toml
a.b = 42   # table "a" is defined here, implicitly
a.c = 3.14 # table "a" is merged with {c = 3.14}
```
To distinguish those, we check whether the current table is defined as
an inline table or via dotted key. If the table we are inserting is
defined via dotted key, we accept it and merge the table. If the table
being inserted is defined as an inline table, then we report an error.
2021-12-16 01:11:47 +09:00
ToruNiina
75e297eb47 fix: Merge branch 'check-datetime'
Briefly check if a given date and time is valid
2021-12-15 22:35:56 +09:00
ToruNiina
518e6d4ae2 feat: check date and time are valid or not 2021-12-15 00:31:41 +09:00
ToruNiina
db2aa55d20 fix: disallow null char at the end of input
since std::string and ""_toml literal actually does not include null
char, we don't need to check if the last char is null or not
2021-12-14 22:33:58 +09:00
ToruNiina
2e4c7fb95e fix: line-feed is not required at the EOF 2021-12-10 23:39:54 +09:00
Louis R. Marascio
21732fce45 Resolve g++ warning: free-nonheap-object
As described in issue #173, this warning is raised on various platforms
and in various build types. For example, g++ 11 in release mode will
cause this warning to be raised. This change fixes this warning.
2021-12-01 14:43:43 -06:00
ToruNiina
bcee9f25a2 fix: check if subtable key conflicts 2021-10-10 20:58:28 +09:00
Karl Nilsson
3eee515ce1 Spelling fixes 2021-08-27 19:52:45 -04:00
ToruNiina
ca9e36a484 fix: avoid duplicated-branches in result
when both two types are trivially destructible, both branches of cleanup
function results in the same code...
2021-07-01 00:46:56 +09:00
ToruNiina
0aa3773860 feat: add bare minimum utf8 seq validity check 2021-06-30 00:58:50 +09:00
ToruNiina
f09bd5b035 feat: easy check for datetime 2021-06-27 18:54:55 +09:00
ToruNiina
0dc51f95d9 fix: disallow trailing comma in an inline table 2021-06-27 18:54:28 +09:00
ToruNiina
1b7ca8566b fix: out_of_range with malformed toml file #164 2021-06-27 15:58:40 +09:00
Oliver Kahrmann
58542d36be
Preserve empty location for empty files
Without a region, error messages in exceptions are unable to print
a filename.

By retaining the location in a zero-length region and detecting this
when formatting the exception text it is possible to print the filename
and explicitly state that the file is completely empty.

Fixes #160
2021-05-25 20:52:33 +02:00
ToruNiina
c40e0dbd37 feat: use comment macro everywhere 2021-04-16 15:29:24 +09:00
ToruNiina
b924e70e3c feat: add a simple way to disable <filesystem>
As jwillikers pointed out in #150, there is a case where compiler
defines the corresponding feature test macro of <filesystem> but is
actually not available. The macro is a way to disable the feature
regardless of the status of feature test macro.
2021-03-25 11:44:11 +09:00
sneakypete81
08859c36d0
Fix typo in error message 2021-01-30 20:04:00 +00:00
ToruNiina
2e41a26785 Merge branch 'master' of github.com:ToruNiina/toml11 into master 2020-10-14 15:35:18 +09:00
ToruNiina
3d86f3a4e1 fix: avoid comment duplication in array of tables 2020-10-13 21:59:46 +09:00
Ivan Shynkarenka
5d8c573357 Fixed: Compile toml11 with MinGW cause error in <filesystem> #136 2020-10-03 23:16:58 +03:00
Ivan Shynkarenka
6e1e5ccd84 Fixed: Compile toml11 with MinGW cause error in <filesystem> #136 2020-10-03 23:06:47 +03:00
Ivan Shynkarenka
f2d9fd1d1f Fixed: Compile toml11 with MinGW cause error in <filesystem> #136 2020-10-03 22:36:59 +03:00
Ivan Shynkarenka
97c8cbdaf5 Fixed: Compile toml11 with MinGW cause error in <filesystem> #135 2020-10-02 19:10:04 +03:00
ToruNiina
670186fac7 Merge branch 'master' into allow-comment-before-comma 2020-09-19 18:10:45 +09:00
ToruNiina
003bc16c1b fix: skip the last zero in the file 2020-09-14 16:35:51 +09:00
ToruNiina
5f38127692 feat: allow comments before comma
replace ws by ws_comment_newline, as suggested.
discussed here: toml-lang/toml/issues/766
2020-08-16 11:03:58 +09:00