| 181 | |
| 182 | |
| 183 | size_t locationToPosition(const std::string& s, Location location) { |
| 184 | size_t pos = 0; |
| 185 | |
| 186 | // Advance `location.line` newlines |
| 187 | for (size_t lines = 0; lines < location.line && pos < s.size(); pos++) { |
| 188 | if (s[pos] == '\n') |
| 189 | lines++; |
| 190 | } |
| 191 | |
| 192 | // Advance `location.column` codepoints |
| 193 | for (size_t columns = 0; columns < location.column && pos < s.size(); columns++) { |
| 194 | // Stop if column is beyond newline |
| 195 | if (s[pos] == '\n') |
| 196 | break; |
| 197 | pos = UTF8NextCodepoint(s, pos); |
| 198 | } |
| 199 | |
| 200 | return pos; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | std::string toBase64(const uint8_t* data, size_t dataLen) { |
no test coverage detected