blob: 34a97e65a9cc78b50c5fd38657f26cbfd257eaac [file] [log] [blame]
#include "parse_text_proto.h"
#include <cstddef>
#include <vector>
#include "absl/log/log.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/io/tokenizer.h"
namespace safepower_agent {
namespace internal {
static absl::string_view ExtractLine(absl::string_view text, int line) {
std::vector<absl::string_view> lines = absl::StrSplit(text, '\n');
return (static_cast<std::size_t>(line) < lines.size()) ? lines[line] : "";
}
void ErrorCollector::RecordError(int line, google::protobuf::io::ColumnNumber column,
absl::string_view message) {
absl::StrAppendFormat(&message_, "%s [line %d, column %d]\n%s", message,
line + 1, column + 1, ExtractLine(text_proto_, line));
}
void ErrorCollector::RecordWarning(int line, google::protobuf::io::ColumnNumber column,
absl::string_view message) {
LOG(WARNING) << message << " [line " << line + 1 << ", column " << column + 1
<< "]\n"
<< ExtractLine(text_proto_, line);
}
} // namespace internal
} // namespace safepower_agent