[Qt-interest] Converting first character of a char* from local charset
Thiago Macieira
thiago at kde.org
Fri May 27 23:10:56 CEST 2011
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.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110527/8f477883/attachment.bin
More information about the Qt-interest-old
mailing list