Highlight the place of syntax error.
| 68 | |
| 69 | /// Highlight the place of syntax error. |
| 70 | void writeQueryWithHighlightedErrorPositions( |
| 71 | WriteBuffer & out, |
| 72 | const char * begin, |
| 73 | const char * end, |
| 74 | const Token * positions_to_hilite, /// must go in ascending order |
| 75 | size_t num_positions_to_hilite) |
| 76 | { |
| 77 | const char * pos = begin; |
| 78 | for (size_t position_to_hilite_idx = 0; position_to_hilite_idx < num_positions_to_hilite; ++position_to_hilite_idx) |
| 79 | { |
| 80 | const char * current_position_to_hilite = positions_to_hilite[position_to_hilite_idx].begin; |
| 81 | |
| 82 | chassert(current_position_to_hilite <= end); |
| 83 | chassert(current_position_to_hilite >= begin); |
| 84 | |
| 85 | out.write(pos, current_position_to_hilite - pos); |
| 86 | |
| 87 | if (current_position_to_hilite == end) |
| 88 | { |
| 89 | out << "\033[41;1m \033[0m"; |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | ssize_t bytes_to_hilite = std::min<ssize_t>(UTF8::seqLength(*current_position_to_hilite), end - current_position_to_hilite); |
| 94 | |
| 95 | /// Bright on red background. |
| 96 | out << "\033[41;1m"; |
| 97 | out.write(current_position_to_hilite, bytes_to_hilite); |
| 98 | out << "\033[0m"; |
| 99 | pos = current_position_to_hilite + bytes_to_hilite; |
| 100 | } |
| 101 | out.write(pos, end - pos); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void writeQueryAroundTheError( |
no test coverage detected