| 567 | } |
| 568 | |
| 569 | absl::optional<std::pair<int32_t, SourcePosition>> Source::FindLine( |
| 570 | SourcePosition position) const { |
| 571 | if (ABSL_PREDICT_FALSE(position < 0)) { |
| 572 | return absl::nullopt; |
| 573 | } |
| 574 | int32_t line = 1; |
| 575 | const auto line_offsets = this->line_offsets(); |
| 576 | for (const auto& line_offset : line_offsets) { |
| 577 | if (line_offset > position) { |
| 578 | break; |
| 579 | } |
| 580 | ++line; |
| 581 | } |
| 582 | if (line == 1) { |
| 583 | return std::make_pair(line, SourcePosition{0}); |
| 584 | } |
| 585 | return std::make_pair(line, line_offsets[static_cast<size_t>(line) - 2]); |
| 586 | } |
| 587 | |
| 588 | absl::StatusOr<absl_nonnull SourcePtr> NewSource(absl::string_view content, |
| 589 | std::string description) { |
nothing calls this directly
no test coverage detected