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

Inaccurate comment of flush #51

Open
metab0t opened this issue Nov 19, 2021 · 1 comment
Open

Inaccurate comment of flush #51

metab0t opened this issue Nov 19, 2021 · 1 comment
Labels
Milestone

Comments

@metab0t
Copy link

metab0t commented Nov 19, 2021

The comment says that flush returns the number of bytes written to output buffer, but it returns the encoder. Is the comment outdated?

# Flush input buffer and convert it into output buffer
# Returns the number of bytes written to output buffer
function flush(s::StringEncoder)
s.cd == C_NULL && return s
# We need to retry several times in case output buffer is too small to convert
# all of the input. Even so, some incomplete sequences may remain in the input
# until more data is written, which will only trigger an error on close().
s.outbytesleft[] = 0
while s.outbytesleft[] < BUFSIZE
iconv!(s.cd, s.inbuf, s.outbuf, s.inbufptr, s.outbufptr, s.inbytesleft, s.outbytesleft)
write(s.stream, view(s.outbuf, 1:(BUFSIZE - Int(s.outbytesleft[]))))
end
s
end

@nalimilan
Copy link
Member

nalimilan commented Nov 26, 2021

Good catch. I've pushed a commit to remove that comment.

It would also make sense to return nothing rather than the stream, for consistency with what happens with IOStream in Base (though it's not documented). But changing this could break code that relies on it, so we'd better not do it until we tag a breaking release.

@nalimilan nalimilan added this to the 1.0 milestone Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants