omni/structuredlog/StringView.h

File members: omni/structuredlog/StringView.h

// Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include "../../carb/cpp/StringView.h"
#include <string>

namespace omni
{
namespace structuredlog
{

template <class CharT, class Traits = std::char_traits<CharT>>
class BasicStringView : public carb::cpp::basic_string_view<CharT, Traits>
{
public:
    constexpr BasicStringView() : base()
    {
    }

    constexpr BasicStringView(const CharT* s) : base(s, s == nullptr ? 0 : Traits::length(s))
    {
    }

    constexpr BasicStringView(const CharT* s, size_t len) : base(s, len)
    {
    }

    constexpr BasicStringView(const std::basic_string<CharT>& s) : base(s.c_str(), s.size())
    {
    }

private:
    using base = carb::cpp::basic_string_view<CharT, Traits>;
};

using StringView = BasicStringView<char>;

} // namespace structuredlog
} // namespace omni