cpp-common/bt2c/read-fixed-len-int.hpp \
cpp-common/bt2c/safe-ops.hpp \
cpp-common/bt2c/std-int.hpp \
+ cpp-common/bt2c/text-loc.cpp \
+ cpp-common/bt2c/text-loc.hpp \
cpp-common/bt2c/type-traits.hpp \
cpp-common/bt2c/uuid.hpp \
cpp-common/bt2c/vector.hpp \
--- /dev/null
+/*
+ * Copyright (c) 2016-2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "text-loc.hpp"
+
+namespace bt2c {
+
+TextLoc::TextLoc(const unsigned long long offset, const unsigned long long lineNo,
+ const unsigned long long colNo) noexcept :
+ _mOffset {offset},
+ _mLineNo {lineNo}, _mColNo {colNo}
+{
+}
+
+} /* namespace bt2c */
--- /dev/null
+/*
+ * Copyright (c) 2016-2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_TEXT_LOC_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_TEXT_LOC_HPP
+
+namespace bt2c {
+
+/*
+ * Location in a multiline text.
+ */
+class TextLoc final
+{
+public:
+ /*
+ * Builds a text location which targets offset `offset` bytes,
+ * zero-based line number `lineNo`, and zero-based column number
+ * `colNo`.
+ */
+ explicit TextLoc(unsigned long long offset = 0, unsigned long long lineNo = 0,
+ unsigned long long colNo = 0) noexcept;
+
+ /*
+ * Offset (bytes).
+ */
+ unsigned long long offset() const noexcept
+ {
+ return _mOffset;
+ }
+
+ /*
+ * Line number (zero-based).
+ */
+ unsigned long long lineNo() const noexcept
+ {
+ return _mLineNo;
+ }
+
+ /*
+ * Column number (zero-based).
+ */
+ unsigned long long colNo() const noexcept
+ {
+ return _mColNo;
+ }
+
+ /*
+ * Line number (one-based).
+ */
+ unsigned long long naturalLineNo() const noexcept
+ {
+ return _mLineNo + 1;
+ }
+
+ /*
+ * Column number (one-based).
+ */
+ unsigned long long naturalColNo() const noexcept
+ {
+ return _mColNo + 1;
+ }
+
+private:
+ unsigned long long _mOffset = 0;
+ unsigned long long _mLineNo = 0;
+ unsigned long long _mColNo = 0;
+};
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_TEXT_LOC_HPP */