Add some more features from assimp patch. Also fix some things in the previously added methods.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3673 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
3d6b88ebda
commit
0161971c17
|
@ -111,6 +111,24 @@ inline s32 strtol10(const char* in, const char** out=0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Convert a hex-encoded character to an unsigned integer.
|
||||||
|
/** \param[in] in The digit to convert. Only digits 0 to 9 and chars A-F,a-f
|
||||||
|
will be considered.
|
||||||
|
\return The unsigned integer value of the digit. 0xffffffff if the input is
|
||||||
|
not hex
|
||||||
|
*/
|
||||||
|
inline u32 ctoul16(char in)
|
||||||
|
{
|
||||||
|
if (in >= '0' && in <= '9')
|
||||||
|
return in - '0';
|
||||||
|
else if (in >= 'a' && in <= 'f')
|
||||||
|
return 10u + in - 'a';
|
||||||
|
else if (in >= 'A' && in <= 'F')
|
||||||
|
return 10u + in - 'A';
|
||||||
|
else
|
||||||
|
return 0xffffffff;
|
||||||
|
}
|
||||||
|
|
||||||
//! Convert a simple string of base 16 digits into an unsigned 32 bit integer.
|
//! Convert a simple string of base 16 digits into an unsigned 32 bit integer.
|
||||||
/** \param[in] in: The string of digits to convert. No leading chars are
|
/** \param[in] in: The string of digits to convert. No leading chars are
|
||||||
allowed, only digits 0 to 9 and chars A-F,a-f are allowed. Parsing stops
|
allowed, only digits 0 to 9 and chars A-F,a-f are allowed. Parsing stops
|
||||||
|
@ -120,7 +138,7 @@ inline s32 strtol10(const char* in, const char** out=0)
|
||||||
\return The unsigned integer value of the digits. If the string specifies
|
\return The unsigned integer value of the digits. If the string specifies
|
||||||
too many digits to encode in an u32 then INT_MAX will be returned.
|
too many digits to encode in an u32 then INT_MAX will be returned.
|
||||||
*/
|
*/
|
||||||
inline s32 strtoul16(const char* in, const char** out=0)
|
inline u32 strtoul16(const char* in, const char** out=0)
|
||||||
{
|
{
|
||||||
if (!in)
|
if (!in)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +163,7 @@ inline s32 strtoul16(const char* in, const char** out=0)
|
||||||
if (tmp<unsignedValue)
|
if (tmp<unsignedValue)
|
||||||
{
|
{
|
||||||
unsignedValue=(u32)INT_MAX;
|
unsignedValue=(u32)INT_MAX;
|
||||||
overflow=false;
|
overflow=true;
|
||||||
}
|
}
|
||||||
if (!overflow)
|
if (!overflow)
|
||||||
unsignedValue = tmp;
|
unsignedValue = tmp;
|
||||||
|
@ -158,6 +176,71 @@ inline s32 strtoul16(const char* in, const char** out=0)
|
||||||
return unsignedValue;
|
return unsignedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Convert a simple string of base 8 digits into an unsigned 32 bit integer.
|
||||||
|
/** \param[in] in The string of digits to convert. No leading chars are
|
||||||
|
allowed, only digits 0 to 7 are allowed. Parsing stops at the first illegal
|
||||||
|
char.
|
||||||
|
\param[out] out (optional) If provided, it will be set to point at the
|
||||||
|
first character not used in the calculation.
|
||||||
|
\return The unsigned integer value of the digits. If the string specifies
|
||||||
|
too many digits to encode in an u32 then INT_MAX will be returned.
|
||||||
|
*/
|
||||||
|
inline u32 strtoul8(const char* in, const char** out=0)
|
||||||
|
{
|
||||||
|
if (!in)
|
||||||
|
{
|
||||||
|
if (out)
|
||||||
|
*out = in;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool overflow=false;
|
||||||
|
u32 unsignedValue = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
u32 tmp = 0;
|
||||||
|
if ((*in >= '0') && (*in <= '7'))
|
||||||
|
tmp = (unsignedValue << 3u) + (*in - '0');
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
if (tmp<unsignedValue)
|
||||||
|
{
|
||||||
|
unsignedValue=(u32)INT_MAX;
|
||||||
|
overflow=true;
|
||||||
|
}
|
||||||
|
if (!overflow)
|
||||||
|
unsignedValue = tmp;
|
||||||
|
++in;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out)
|
||||||
|
*out = in;
|
||||||
|
|
||||||
|
return unsignedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Convert a C-style prefixed string (hex, oct, integer) into an unsigned 32 bit integer.
|
||||||
|
/** \param[in] in The string of digits to convert. If string starts with 0x the
|
||||||
|
hex parser is used, if only leading 0 is used, oct parser is used. In all
|
||||||
|
other cases, the usual unsigned parser is used.
|
||||||
|
\param[out] out (optional) If provided, it will be set to point at the
|
||||||
|
first character not used in the calculation.
|
||||||
|
\return The unsigned integer value of the digits. If the string specifies
|
||||||
|
too many digits to encode in an u32 then INT_MAX will be returned.
|
||||||
|
*/
|
||||||
|
inline u32 strtoul_prefix(const char* in, const char** out=0)
|
||||||
|
{
|
||||||
|
if (!in)
|
||||||
|
{
|
||||||
|
if (out)
|
||||||
|
*out = in;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ('0'==in[0])
|
||||||
|
return ('x'==in[1] ? strtoul16(in+2,out) : strtoul8(in+1,out));
|
||||||
|
return strtoul10(in,out);
|
||||||
|
}
|
||||||
|
|
||||||
//! Converts a sequence of digits into a whole positive floating point value.
|
//! Converts a sequence of digits into a whole positive floating point value.
|
||||||
/** Only digits 0 to 9 are parsed. Parsing stops at any other character,
|
/** Only digits 0 to 9 are parsed. Parsing stops at any other character,
|
||||||
including sign characters or a decimal point.
|
including sign characters or a decimal point.
|
||||||
|
@ -213,12 +296,12 @@ inline f32 strtof10(const char* in, const char** out = 0)
|
||||||
//! Provides a fast function for converting a string into a float.
|
//! Provides a fast function for converting a string into a float.
|
||||||
/** This is not guaranteed to be as accurate as atof(), but is
|
/** This is not guaranteed to be as accurate as atof(), but is
|
||||||
approximately 6 to 8 times as fast.
|
approximately 6 to 8 times as fast.
|
||||||
\param[in] in: The string to convert.
|
\param[in] in The string to convert.
|
||||||
\param[out] out: The resultant float will be written here.
|
\param[out] result The resultant float will be written here.
|
||||||
\return A pointer to the first character in the string that wasn't
|
\return Pointer to the first character in the string that wasn't used
|
||||||
used to create the float value.
|
to create the float value.
|
||||||
*/
|
*/
|
||||||
inline const char* fast_atof_move(const char * in, f32& result)
|
inline const char* fast_atof_move(const char* in, f32& result)
|
||||||
{
|
{
|
||||||
// Please run this regression test when making any modifications to this function:
|
// Please run this regression test when making any modifications to this function:
|
||||||
// https://sourceforge.net/tracker/download.php?group_id=74339&atid=540676&file_id=298968&aid=1865300
|
// https://sourceforge.net/tracker/download.php?group_id=74339&atid=540676&file_id=298968&aid=1865300
|
||||||
|
@ -228,7 +311,7 @@ inline const char* fast_atof_move(const char * in, f32& result)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const bool negative = ('-' == *in);
|
const bool negative = ('-' == *in);
|
||||||
if (negative)
|
if (negative || ('+'==*in))
|
||||||
++in;
|
++in;
|
||||||
|
|
||||||
f32 value = strtof10(in, &in);
|
f32 value = strtof10(in, &in);
|
||||||
|
@ -255,12 +338,18 @@ inline const char* fast_atof_move(const char * in, f32& result)
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Convert a string to a floating point number
|
//! Convert a string to a floating point number
|
||||||
/** \param floatAsString: The string to convert.
|
/** \param floatAsString The string to convert.
|
||||||
|
\param out Optional pointer to the first character in the string that
|
||||||
|
wasn't used to create the float value.
|
||||||
|
\result Float value parsed from the input string
|
||||||
*/
|
*/
|
||||||
inline float fast_atof(const char* floatAsString)
|
inline float fast_atof(const char* floatAsString, const char** out=0)
|
||||||
{
|
{
|
||||||
float ret;
|
float ret;
|
||||||
fast_atof_move(floatAsString, ret);
|
if (out)
|
||||||
|
*out=fast_atof_move(floatAsString, ret);
|
||||||
|
else
|
||||||
|
fast_atof_move(floatAsString, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue