Convert string values to integer. * * @note This function implements the same behaviour as std::stoi. The latter * is missing in some Android toolchains. * * @param[in] str String to be converted to int. * @param[in] pos If idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number. * @param[in] base Numeric base used
| 53 | * @return Integer representation of @p str. |
| 54 | */ |
| 55 | inline int stoi(const std::string &str, std::size_t *pos = 0, NumericBase base = NumericBase::BASE_10) |
| 56 | { |
| 57 | assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16); |
| 58 | unsigned int x; |
| 59 | std::stringstream ss; |
| 60 | if (base == NumericBase::BASE_16) |
| 61 | { |
| 62 | ss << std::hex; |
| 63 | } |
| 64 | ss << str; |
| 65 | ss >> x; |
| 66 | |
| 67 | if (pos) |
| 68 | { |
| 69 | std::string s; |
| 70 | std::stringstream ss_p; |
| 71 | |
| 72 | ss_p << x; |
| 73 | ss_p >> s; |
| 74 | *pos = s.length(); |
| 75 | } |
| 76 | |
| 77 | return x; |
| 78 | } |
| 79 | |
| 80 | /** Convert string values to unsigned long. |
| 81 | * |
no outgoing calls