Bug 22187 – std.utf.byUTF lags behind underlying streams by one codepoint

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-08-06T17:06:53Z
Last change time
2024-12-01T16:39:09Z
Assigned to
No Owner
Creator
Holden Rohrer
Moved to GitHub: phobos#10471 →

Comments

Comment #0 by hr — 2021-08-06T17:06:53Z
I've got an InputRange!char which relies on user input from a C library (ncurses) and I wanted to iterate over it by dchar, so I used std.utf.byDchar (an alias for std.utf.byUTF!dchar) to wrap it, and I tried to terminate parsing when I received the newline character from the dchar stream. However, as a user, I had to input "my text\n[any other character]", while the underlying stream was able to stop at "my text\n". This seems to be because, after byUTF parses a codepoint (I think for char -> dchar, this is done in decodeFront) it uses popFront. This blocks until the user inputs another character. A simple way to fix this would be to store the front codepoint in a buffer and then, on subsequent runs, run popFront before reading the front codepoint. I may be able to help write a patch, but I'm not very familiar with all the language features std.utf uses.
Comment #1 by robert.schadek — 2024-12-01T16:39:09Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10471 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB