rex-core/src/str.cpp
// TODO: use Res instead of boolean pointer
use Res instead of boolean pointer
use Res instead of boolean pointer
double
	str_to_double(const Str& self, bool* succeeded)
	{
		if (self.count == 0)
		{
			*succeeded = false;
			return 0;
		}
		sz i = 0;
		int sign = 1;
		if (self[0] == '-')
		{
			if (self.count == 1)
			{
				*succeeded = false;
				return 0;
			}
			sign = -1;
			i = 1;
		}
		double value = 0.0;
		double multiplier = 10.0;
		for (; i < self.count; ++i)
		{
			if (self[i] == '.')
			{
				multiplier = 1.0 / multiplier;
				continue;
			}
			else if (self[i] == 'e')
			{
				bool result = false;
				auto exp = str_to_int(rc::str_from(self.ptr + i + 1, self.ptr + self.count, frame_allocator()), &result);
				if (result == false)
				{
					*succeeded = false;
					return 0;
				}
				if (exp < 0)
				{
					for (auto i = exp; i < 0; ++i)
						value *= 0.1;
				}
				else if (exp > 0)
				{
					for (auto i = 0; i < exp; ++i)
						value *= 10;
				}
				break;
			}
			else if (self[i] >= '0' && self[i] <= '9')
			{
				if (multiplier > 1.0)
				{
					value *= multiplier;
					value += self[i] - '0';
				}
				else
				{
					value += ((self[i] - '0') * multiplier);
					multiplier *= (0.1);
				}
			}
			else
			{
				*succeeded = false;
				return 0;
			}
		}
		*succeeded = true;
		return sign * value;
	}
double str_to_double ( const Str & self , bool * succeeded ) { if ( self . count == 0 ) { * succeeded = false ; return 0 ; } sz i = 0 ; int sign = 1 ; if ( self [ 0 ] == ' ' ) { if ( self . count == 1 ) { * succeeded = false ; return 0 ; } sign = -1 ; i = 1 ; } double value = 0.0 ; double multiplier = 10.0 ; for ( ; i < self . count ; ++ i ) { if ( self [ i ] == ' ' ) { multiplier = 1.0 / multiplier ; continue ; } else if ( self [ i ] == ' ' ) { bool result = false ; auto exp = str_to_int ( rc :: str_from ( self . ptr + i + 1 , self . ptr + self . count , frame_allocator ( ) ) , & result ) ; if ( result == false ) { * succeeded = false ; return 0 ; } if ( exp < 0 ) { for ( auto i = exp ; i < 0 ; ++ i ) value *= 0.1 ; } else if ( exp > 0 ) { for ( auto i = 0 ; i < exp ; ++ i ) value *= 10 ; } break ; } else if ( self [ i ] >= ' ' && self [ i ] <= ' ' ) { if ( multiplier > 1.0 ) { value *= multiplier ; value += self [ i ] - ' ' ; } else { value += ( ( self [ i ] - ' ' ) * multiplier ) ; multiplier *= ( 0.1 ) ; } } else { * succeeded = false ; return 0 ; } } * succeeded = true ; return sign * value ; }
TODO: use Res instead of boolean pointer
TODO : use Res instead of boolean pointer