static inline std::string function_to_func_name(const std::string& f_name)
{
#ifdef __GNUC__ //whether define the __GNUC__
std::string name(f_name); //f_name initialize the class of name
std::string::size_type end_pos = f_name.find('(');//string::size_type = unsigned int find the first '('
if (end_pos == std::string::npos) { //npos is the end of string
return f_name;
}
std::string::size_type start = f_name.rfind(' ', end_pos); //find the finally ' '
if (start == std::string::npos) {
return name.substr(0, end_pos);
}
end_pos -= ++start;
return name.substr(start, end_pos);
#else
return f_name;
#endif
}
__GNUC__ 是用gcc编译的宏 其类型为代表 gcc版本的整型
函数的功能是对于给定的字符串中,找出函数名字
1. size_type 的类型是unsigned int
2. 定义end_pos 找到函数名的结尾位置返回,利用的是标准库中的find函数 返回其‘(’的下标
若未找到那么直接返回这个字符串
3.定义start 找到函数名的起始位置,利用的是标准函数库中的rfind函数,返回‘ ’的下标
若未找到那么返回从0开始 的endpos个字符串
若找到了那么返回 ‘ ’ 与 ‘(’ 之间的字符串