cpp-common/bt2c/std-int.hpp \
cpp-common/bt2c/text-loc.cpp \
cpp-common/bt2c/text-loc.hpp \
+ cpp-common/bt2c/text-loc-str.cpp \
+ cpp-common/bt2c/text-loc-str.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 <sstream>
+
+#include "text-loc-str.hpp"
+
+namespace bt2c {
+
+std::string textLocStr(const TextLoc& loc, const TextLocStrFmt fmt)
+{
+ std::ostringstream ss;
+
+ if (fmt == TextLocStrFmt::LineColNosAndOffset || fmt == TextLocStrFmt::LineColNos) {
+ ss << loc.naturalLineNo() << ':' << loc.naturalColNo();
+
+ if (fmt == TextLocStrFmt::LineColNosAndOffset) {
+ ss << ' ';
+ }
+ }
+
+ if (fmt == TextLocStrFmt::Offset || fmt == TextLocStrFmt::LineColNosAndOffset) {
+ ss << "@ " << loc.offset() << " bytes";
+ }
+
+ return ss.str();
+}
+
+} /* namespace bt2c */
--- /dev/null
+/*
+ * Copyright (c) 2016-2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_TEXT_LOC_STR_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_TEXT_LOC_STR_HPP
+
+#include <string>
+
+#include "text-loc.hpp"
+
+namespace bt2c {
+
+/*
+ * Text location string format.
+ */
+enum class TextLocStrFmt
+{
+ Offset,
+ LineColNosAndOffset,
+ LineColNos,
+};
+
+/*
+ * Formats the text location `loc` as a string following the format
+ * `fmt`.
+ */
+std::string textLocStr(const TextLoc& loc, TextLocStrFmt fmt);
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_TEXT_LOC_STR_HPP */