-
-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support and tests for multiline string encoding closes BurntSushi/toml#64 #65
Conversation
The build on Travis shows as failed but it seems the failure is on some other problem with an integer related test in the toml-test suite rather than on multiline strings. This is the error message -
|
This looks pretty good. I like the idea of using struct tags to do this. I'll review the commit/strategy in more detail (but at a glance, it looks good). Also, don't worry about the test failing. I think I know the problem---I'll get it straightened out. Thank you! |
A simpler implementation by using just a The previous implementation involved inserting a |
Hi - anything you'd like me to further check or clean-up on this? |
Has this effort fizzled? I am interested in this effort. As an aside, toml 0.4.0 has a syntax for multi line strings with the triple quotes that I think would map nicely to go's raw strings |
@treehau5 I will review this patch when I have some time. Personally, I'm somewhat opposed to adding a specific feature to support encoding multi-line strings. It seems like an API expansion that doesn't carry its weight. I think that requiring a custom encoder type for this unusual case would be a better option here (see #76). Note that this is only about encoding multi-line strings. This library already decodes them fine.
Raw string literals are purely syntactic in Go. You're already free to write strings in your code using whatever flavor of string literal is most convenient. |
Well I'd submitted this a while back because I ran into a use case where i needed long strings in the toml file to be readable by humans as well as machines. I usee my patched version while waiting for code review. JSON/yaml do a terrible job at readability which was the point behind toml development. Since mulit line strings are in the spec and improve readability, I'd love to have this in the core code. |
* Better logging for parser tests * Add spew to tests deps list
I'd like to see this feature in this package. Multiline strings are already part of the spec, also there is no other package that supports encoding strings as multi-line. |
I'll close this for now as I want to think of a better and more comprehensive solution for this rather than just "slap a struct tag on it". For example, if you decode a TOML multi-line string and encode it again then it should probably get encoded in the same way (i.e. as a multi-line string) without the need to add struct tags all over the place (although you should be able to override it as well). I have some ideas for a better solution, but I need to prototype a few things to see what does and doesn't work. And before I take this on I want to fix some other things, like supporting all of TOML 1.0, fixing a few remaining bugs, and improving the errors a wee bit. I absolutely want to add this feature on the short term (i.e. weeks, not years), just need to think of the best way to do it. You can track #64 for updates. |
I would like to propose a solution to encoding multiline strings and raw multiline strings that I had raised in the issue #64.
The proposal is to accept a new struct tag
modifier
which can take values of"multiline_string"
or"multiline_rawstring"
(exported as constantsMOD_MULTILINE_STRING
andMOD_MULTILINE_RAWSTRING
). On detecting presence of either of these modifiers, the type of the struct member is checked to confirm toreflect.String
and then theKey.String()
to which the modifier applies is inserted into a new map attribute of Encoder calledmodifiers
.In the functions that actually process and emit the key/value (in this case in
keyEqElement
) we can check for presence of the key being processed currently inmodifiers
and if the modifier isMOD_MULTILINE_STRING
orMOD_MULTILINE_RAWSTRING
, the element is written by the newwriteMultiLineString()
function. The reason for choosing the route of using an additional encoder attribute is thatKey
is currently implemented as[]string
which makes it difficult to store modifiers with theKey
itself.The same concept can be extended to any other output modifiers if necessary even in the future. I have added tests for multiline string encoding currently in the encode_test.go file (not yet figured out the toml-test package) and still need to writeup documentation but would like to seek review of the proposal