* @brief Transform @a position in @c json into line and column location. * * @param json JSON string. * @param position Byte distance from start of JSON string. * * @return Pair (line, column) . */
| 869 | * @return Pair <tt>(line, column)</tt>. |
| 870 | */ |
| 871 | std::pair<std::size_t, std::size_t> getLineAndColumnFromPosition(const std::string &json, |
| 872 | std::size_t position) { |
| 873 | std::size_t line = 0; |
| 874 | std::size_t column = 0; |
| 875 | |
| 876 | if (position >= json.size()) |
| 877 | return {line, column}; |
| 878 | |
| 879 | for (std::size_t p = 0; p < position; ++p) { |
| 880 | if (json[p] == '\r' && (p + 1) < json.size() && json[p + 1] == '\n') { |
| 881 | ++p; |
| 882 | ++line; |
| 883 | column = 0; |
| 884 | } else if (json[p] == '\n') { |
| 885 | ++line; |
| 886 | column = 0; |
| 887 | } else { |
| 888 | ++column; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | // column & line start at 1 |
| 893 | return {line + 1, column + 1}; |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * @brief Checks if the string is a number. |