| 83 | } // End of anonymous namespace |
| 84 | |
| 85 | std::string FormatErrorsToString(const Errors& errors, |
| 86 | Location::Type location_type, |
| 87 | LexerSourceLineFinder* line_finder, |
| 88 | const Color& color, |
| 89 | const std::string& header, |
| 90 | PrintHeader print_header, |
| 91 | int source_line_max_length) { |
| 92 | std::string result; |
| 93 | for (const auto& error : errors) { |
| 94 | if (!header.empty()) { |
| 95 | switch (print_header) { |
| 96 | case PrintHeader::Never: |
| 97 | break; |
| 98 | case PrintHeader::Once: |
| 99 | print_header = PrintHeader::Never; |
| 100 | [[fallthrough]]; |
| 101 | case PrintHeader::Always: |
| 102 | result += header; |
| 103 | result += ":\n"; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | int indent = header.empty() ? 0 : 2; |
| 109 | |
| 110 | result += FormatError(error, location_type, color, line_finder, |
| 111 | source_line_max_length, indent); |
| 112 | } |
| 113 | return result; |
| 114 | } |
| 115 | |
| 116 | void FormatErrorsToFile(const Errors& errors, |
| 117 | Location::Type location_type, |