|
|
|
date: Fri, 15 Aug 2008 20:20:03 -0700,
group: microsoft.public.win32.programmer.ui
back
Re: Single byte to double byte
Greetings,
1) I want to do a file read in which I read single byte but store in a
wchar_t buffer. Is there a way to do a direct read that will fill a
wchar_t buffer with the results of my single byte read? I do not need to do
any code page conversion (for my purposes, the value of the single byte read
can be used as is in the wchar_t buffer.)
2) Similarly, I have a very long single byte string in a buffer in memory.
What is the fastest way to get that into a wchar_t-defined buffer?
Thanks in advance,
Tony Duff
"Mihai N." wrote:
> > 1) I want to do a file read in which I read single byte but store in a
> > double byte buffer. Is there a way to do a direct read that will fill a
> > double-byte buffer with the results of my single byte read?
> >
> > 2) Similarly, I have a very long single byte string in a buffer in memory.
> > What is the fastest way to get that into a double-byte-defined buffer?
>
>
> What do you mean by "double byte buffer"?
>
> UTF-16? that would be "Unicode UTF-16 buffer" or "wide character buffer"
> or something like that. In this case you will have to know the code page
> of the "single byte string" and convert using MultiByteToWideChar.
>
> "Double byte" has a very clear meaning (refers to a certain types of
> encodings, used for Chinese, Japanese, Korean), and it is confusing
> if used otherwise.
>
> Sorry, just guessing, but asking the question helps a lot.
>
>
> --
> Mihai Nita [Microsoft MVP, Visual C++]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email
>
date: Sat, 16 Aug 2008 07:03:01 -0700
author: Tony Duff
Re: Single byte to double byte
> 1) I want to do a file read in which I read single byte but store in a
> wchar_t buffer. Is there a way to do a direct read that will fill a
> wchar_t buffer with the results of my single byte read? I do not need to
> do any code page conversion (for my purposes, the value of the single byte
> read can be used as is in the wchar_t buffer.)
That only works without conversion only if all characters in the input buffer
are plain ASCII (below 128). So no accented characters, smart quotes,
copyright or registration marks, etc.
And you are sure that software will never have to deal with that kind of data
:-)
If that is the case, I don't know of any way to achieve that, except the dumb
copy char by char with cast to wchar_t.
If you read from a file, you might avoid reading it in memory by
memory-mapping it. But you have to measure the performance to see it it
is better.
> 2) Similarly, I have a very long single byte string in a buffer in memory.
> What is the fastest way to get that into a wchar_t-defined buffer?
With the same warnings as as above about ASCII,
char by char copy with cast to wchar_t.
I can't think of any other way.
You might also try WideChartoMultiByte with code page 20127 (ASCII), see if
the OS can do something better (although I doubt) it can beat just a copy.
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Sat, 16 Aug 2008 22:48:51 -0700
author: Mihai N.
|
|