From 0161971c17102a24e529461fd49e9b12e9599835 Mon Sep 17 00:00:00 2001 From: hybrid Date: Wed, 27 Apr 2011 22:15:51 +0000 Subject: [PATCH] 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-e03cc46cb475 --- include/fast_atof.h | 117 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 14 deletions(-) diff --git a/include/fast_atof.h b/include/fast_atof.h index ed423903..79e560d2 100644 --- a/include/fast_atof.h +++ b/include/fast_atof.h @@ -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. /** \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 @@ -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 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) { @@ -145,7 +163,7 @@ inline s32 strtoul16(const char* in, const char** out=0) if (tmp= '0') && (*in <= '7')) + tmp = (unsignedValue << 3u) + (*in - '0'); + else + break; + if (tmp= '0') && ( *in <= '9' ) ) { @@ -211,14 +294,14 @@ inline f32 strtof10(const char* in, const char** out = 0) } //! 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. - \param[in] in: The string to convert. - \param[out] out: The resultant float will be written here. - \return A pointer to the first character in the string that wasn't - used to create the float value. + \param[in] in The string to convert. + \param[out] result The resultant float will be written here. + \return Pointer to the first character in the string that wasn't used + 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: // 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; const bool negative = ('-' == *in); - if (negative) + if (negative || ('+'==*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 -/** \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; - fast_atof_move(floatAsString, ret); + if (out) + *out=fast_atof_move(floatAsString, ret); + else + fast_atof_move(floatAsString, ret); return ret; }