当前位置: 首页>>代码示例>>C++>>正文


C++ wcstring::replace方法代码示例

本文整理汇总了C++中wcstring::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ wcstring::replace方法的具体用法?C++ wcstring::replace怎么用?C++ wcstring::replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wcstring的用法示例。


在下文中一共展示了wcstring::replace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: wcslen

__attribute__((unused)) static void replace_all(wcstring &str, const wchar_t *needle,
                                                const wchar_t *replacement) {
    size_t needle_len = wcslen(needle);
    size_t offset = 0;
    while ((offset = str.find(needle, offset)) != wcstring::npos) {
        str.replace(offset, needle_len, replacement);
        offset += needle_len;
    }
}
开发者ID:AlexShiLucky,项目名称:fish-shell,代码行数:9,代码来源:path.cpp

示例2: unescape_string

bool unescape_string(wcstring &str, int escape_special)
{
    bool success = false;
    wchar_t *result = unescape(str.c_str(), escape_special);
    if (result) {
        str.replace(str.begin(), str.end(), result);
        free(result);
        success = true;
    }
    return success;
}
开发者ID:berdario,项目名称:fish-shell,代码行数:11,代码来源:common.cpp

示例3: expand_home_directory

/**
   Attempts tilde expansion of the string specified, modifying it in place.
*/
static void expand_home_directory(wcstring &input)
{
    const wchar_t * const in = input.c_str();
    if (in[0] == HOME_DIRECTORY)
    {
        int tilde_error = 0;
        size_t tail_idx;
        wcstring home;

        if (in[1] == '/' || in[1] == '\0')
        {
            /* Current users home directory */

            home = env_get_string(L"HOME");
            tail_idx = 1;
        }
        else
        {
            /* Some other users home directory */
            const wchar_t *name_end = wcschr(in, L'/');
            if (name_end)
            {
                tail_idx = name_end - in;
            }
            else
            {
                tail_idx = wcslen(in);
            }
            wcstring name_str = input.substr(1, tail_idx - 1);
            std::string name_cstr = wcs2string(name_str);
            struct passwd *userinfo = getpwnam(name_cstr.c_str());

            if (userinfo == NULL)
            {
                tilde_error = 1;
                input[0] = L'~';
            }
            else
            {
                home = str2wcstring(userinfo->pw_dir);
            }
        }

        if (! tilde_error)
        {
            input.replace(input.begin(), input.begin() + tail_idx, home);
        }
    }
}
开发者ID:frogshead,项目名称:fish-shell,代码行数:52,代码来源:expand.cpp


注:本文中的wcstring::replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。