SourceCode.h 707 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Vector.h>
  9. #include <LibJS/Forward.h>
  10. namespace JS {
  11. class SourceCode : public RefCounted<SourceCode> {
  12. public:
  13. static NonnullRefPtr<SourceCode> create(String filename, String code);
  14. String const& filename() const;
  15. String const& code() const;
  16. SourceRange range_from_offsets(u32 start_offset, u32 end_offset) const;
  17. private:
  18. SourceCode(String filename, String code);
  19. void compute_line_break_offsets() const;
  20. String m_filename;
  21. String m_code;
  22. Optional<Vector<size_t>> mutable m_line_break_offsets;
  23. };
  24. }