remove unnecessary str pointer and rename arg to be clearer

This commit is contained in:
Jett 2016-10-16 17:35:27 -05:00
parent 7f5b228e2c
commit 973ee97a93
2 changed files with 25 additions and 27 deletions

View File

@ -8815,41 +8815,40 @@ basic_json_parser_63:
@tparam T a is_floating_point type @tparam T a is_floating_point type
@param[in] st the string we will parse @param[in] str the string we will parse
@return the floating point number @return the floating point number
*/ */
template <typename T, typename = typename std::enable_if< template <typename T, typename = typename std::enable_if<
std::is_floating_point<T>::value>::type> std::is_floating_point<T>::value>::type>
T strtox(const char *st) const T strtox(const char *str) const
{ {
constexpr std::array<long double, 9> powerof10 { constexpr std::array<long double, 9> powerof10 {
{1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L}
}; };
T result = 0; T result = 0;
const char *fst = st; char cp = *str;
char cp = *fst;
int exp = 0; // exponent int exp = 0; // exponent
{ {
const bool negative_sign = cp == '-'; const bool negative_sign = cp == '-';
if (cp == '-' or cp == '+') if (cp == '-' or cp == '+')
{ {
++fst; ++str;
} }
// read in fractional part of number, until an 'e' is reached. // read in fractional part of number, until an 'e' is reached.
// count digits after decimal point. // count digits after decimal point.
while (nl_isdigit(cp = *fst)) while (nl_isdigit(cp = *str))
{ {
result = result * 10 + (cp - '0'); result = result * 10 + (cp - '0');
++fst; ++str;
} }
if (cp == '.') if (cp == '.')
{ {
while (nl_isdigit(cp = *++fst)) while (nl_isdigit(cp = *++str))
{ {
result = result * 10 + (cp - '0'); result = result * 10 + (cp - '0');
--exp; --exp;
@ -8864,15 +8863,15 @@ basic_json_parser_63:
} }
// read in explicit exponent and calculate real exponent. // read in explicit exponent and calculate real exponent.
if (*fst == 'e' or *fst == 'E') if (*str == 'e' or *str == 'E')
{ {
cp = *++fst; cp = *++str;
bool negative_exp = cp == '-'; // read in exponent sign (+/-) bool negative_exp = cp == '-'; // read in exponent sign (+/-)
bool plus_or_minus = false; bool plus_or_minus = false;
if (cp == '-' or cp == '+') if (cp == '-' or cp == '+')
{ {
cp = *++fst; cp = *++str;
plus_or_minus = true; plus_or_minus = true;
} }
@ -8881,10 +8880,10 @@ basic_json_parser_63:
{ {
if (plus_or_minus) if (plus_or_minus)
{ {
*--fst; *--str;
} }
*--fst; *--str;
goto skip_loop; goto skip_loop;
} }
@ -8903,7 +8902,7 @@ basic_json_parser_63:
break; break;
} }
cp = *++fst; cp = *++str;
} }
skip_loop: skip_loop:
exp += negative_exp ? -count : count; exp += negative_exp ? -count : count;

View File

@ -8112,7 +8112,7 @@ class basic_json
@tparam T a is_floating_point type @tparam T a is_floating_point type
@param[in] st the string we will parse @param[in] str the string we will parse
@return the floating point number @return the floating point number
*/ */
@ -8125,28 +8125,27 @@ class basic_json
}; };
T result = 0; T result = 0;
const char *fst = st; char cp = *str;
char cp = *fst;
int exp = 0; // exponent int exp = 0; // exponent
{ {
const bool negative_sign = cp == '-'; const bool negative_sign = cp == '-';
if (cp == '-' or cp == '+') if (cp == '-' or cp == '+')
{ {
++fst; ++str;
} }
// read in fractional part of number, until an 'e' is reached. // read in fractional part of number, until an 'e' is reached.
// count digits after decimal point. // count digits after decimal point.
while (nl_isdigit(cp = *fst)) while (nl_isdigit(cp = *str))
{ {
result = result * 10 + (cp - '0'); result = result * 10 + (cp - '0');
++fst; ++str;
} }
if (cp == '.') if (cp == '.')
{ {
while (nl_isdigit(cp = *++fst)) while (nl_isdigit(cp = *++str))
{ {
result = result * 10 + (cp - '0'); result = result * 10 + (cp - '0');
--exp; --exp;
@ -8161,15 +8160,15 @@ class basic_json
} }
// read in explicit exponent and calculate real exponent. // read in explicit exponent and calculate real exponent.
if (*fst == 'e' or *fst == 'E') if (*str == 'e' or *str == 'E')
{ {
cp = *++fst; cp = *++str;
bool negative_exp = cp == '-'; // read in exponent sign (+/-) bool negative_exp = cp == '-'; // read in exponent sign (+/-)
bool plus_or_minus = false; bool plus_or_minus = false;
if (cp == '-' or cp == '+') if (cp == '-' or cp == '+')
{ {
cp = *++fst; cp = *++str;
plus_or_minus = true; plus_or_minus = true;
} }
@ -8178,10 +8177,10 @@ class basic_json
{ {
if (plus_or_minus) if (plus_or_minus)
{ {
*--fst; *--str;
} }
*--fst; *--str;
goto skip_loop; goto skip_loop;
} }
@ -8200,7 +8199,7 @@ class basic_json
break; break;
} }
cp = *++fst; cp = *++str;
} }
skip_loop: skip_loop:
exp += negative_exp ? -count : count; exp += negative_exp ? -count : count;