Skip to content
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

Add option to indent output in encoding/text #143

Merged
merged 1 commit into from
Jul 24, 2019

Conversation

martin-sucha
Copy link

Indented output is more readable.

Copy link
Contributor

@zombiezen zombiezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Here's some areas that I think can improve before we merge in:

encoding/text/marshal.go Outdated Show resolved Hide resolved
encoding/text/marshal_test.go Outdated Show resolved Hide resolved
encoding/text/marshal.go Outdated Show resolved Hide resolved
encoding/text/marshal.go Outdated Show resolved Hide resolved
iw.currentIndent--
}

func (iw *indentWriter) NewLine() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether the calling logic becomes simpler if NewLine and NewLineOrSpace were removed and the indentWriter would automatically apply this logic when a \n is encountered in its stream. WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would complicate the code instead of simplifying it. indentWriter would need to parse all the strings for \n, so the write couldn't just pass the buffer to the underlying writer. On top of that, we have NewLine which inserts a new line or nothing and NewLineOrSpace which inserts a new line or space. We need to distinguish those two cases, which would mean that we'd need to mark it somehow in the stream, complicating the parsing logic further. So I'd rather keep NewLine and NewLineOrSpace as they are now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged.

Indented output is more readable.
@zombiezen zombiezen merged commit def4a3e into capnproto:master Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants