There is nothing really wrong with the original code, though it might be a good idea to avoid conditional compilation and just make the buffer big enough for a stringified 64-bit unsigned. It might also be useful to use the C99 function
swprintf() instead of
snprintf.
torleif wrote:Another is simply to rip through the pointers and append it to the end str:
example:
Code: Select all
irr::core::stringw ulTOstringw(u32 * mchar)
{
core::stringw ret;
while (char != 0) {
ret.append((u16)mchar++)
}
return ret;
}
Uh, yeah. that will not do what you, or the original poster, want. First off, it would never compile, and if you fixed that, it would loop until you ran out of memory, an access violation, or
mchar wrapped around to 0. IMO, the original posters code is much better.
If you really wanted to write your own, you would typically mod by 10 and convert the result from an integer 0-9 to a character '0'-'9', then divide the remainder by 10. Append the character, and repeat until the remainder is 0. Once you have the resulting string, you have to reverse it. There are other ways, but this is the most obvious.
Travis