| 162 | } |
| 163 | |
| 164 | inline dtype_t parse_descr(std::string typestring) { |
| 165 | if (typestring.length() < 3) { |
| 166 | throw std::runtime_error("invalid typestring (length)"); |
| 167 | } |
| 168 | |
| 169 | char byteorder_c = typestring.at(0); |
| 170 | char kind_c = typestring.at(1); |
| 171 | std::string itemsize_s = typestring.substr(2); |
| 172 | |
| 173 | if (!in_array(byteorder_c, endian_chars)) { |
| 174 | throw std::runtime_error("invalid typestring (byteorder)"); |
| 175 | } |
| 176 | |
| 177 | if (!in_array(kind_c, numtype_chars)) { |
| 178 | throw std::runtime_error("invalid typestring (kind)"); |
| 179 | } |
| 180 | |
| 181 | if (!is_digits(itemsize_s)) { |
| 182 | throw std::runtime_error("invalid typestring (itemsize)"); |
| 183 | } |
| 184 | unsigned int itemsize = std::stoul(itemsize_s); |
| 185 | |
| 186 | return {byteorder_c, kind_c, itemsize}; |
| 187 | } |
| 188 | |
| 189 | namespace pyparse { |
| 190 |
no test coverage detected