本文整理汇总了C++中st::string::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string::size方法的具体用法?C++ string::size怎么用?C++ string::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st::string
的用法示例。
在下文中一共展示了string::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memcpy
void DS::Stream::writeSafeString(const ST::string& value, DS::StringType format)
{
if (format == e_StringUTF16) {
ST::utf16_buffer buffer = value.to_utf16();
uint16_t length = value.size() & 0x0FFF;
ST::utf16_buffer work;
char16_t* data = work.create_writable_buffer(length);
memcpy(data, buffer.data(), length * sizeof(char16_t));
for (uint16_t i=0; i<length; ++i)
data[i] = ~data[i];
write<uint16_t>(length | 0xF000);
writeBytes(data, length * sizeof(char16_t));
write<char16_t>(0);
} else {
ST::char_buffer buffer = (format == e_StringUTF8) ? value.to_utf8()
: value.to_latin_1(ST::substitute_invalid);
uint16_t length = value.size() & 0x0FFF;
ST::char_buffer work;
char* data = work.create_writable_buffer(length);
memcpy(data, buffer.data(), length * sizeof(char));
for (uint16_t i=0; i<length; ++i)
data[i] = ~data[i];
write<uint16_t>(length | 0xF000);
writeBytes(data, length * sizeof(char));
}
}
示例2: cdUp
ST::string cdUp(ST::string path) {
// Check for root paths, we can't go up from there!
#ifdef _WIN32
if (path.substr(1) == ":\\")
return path;
#else
if (path == "/")
return path;
#endif
// Not very robust, but it works for one level of parent scanning
if (path.is_empty())
return ".." PATHSEPSTR;
// Strip the ending slash, if necessary, and then go up one dir
if (path.char_at(path.size()-1) == PATHSEP)
path = path.left(path.size() - 1);
ST::string up = path.before_last(PATHSEP);
if (path.char_at(0) == PATHSEP) {
// Absolute path specified -- make sure we keep it that way
return up + PATHSEPSTR;
} else {
// Relative path specified
return up.is_empty() ? "" : up + PATHSEPSTR;
}
}
示例3: GetPassword
/*****************************************************************************
** pfMacPasswordStore **
*****************************************************************************/
ST::string pfMacPasswordStore::GetPassword(const ST::string& username)
{
ST::string service = GetServerDisplayName();
void* passwd = nullptr;
uint32_t passwd_len = 0;
if (SecKeychainFindGenericPassword(nullptr,
service.size(),
service.c_str(),
username.size(),
username.c_str(),
&passwd_len,
&passwd,
nullptr) != errSecSuccess)
{
return ST::null;
}
ST::string ret(reinterpret_cast<const char*>(passwd), size_t(passwd_len));
SecKeychainItemFreeContent(nullptr, passwd);
return ret;
}
示例4: CleanFileName
ST::string CleanFileName(const ST::string& fname) {
ST::char_buffer result;
char* buf = result.create_writable_buffer(fname.size());
memcpy(buf, fname.c_str(), fname.size() + 1);
for (char* bp = buf; *bp; bp++) {
if (*bp == '?' || *bp == '*' || *bp == '<' || *bp == '>' ||
*bp == '"' || *bp == '|' || *bp < (char)0x20)
*bp = '_';
if (*bp == '/' || *bp == '\\' || *bp == ':')
*bp = '_';
}
return result;
}
示例5: FixSlashes
ST::string FixSlashes(const ST::string& src) {
if (src.is_empty())
return src;
ST::char_buffer dest;
char* pbuf = dest.create_writable_buffer(src.size());
memcpy(pbuf, src.c_str(), src.size() + 1);
for (char* pc = pbuf; *pc != 0; pc++) {
if (*pc == '/' || *pc == '\\')
*pc = PATHSEP;
}
return dest;
}
示例6: SetPassword
bool pfMacPasswordStore::SetPassword(const ST::string& username, const ST::string& password)
{
ST::string service = GetServerDisplayName();
return SecKeychainAddGenericPassword(nullptr,
service.size(),
service.c_str(),
username.size(),
username.c_str(),
password.size(),
password.c_str(),
nullptr) == errSecSuccess;
}