spice Application.cpp ---function_to_func_name 2013-5-28

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个字符串

 若找到了那么返回 ‘ ’ 与 ‘(’ 之间的字符串


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值