|
@@ -59,69 +59,65 @@ const double fast_atof_table[16] = { // we write [16] here instead of [] to wo
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// Convert a string in decimal format to a number
|
|
// Convert a string in decimal format to a number
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline unsigned int strtoul10( const char* in, const char** out=0)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+unsigned int strtoul10( const char* in, const char** out=0) {
|
|
unsigned int value = 0;
|
|
unsigned int value = 0;
|
|
|
|
|
|
- bool running = true;
|
|
|
|
- while ( running )
|
|
|
|
- {
|
|
|
|
|
|
+ for ( ;; ) {
|
|
if ( *in < '0' || *in > '9' )
|
|
if ( *in < '0' || *in > '9' )
|
|
break;
|
|
break;
|
|
|
|
|
|
value = ( value * 10 ) + ( *in - '0' );
|
|
value = ( value * 10 ) + ( *in - '0' );
|
|
++in;
|
|
++in;
|
|
}
|
|
}
|
|
- if (out)*out = in;
|
|
|
|
|
|
+ if ( out ) {
|
|
|
|
+ *out = in;
|
|
|
|
+ }
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// Convert a string in octal format to a number
|
|
// Convert a string in octal format to a number
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline unsigned int strtoul8( const char* in, const char** out=0)
|
|
|
|
-{
|
|
|
|
- unsigned int value = 0;
|
|
|
|
-
|
|
|
|
- bool running = true;
|
|
|
|
- while ( running )
|
|
|
|
- {
|
|
|
|
- if ( *in < '0' || *in > '7' )
|
|
|
|
|
|
+inline
|
|
|
|
+unsigned int strtoul8( const char* in, const char** out=0) {
|
|
|
|
+ unsigned int value( 0 );
|
|
|
|
+ for ( ;; ) {
|
|
|
|
+ if ( *in < '0' || *in > '7' ) {
|
|
break;
|
|
break;
|
|
|
|
+ }
|
|
|
|
|
|
value = ( value << 3 ) + ( *in - '0' );
|
|
value = ( value << 3 ) + ( *in - '0' );
|
|
++in;
|
|
++in;
|
|
}
|
|
}
|
|
- if (out)*out = in;
|
|
|
|
|
|
+ if ( out ) {
|
|
|
|
+ *out = in;
|
|
|
|
+ }
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// Convert a string in hex format to a number
|
|
// Convert a string in hex format to a number
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline unsigned int strtoul16( const char* in, const char** out=0)
|
|
|
|
-{
|
|
|
|
- unsigned int value = 0;
|
|
|
|
-
|
|
|
|
- bool running = true;
|
|
|
|
- while ( running )
|
|
|
|
- {
|
|
|
|
- if ( *in >= '0' && *in <= '9' )
|
|
|
|
- {
|
|
|
|
|
|
+inline
|
|
|
|
+unsigned int strtoul16( const char* in, const char** out=0) {
|
|
|
|
+ unsigned int value( 0 );
|
|
|
|
+ for ( ;; ) {
|
|
|
|
+ if ( *in >= '0' && *in <= '9' ) {
|
|
value = ( value << 4u ) + ( *in - '0' );
|
|
value = ( value << 4u ) + ( *in - '0' );
|
|
- }
|
|
|
|
- else if (*in >= 'A' && *in <= 'F')
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (*in >= 'A' && *in <= 'F') {
|
|
value = ( value << 4u ) + ( *in - 'A' ) + 10;
|
|
value = ( value << 4u ) + ( *in - 'A' ) + 10;
|
|
- }
|
|
|
|
- else if (*in >= 'a' && *in <= 'f')
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (*in >= 'a' && *in <= 'f') {
|
|
value = ( value << 4u ) + ( *in - 'a' ) + 10;
|
|
value = ( value << 4u ) + ( *in - 'a' ) + 10;
|
|
}
|
|
}
|
|
- else break;
|
|
|
|
|
|
+ else {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
++in;
|
|
++in;
|
|
}
|
|
}
|
|
- if (out)*out = in;
|
|
|
|
|
|
+ if ( out ) {
|
|
|
|
+ *out = in;
|
|
|
|
+ }
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -129,17 +125,16 @@ inline unsigned int strtoul16( const char* in, const char** out=0)
|
|
// Convert just one hex digit
|
|
// Convert just one hex digit
|
|
// Return value is UINT_MAX if the input character is not a hex digit.
|
|
// Return value is UINT_MAX if the input character is not a hex digit.
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline unsigned int HexDigitToDecimal(char in)
|
|
|
|
-{
|
|
|
|
- unsigned int out = UINT_MAX;
|
|
|
|
- if (in >= '0' && in <= '9')
|
|
|
|
|
|
+inline
|
|
|
|
+unsigned int HexDigitToDecimal(char in) {
|
|
|
|
+ unsigned int out( UINT_MAX );
|
|
|
|
+ if ( in >= '0' && in <= '9' ) {
|
|
out = in - '0';
|
|
out = in - '0';
|
|
-
|
|
|
|
- else if (in >= 'a' && in <= 'f')
|
|
|
|
|
|
+ } else if ( in >= 'a' && in <= 'f' ) {
|
|
out = 10u + in - 'a';
|
|
out = 10u + in - 'a';
|
|
-
|
|
|
|
- else if (in >= 'A' && in <= 'F')
|
|
|
|
|
|
+ } else if ( in >= 'A' && in <= 'F' ) {
|
|
out = 10u + in - 'A';
|
|
out = 10u + in - 'A';
|
|
|
|
+ }
|
|
|
|
|
|
// return value is UINT_MAX if the input is not a hex digit
|
|
// return value is UINT_MAX if the input is not a hex digit
|
|
return out;
|
|
return out;
|
|
@@ -148,8 +143,8 @@ inline unsigned int HexDigitToDecimal(char in)
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// Convert a hex-encoded octet (2 characters, i.e. df or 1a).
|
|
// Convert a hex-encoded octet (2 characters, i.e. df or 1a).
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline uint8_t HexOctetToDecimal(const char* in)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+uint8_t HexOctetToDecimal(const char* in) {
|
|
return ((uint8_t)HexDigitToDecimal(in[0])<<4)+(uint8_t)HexDigitToDecimal(in[1]);
|
|
return ((uint8_t)HexDigitToDecimal(in[0])<<4)+(uint8_t)HexDigitToDecimal(in[1]);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -157,11 +152,12 @@ inline uint8_t HexOctetToDecimal(const char* in)
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// signed variant of strtoul10
|
|
// signed variant of strtoul10
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline int strtol10( const char* in, const char** out=0)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+int strtol10( const char* in, const char** out=0) {
|
|
bool inv = (*in=='-');
|
|
bool inv = (*in=='-');
|
|
- if (inv || *in=='+')
|
|
|
|
|
|
+ if ( inv || *in == '+' ) {
|
|
++in;
|
|
++in;
|
|
|
|
+ }
|
|
|
|
|
|
int value = strtoul10(in,out);
|
|
int value = strtoul10(in,out);
|
|
if (inv) {
|
|
if (inv) {
|
|
@@ -176,10 +172,9 @@ inline int strtol10( const char* in, const char** out=0)
|
|
// 0NNN - oct
|
|
// 0NNN - oct
|
|
// NNN - dec
|
|
// NNN - dec
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline unsigned int strtoul_cppstyle( const char* in, const char** out=0)
|
|
|
|
-{
|
|
|
|
- if ('0' == in[0])
|
|
|
|
- {
|
|
|
|
|
|
+inline
|
|
|
|
+unsigned int strtoul_cppstyle( const char* in, const char** out=0) {
|
|
|
|
+ if ('0' == in[0]) {
|
|
return 'x' == in[1] ? strtoul16(in+2,out) : strtoul8(in+1,out);
|
|
return 'x' == in[1] ? strtoul16(in+2,out) : strtoul8(in+1,out);
|
|
}
|
|
}
|
|
return strtoul10(in, out);
|
|
return strtoul10(in, out);
|
|
@@ -189,19 +184,19 @@ inline unsigned int strtoul_cppstyle( const char* in, const char** out=0)
|
|
// Special version of the function, providing higher accuracy and safety
|
|
// Special version of the function, providing higher accuracy and safety
|
|
// It is mainly used by fast_atof to prevent ugly and unwanted integer overflows.
|
|
// It is mainly used by fast_atof to prevent ugly and unwanted integer overflows.
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* max_inout=0)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* max_inout=0) {
|
|
unsigned int cur = 0;
|
|
unsigned int cur = 0;
|
|
uint64_t value = 0;
|
|
uint64_t value = 0;
|
|
|
|
|
|
- if ( *in < '0' || *in > '9' )
|
|
|
|
- throw std::invalid_argument(std::string("The string \"") + in + "\" cannot be converted into a value.");
|
|
|
|
|
|
+ if ( *in < '0' || *in > '9' ) {
|
|
|
|
+ throw std::invalid_argument( std::string( "The string \"" ) + in + "\" cannot be converted into a value." );
|
|
|
|
+ }
|
|
|
|
|
|
- bool running = true;
|
|
|
|
- while ( running )
|
|
|
|
- {
|
|
|
|
- if ( *in < '0' || *in > '9' )
|
|
|
|
|
|
+ for ( ;; ) {
|
|
|
|
+ if ( *in < '0' || *in > '9' ) {
|
|
break;
|
|
break;
|
|
|
|
+ }
|
|
|
|
|
|
const uint64_t new_value = ( value * 10 ) + ( *in - '0' );
|
|
const uint64_t new_value = ( value * 10 ) + ( *in - '0' );
|
|
|
|
|
|
@@ -240,11 +235,12 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int*
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// signed variant of strtoul10_64
|
|
// signed variant of strtoul10_64
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
-inline int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* max_inout = 0)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* max_inout = 0) {
|
|
bool inv = (*in == '-');
|
|
bool inv = (*in == '-');
|
|
- if (inv || *in == '+')
|
|
|
|
|
|
+ if (inv || *in == '+') {
|
|
++in;
|
|
++in;
|
|
|
|
+ }
|
|
|
|
|
|
int64_t value = strtoul10_64(in, out, max_inout);
|
|
int64_t value = strtoul10_64(in, out, max_inout);
|
|
if (inv) {
|
|
if (inv) {
|
|
@@ -263,8 +259,8 @@ inline int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* m
|
|
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
|
|
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
template <typename Real>
|
|
template <typename Real>
|
|
-inline const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true) {
|
|
Real f = 0;
|
|
Real f = 0;
|
|
|
|
|
|
bool inv = (*c == '-');
|
|
bool inv = (*c == '-');
|
|
@@ -272,42 +268,36 @@ inline const char* fast_atoreal_move(const char* c, Real& out, bool check_comma
|
|
++c;
|
|
++c;
|
|
}
|
|
}
|
|
|
|
|
|
- if ((c[0] == 'N' || c[0] == 'n') && ASSIMP_strincmp(c, "nan", 3) == 0)
|
|
|
|
- {
|
|
|
|
|
|
+ if ((c[0] == 'N' || c[0] == 'n') && ASSIMP_strincmp(c, "nan", 3) == 0) {
|
|
out = std::numeric_limits<Real>::quiet_NaN();
|
|
out = std::numeric_limits<Real>::quiet_NaN();
|
|
c += 3;
|
|
c += 3;
|
|
return c;
|
|
return c;
|
|
}
|
|
}
|
|
|
|
|
|
- if ((c[0] == 'I' || c[0] == 'i') && ASSIMP_strincmp(c, "inf", 3) == 0)
|
|
|
|
- {
|
|
|
|
|
|
+ if ((c[0] == 'I' || c[0] == 'i') && ASSIMP_strincmp(c, "inf", 3) == 0) {
|
|
out = std::numeric_limits<Real>::infinity();
|
|
out = std::numeric_limits<Real>::infinity();
|
|
if (inv) {
|
|
if (inv) {
|
|
out = -out;
|
|
out = -out;
|
|
}
|
|
}
|
|
c += 3;
|
|
c += 3;
|
|
- if ((c[0] == 'I' || c[0] == 'i') && ASSIMP_strincmp(c, "inity", 5) == 0)
|
|
|
|
- {
|
|
|
|
|
|
+ if ((c[0] == 'I' || c[0] == 'i') && ASSIMP_strincmp(c, "inity", 5) == 0) {
|
|
c += 5;
|
|
c += 5;
|
|
}
|
|
}
|
|
return c;
|
|
return c;
|
|
}
|
|
}
|
|
|
|
|
|
if (!(c[0] >= '0' && c[0] <= '9') &&
|
|
if (!(c[0] >= '0' && c[0] <= '9') &&
|
|
- !((c[0] == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9'))
|
|
|
|
- {
|
|
|
|
|
|
+ !((c[0] == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9')) {
|
|
throw std::invalid_argument("Cannot parse string "
|
|
throw std::invalid_argument("Cannot parse string "
|
|
"as real number: does not start with digit "
|
|
"as real number: does not start with digit "
|
|
"or decimal point followed by digit.");
|
|
"or decimal point followed by digit.");
|
|
}
|
|
}
|
|
|
|
|
|
- if (*c != '.' && (! check_comma || c[0] != ','))
|
|
|
|
- {
|
|
|
|
|
|
+ if (*c != '.' && (! check_comma || c[0] != ',')) {
|
|
f = static_cast<Real>( strtoul10_64 ( c, &c) );
|
|
f = static_cast<Real>( strtoul10_64 ( c, &c) );
|
|
}
|
|
}
|
|
|
|
|
|
- if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9')
|
|
|
|
- {
|
|
|
|
|
|
+ if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') {
|
|
++c;
|
|
++c;
|
|
|
|
|
|
// NOTE: The original implementation is highly inaccurate here. The precision of a single
|
|
// NOTE: The original implementation is highly inaccurate here. The precision of a single
|
|
@@ -358,30 +348,30 @@ inline const char* fast_atoreal_move(const char* c, Real& out, bool check_comma
|
|
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------
|
|
// The same but more human.
|
|
// The same but more human.
|
|
-inline ai_real fast_atof(const char* c)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+ai_real fast_atof(const char* c) {
|
|
ai_real ret(0.0);
|
|
ai_real ret(0.0);
|
|
fast_atoreal_move<ai_real>(c, ret);
|
|
fast_atoreal_move<ai_real>(c, ret);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-inline ai_real fast_atof( const char* c, const char** cout)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+ai_real fast_atof( const char* c, const char** cout) {
|
|
ai_real ret(0.0);
|
|
ai_real ret(0.0);
|
|
*cout = fast_atoreal_move<ai_real>(c, ret);
|
|
*cout = fast_atoreal_move<ai_real>(c, ret);
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-inline ai_real fast_atof( const char** inout)
|
|
|
|
-{
|
|
|
|
|
|
+inline
|
|
|
|
+ai_real fast_atof( const char** inout) {
|
|
ai_real ret(0.0);
|
|
ai_real ret(0.0);
|
|
*inout = fast_atoreal_move<ai_real>(*inout, ret);
|
|
*inout = fast_atoreal_move<ai_real>(*inout, ret);
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-} // end of namespace Assimp
|
|
|
|
|
|
+} //! namespace Assimp
|
|
|
|
|
|
-#endif
|
|
|
|
|
|
+#endif // __FAST_A_TO_F_H_INCLUDED__
|