1 // Copyright 2017 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ZIRCON_SYSTEM_HOST_BANJO_INCLUDE_BANJO_SOURCE_FILE_H_ 6 #define ZIRCON_SYSTEM_HOST_BANJO_INCLUDE_BANJO_SOURCE_FILE_H_ 7 8 #include <string> 9 #include <utility> 10 #include <vector> 11 12 #include "string_view.h" 13 14 namespace banjo { 15 16 class SourceFile { 17 public: 18 SourceFile(std::string filename, std::string data); 19 ~SourceFile(); 20 filename()21 StringView filename() const { return filename_; } data()22 StringView data() const { return data_; } 23 24 // This is in the coordinates that most editors use. Lines start 25 // at 1 but columns start at 0. 26 struct Position { 27 int line; 28 int column; 29 }; 30 31 StringView LineContaining(StringView view, Position* position_out) const; 32 33 private: 34 std::string filename_; 35 std::string data_; 36 std::vector<StringView> lines_; 37 }; 38 39 } // namespace banjo 40 41 #endif // ZIRCON_SYSTEM_HOST_BANJO_INCLUDE_BANJO_SOURCE_FILE_H_ 42