Re: Antonym to _tcsnextc()
- From: "Eugene Gershnik" <gershnik@xxxxxxxxxxx>
- Date: Wed, 14 Jun 2006 04:14:14 GMT
Frank A. Uepping wrote:
Thanks, but this is not what I mean; I was a little imprecise.
[A better place to ask would be one of VC groups]
I am looking for a function (I will name it _tcsfoo()) that takes the
result of _tcsnextc() and returns the string representation for it.
There is no such function but it is easy to write your own. One way to write
it is something like this (warning: untested code)
struct char_str
{
char buf[2];
};
struct wchar_str
{
wchar_t buf[2];
};
struct mbchar_str
{
unsigned char buf[sizeof(unsigned)];
};
mbchar_str mbcsfoo(unsigned val)
{
mbchar_str ret = {0};
unsigned char * buf = &ret.buf;
int i = (sizeof(val) - 1) * CHAR_BIT;
for( ; i >= 0; i -= CHAR_BIT)
{
const unsigned char c = unsigned char(val >> i);
if (c != 0)
*buf++ = c;
}
return ret;
}
char_str strfoo(unsigned val)
{
char_str ret = {0};
ret.buf[0] = char(val);
return ret;
}
wchar_str wcsfoo(unsigned val)
{
wchar_str ret = {0};
ret.buf[0] = wchar_t(val);
return ret;
}
Then add the usual #defines for t versions.
--
Eugene
http://www.gershnik.com
.
- Prev by Date: Limiting the growth of system cache ?
- Next by Date: Re: NTFS file times and ordering
- Previous by thread: Limiting the growth of system cache ?
- Next by thread: Re: How to Canonicalize a filename using the Win32 API
- Index(es):
Relevant Pages
|
|