@@ -27,43 +27,30 @@ using NlohmannJsonTypeError = nlohmann::json::type_error;
2727namespace ppc ::util {
2828
2929/* *
30- * @brief Extract the bare function name (e.g. "PreProcessing" or "foo")
31- * from a full signature provided by std::source_location,
32- * working both on GCC/Clang and MSVC.
30+ * @brief Obtain the simple function name (e.g. "PreProcessing" or "foo")
31+ * from the full signature returned by std::source_location.
3332 *
34- * @param loc Source location (file, line, pretty- signature).
33+ * @param loc Source location info (file, line, full signature).
3534 * Defaults to the call site via std::source_location::current().
36- * @return A std::string containing only the function name.
35+ * @return A std::string with only the function’s unqualified name.
3736 *
38- * @note On GCC/Clang, loc.function_name() yields a “pretty” signature
39- * including namespaces, templates and parameter list.
40- * On MSVC, it also includes return type and calling convention.
41- * This function strips off everything before the last `::` (if any),
42- * and any parameter list or qualifiers after the name.
37+ * @details
38+ * - On GCC/Clang, function_name() returns a pretty signature
39+ * including namespaces, templates, and parameters.
40+ * - On MSVC, it also includes return type and calling convention.
41+ * - This routine removes any leading scope qualifiers (“::…”) and
42+ * drops everything from the first '(' onward.
4343 */
44- inline std::string FuncName (const std::source_location& loc = std::source_location::current()) {
45- std::string_view full = loc.function_name ();
46- // 1) find end of name (just before '(' or end of string)
47- size_t paren = full.find (' (' );
48- size_t name_end = (paren == std::string_view::npos ? full.size () : paren);
49-
50- // 2) try to strip namespaces/classes via '::'
51- size_t colons = full.rfind (" ::" , name_end);
52- size_t start = (colons == std::string_view::npos ? 0 : colons + 2 );
5344
54- // 3) on MSVC there's often a return-type + "__cdecl " prefix before the name
55- #ifdef _MSC_VER
56- if (colons == std::string_view::npos) {
57- // if no '::', drop everything up to last space before name_end
58- size_t last_space = full.rfind (' ' , name_end);
59- if (last_space != std::string_view::npos) {
60- start = last_space + 1 ;
61- }
45+ inline std::string FuncName (const std::source_location& loc = std::source_location::current()) {
46+ std::string s{loc.function_name ()};
47+ if (auto p = s.find (' (' ); p != std::string::npos) {
48+ s.resize (p); // drop “(…)”
6249 }
63- # endif
64-
65- // 4) construct owning string of just the name
66- return std::string{full. substr (start, name_end - start)} ;
50+ if ( auto p = s. rfind ( " :: " ); p != std::string::npos) {
51+ s. erase ( 0 , p + 2 ); // drop namespaces
52+ }
53+ return s ;
6754}
6855
6956enum GTestParamIndex : uint8_t { kTaskGetter , kNameTest , kTestParams };
0 commit comments