fix some issues with Assimp_itoa10.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@725 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-05-14 12:27:29 +00:00
parent 6079125444
commit a44e065f58
1 changed files with 13 additions and 12 deletions

View File

@ -60,36 +60,37 @@ namespace Assimp {
* @param out Output buffer * @param out Output buffer
* @param max Maximum number of characters to be written, including '\0' * @param max Maximum number of characters to be written, including '\0'
* @param number Number to be written * @param number Number to be written
* @return Number of bytes written. Including the terminal zero. * @return Number of bytes written.
*/ */
inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number) inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number)
{ {
ai_assert(NULL != out); ai_assert(NULL != out);
static const char lookup[] = {'0','1','2','3','4','5','6','7','8','9'};
// write the unary minus to indicate we have a negative number // write the unary minus to indicate we have a negative number
unsigned int written = 1u; unsigned int written = 1u;
if (number < 0 && written < max) if (number < 0 && written < max) {
{
*out++ = '-'; *out++ = '-';
++written; ++written;
number = -number;
} }
// We begin with the largest number that is not zero. // We begin with the largest number that is not zero.
int32_t cur = 1000000000; // 2147483648 int32_t cur = 1000000000; // 2147483648
bool mustPrint = false; bool mustPrint = false;
while (cur > 0 && written <= max) while (written < max) {
{
unsigned int digit = number / cur; const unsigned int digit = number / cur;
if (digit > 0 || mustPrint || 1 == cur) if (mustPrint || digit > 0 || 1 == cur) {
{ // print all future zeroes from now
// print all future zero's from now
mustPrint = true; mustPrint = true;
*out++ = lookup[digit];
*out++ = '0'+digit;
++written; ++written;
number -= digit*cur; number -= digit*cur;
if (1 == cur) {
break;
}
} }
cur /= 10; cur /= 10;
} }