mardi 10 novembre 2020

Format a constexpr const char*

I'm working with __ PRETTY_FUNCTION __, C++11, that is formated like: (type Class::Object(parameters), but I need to format my string like (Class::Object()).

I know how to remove "type" from my string with constexpr. I can simply return a pointer skipping space, like this:

inline constexpr const char* removeType(const char* expression) noexcept
{
    return (*expression == ' ') ? expression+1 : removeType(expression+1);
}

This is working very well! But I can't think of a way to remove "parameters" from my string. I thought I could find "(" in my original expression and put a ") \ 0" after that. But I can't change this string because it's a constant, and that would also change the __ PRETTY_FUNCTION __ return behavior. So, what can I do to create a new string (char* or const char*) in a constexpr and format it removing something in the middle of it?

Aucun commentaire:

Enregistrer un commentaire