Function basename

Synopsis

#include <include/spdlog/pattern_formatter-inl.h>

static const char * basename(const char *filename)

Description

No description yet.

Source

Lines 823-840 in include/spdlog/pattern_formatter-inl.h.

static const char *basename(const char *filename)
{
    // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
    // the branch will be elided by optimizations
    if (sizeof(os::folder_seps) == 2)
    {
        const char *rv = std::strrchr(filename, os::folder_seps[0]);
        return rv != nullptr ? rv + 1 : filename;
    }
    else
    {
        const std::reverse_iterator<const char*> begin(filename + std::strlen(filename));
        const std::reverse_iterator<const char*> end(filename);
        const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), std::end(os::folder_seps) - 1);
        return it != end ? it.base() : filename;
    }
}





Add Discussion

Log in to comment