40 lines
1.5 KiB
C++
40 lines
1.5 KiB
C++
#ifndef MALACHSCRIPT_TEXTSPAN_HPP
|
|
#define MALACHSCRIPT_TEXTSPAN_HPP
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
|
|
namespace MalachScript {
|
|
class TextSpan {
|
|
size_t _start;
|
|
size_t _end;
|
|
|
|
public:
|
|
inline TextSpan(size_t start, size_t end) : _start(start), _end(end) {}
|
|
[[nodiscard]] inline size_t GetStart() const noexcept { return _start; }
|
|
[[nodiscard]] inline size_t GetEnd() const noexcept { return _end; }
|
|
inline bool operator==(const TextSpan& rhs) const { return _start == rhs._start && _end == rhs._end; }
|
|
inline bool operator!=(const TextSpan& rhs) const { return !(rhs == *this); }
|
|
};
|
|
|
|
class ScriptTextSpan {
|
|
TextSpan _span;
|
|
const std::string_view& _scriptName;
|
|
|
|
public:
|
|
inline ScriptTextSpan(size_t start, size_t end, const std::string_view& scriptName)
|
|
: _span(start, end), _scriptName(scriptName) {}
|
|
[[nodiscard]] inline TextSpan GetSpan() const noexcept { return _span; }
|
|
[[nodiscard]] inline const std::string_view& GetScriptName() const noexcept { return _scriptName; }
|
|
inline bool operator==(const ScriptTextSpan& rhs) const {
|
|
return _span == rhs._span && _scriptName == rhs._scriptName;
|
|
}
|
|
inline bool operator!=(const ScriptTextSpan& rhs) const { return !(rhs == *this); }
|
|
[[nodiscard]] inline size_t GetStart() const noexcept { return _span.GetStart(); }
|
|
[[nodiscard]] inline size_t GetEnd() const noexcept { return _span.GetEnd(); }
|
|
};
|
|
|
|
}
|
|
|
|
#endif // MALACHSCRIPT_TEXTSPAN_HPP
|