| 135 | |
| 136 | template <typename Traits> |
| 137 | bool StringToIntegerInternal(const std::string& string, |
| 138 | typename Traits::IntType* number) { |
| 139 | using IntType = typename Traits::IntType; |
| 140 | using LongType = typename Traits::LongType; |
| 141 | |
| 142 | Traits::TypeCheck(); |
| 143 | |
| 144 | if (string.empty() || base::IsAsciiWhitespace(string[0])) { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | errno = 0; |
| 149 | char* end; |
| 150 | LongType result = Traits::Convert(string.data(), &end, 0); |
| 151 | if (Traits::IsNegativeOverflow(result) || |
| 152 | result > std::numeric_limits<IntType>::max() || |
| 153 | errno == ERANGE || |
| 154 | end != string.data() + string.length()) { |
| 155 | return false; |
| 156 | } |
| 157 | *number = static_cast<IntType>(result); |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | } // namespace |
| 162 | |