Repository: gabime/spdlog
File: include/spdlog/common-inl.h (C/C++)

Code before:
// Distributed under the MIT License (http://opensource.org/licenses/MIT)

#pragma once

#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/common.h>
#endif

namespace spdlog {
namespace level {

#if __cplusplus >= 201703L
constexpr
#endif
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;

static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;

SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
{
    return level_string_views[l];
}

SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
{
    return short_level_names[l];
}

SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
{
    int level = 0;
    for (const auto &level_str : level_string_views)
    {
        if (level_str == name)
        {
            return static_cast<level::level_enum>(level);
        }
        level++;
    }
    // check also for "warn" and "err" before giving up..
    if (name == "warn")
    {
        return level::warn;
    }
    if (name == "err")
    {
        return level::err;
    }
    return level::off;
}
} // namespace level

Review comment (bug):
Hello,

I just have this compile error within my project (which used v1.8.2 previously without error):

```
FAILED: _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o 
/usr/local/bin/ccache /usr/bin/c++ -DSPDLOG_COMPILED_LIB -I_deps/spdlog-src/include -g -std=c++2a -MD -MT _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o -MF _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o.d -o _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.o -c _deps/spdlog-src/src/spdlog.cpp
In file included from _deps/spdlog-src/src/spdlog.cpp:9:
_deps/spdlog-src/include/spdlog/common-inl.h: In function ‘void spdlog::level::set_string_view(spdlog::level::level_enum, const string_view_t&)’:
_deps/spdlog-src/include/spdlog/common-inl.h:27:29: error: passing ‘const string_view_t’ {aka ‘const fmt::v7::basic_string_view<char>’} as ‘this’ argument discards qualifiers [-fpermissive]
   27 |     level_string_views[l] = s;
      |                             ^
In file included from _deps/spdlog-src/include/spdlog/fmt/fmt.h:22,
                 from _deps/spdlog-src/include/spdlog/common.h:36,
                 from _deps/spdlog-src/include/spdlog/spdlog.h:12,
                 from _deps/spdlog-src/include/spdlog/spdlog-inl.h:7,
                 from _deps/spdlog-src/src/spdlog.cpp:8:
_deps/spdlog-src/include/spdlog/fmt/bundled/core.h:355:32: note:   in call to ‘constexpr fmt::v7::basic_string_view<char>& fmt::v7::basic_string_view<char>::operator=(const fmt::v7::basic_string_view<char>&)’
  355 | template <typename Char> class basic_string_view {
      |                                ^~~~~~~~~~~~~~~~~
```
Looks like it is linked to this change.

Code after:
// Distributed under the MIT License (http://opensource.org/licenses/MIT)

#pragma once

#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/common.h>
#endif

namespace spdlog {
namespace level {

#if __cplusplus >= 201703L
constexpr
#endif
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;

static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;

SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
{
    return level_string_views[l];
}

SPDLOG_INLINE void set_string_view(spdlog::level::level_enum l, const string_view_t &s) SPDLOG_NOEXCEPT
{
    level_string_views[l] = s;
}

SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
{
    return short_level_names[l];
}

SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
{
    int level = 0;
    for (const auto &level_str : level_string_views)
    {
        if (level_str == name)
        {
            return static_cast<level::level_enum>(level);
        }
        level++;
    }
    // check also for "warn" and "err" before giving up..
    if (name == "warn")
    {
        return level::warn;
    }
    if (name == "err")
    {