[Qt-interest] Converting first character of a char* from local charset
Nikos Chantziaras
realnc at arcor.de
Sat May 28 08:22:28 CEST 2011
On 05/28/2011 12:10 AM, Thiago Macieira wrote:
> On Friday, 27 de May de 2011 20:02:28 Nikos Chantziaras wrote:
>> It's for a charset-aware getch() implementation (same semantics as the
>> one from curses.) This version however, needs to read the first
>> character (which can be multi-byte) from the input buffer, not just the
>> first byte.
>>
>>> Try converting the first 32 bytes to QString and then get the first one
>>> out of the string.
>>
>> This won't work, because then I'd have no idea how many bytes the
>> character used. getch() needs to remove the bytes that were read from
>> the buffer, so that the next call won't read them again.
>>
>> Anyway, I guess my question was answered. There's no routine in Qt that
>> does this directly, so I guess I'll have to live with it. Fortunately,
>> the code is in a place that isn't performance-critical. Although a
>> getch() is needed, it's used rarely; a getstr()-like routine is used far
>> more often, where I simply convert the whole buffer.
>
> Then read the full line and keep it in memory. Return one Unicode character at
> a time, until the line buffer is empty. Then you read more.
>
> Unix terminals are line-buffered by default anyway, so you receive data in
> line-sized chunks.
It's not possible, because this would lead to wasting memory. The
buffers are managed externally. There can be dozens of them, and each
one can disappear without warning. You don't know the specifics of the
application and therefore making such suggestions isn't really useful.
But thanks for trying anyway :-) The application is a VM, running
byte-code programs in it. Obviously, those programs expect a certain
interface from the VM. It's that interface I'm implementing. What
algorithms those programs use to access data is not up to me to decide.
All I can do is choose the fastest way to implement an operation, and
in this case, I simply lucked out.
More information about the Qt-interest-old
mailing list