/*
 * Copyright 2015 - 2025 gary@drinkingtea.net
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#pragma once

#include "basestringview.hpp"

namespace ox {

/**
 * StringLiteral is used for functions that want to ensure that they are taking
 * string literals, and not strings outside of the data section of the program
 * that might get deleted.
 */
class StringLiteral: public detail::BaseStringView {
	public:
		constexpr StringLiteral() noexcept = default;

		constexpr StringLiteral(StringLiteral const &sv) noexcept = default;

		consteval StringLiteral(std::nullptr_t) noexcept {}

		consteval StringLiteral(char const *str, std::size_t const len) noexcept: BaseStringView{str, len} {}

		OX_ALLOW_UNSAFE_BUFFERS_BEGIN
		consteval StringLiteral(char const *str) noexcept: StringLiteral{str, ox::strlen(str)} {}
		OX_ALLOW_UNSAFE_BUFFERS_END

		constexpr StringLiteral &operator=(StringLiteral const &other) noexcept {
			set(other.data(), other.size());
			return *this;
		}

		[[nodiscard]]
		constexpr char const *c_str() const noexcept {
			return data();
		}

};

}
