Re: Antonym to _tcsnextc()



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



.



Relevant Pages