本文整理汇总了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;
}
}
示例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;
}
示例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);
}
}
}