All pastes #445766 Raw Edit

irrlicht string

public cpp v1 · immutable
·published 2007-04-18 02:25 UTC
rendered paste body
	//! Constructs a string from an int	string(int number)	: array(0), allocated(0), used(0)	{		// store if negative and make positive		bool negative = false;		if (number < 0)		{			number *= -1;			negative = true;		}		// temporary buffer for 16 numbers		c8 tmpbuf[16];		tmpbuf[15] = 0;		u32 idx = 15;		// special case '0'		if (!number)		{			tmpbuf[14] = '0';			*this = &tmpbuf[14];			return;		}		// add numbers		while(number && idx)		{			--idx;			tmpbuf[idx] = (c8)('0' + (number % 10));			number /= 10;		}		// add sign		if (negative)		{			--idx;			tmpbuf[idx] = '-';		}		*this = &tmpbuf[idx];	}