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_FIDL_INCLUDE_FIDL_SOURCE_FILE_H_
6#define ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_SOURCE_FILE_H_
7
8#include <string>
9#include <utility>
10#include <vector>
11
12#include "string_view.h"
13
14namespace fidl {
15
16class SourceFile {
17public:
18    SourceFile(std::string filename, std::string data);
19    ~SourceFile();
20
21    StringView filename() const { return filename_; }
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
33private:
34    std::string filename_;
35    std::string data_;
36    std::vector<StringView> lines_;
37};
38
39} // namespace fidl
40
41#endif // ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_SOURCE_FILE_H_
42