本文整理汇总了C++中std::string_view::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::size方法的具体用法?C++ string_view::size怎么用?C++ string_view::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string_view
的用法示例。
在下文中一共展示了string_view::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::string operator+(std::string_view a, std::string_view b)
{
std::string result;
result.reserve(a.size() + b.size());
result.append(a.data(), a.size());
result.append(b.data(), b.size());
return result;
}
示例2: StringFromHex
inline std::string StringFromHex(const std::string_view& input)
{
assert((input.size() & 1) == 0);
std::string result;
result.reserve(input.size() / 2);
for (size_t i = 0; i < input.size(); i += 2)
{
auto val = std::stoi(std::string(input.substr(i, 2)), 0, 16);
result.push_back(val);
}
return result;
}
示例3: writeString
/*!
*/
void SettingNodeBase::writeString(const std::string_view& text,
std::ostream* data_stream) const noexcept
{
const uint32 text_length = zisc::cast<uint32>(text.size());
zisc::write(&text_length, data_stream);
zisc::write(text.data(), data_stream, text_length);
}
示例4: browseTexture
// -----------------------------------------------------------------------------
// Opens the texture browser for [tex_type] textures, with [init_texture]
// initially selected. Returns the selected texture
// -----------------------------------------------------------------------------
std::string MapEditor::browseTexture(
std::string_view init_texture,
TextureType tex_type,
SLADEMap& map,
std::string_view title)
{
// Unlock cursor if locked
bool cursor_locked = edit_context->mouseLocked();
if (cursor_locked)
edit_context->lockMouse(false);
// Setup texture browser
MapTextureBrowser browser(map_window, tex_type, wxString{ init_texture.data(), init_texture.size() }, &map);
browser.SetTitle(WxUtils::strFromView(title));
// Get selected texture
std::string tex;
if (browser.ShowModal() == wxID_OK)
tex = browser.selectedItem()->name();
// Re-lock cursor if needed
if (cursor_locked)
edit_context->lockMouse(true);
return tex;
}
示例5: quote_this
std::string quote_this(std::string_view arg)
{
if (arg.size() && arg[0] != '"' && arg.find(' ') != std::string::npos)
{
return '"' + std::string(arg) + '"';
}
return std::string(arg);
}
示例6: skipSpaces
void Calculator::skipSpaces(std::string_view &ref)
{
size_t i = 0;
while (i < ref.size() && std::isspace(ref[i]))
{
++i;
}
ref.remove_prefix(i);
}
示例7: loadJson
bool loadJson(const std::string_view json, Document& doc)
{
if (json.empty() == true)
{
return false;
}
// Default template parameter uses UTF8 and MemoryPoolAllocator.
return (doc.Parse(json.data(), json.size()).HasParseError() == false);
}
示例8:
static std::string_view hash_from_url( std::string_view url ){
size_t start = url.find_last_of( '/' ) + 1;
size_t end = url.find_last_of( '.' );
//Validate results
if( start == string::npos || end == string::npos || start >= url.size() )
return "";
else
return url.substr( start, end-start );
}
示例9: make_pair
std::pair<std::string_view, std::string_view> splitStringIn2(
const std::string_view str, char delimiter)
{
auto pos = str.find(delimiter, 0);
if (pos != std::string::npos)
{
return std::make_pair(str.substr(0, pos), str.substr(pos + 1, str.size() - pos));
}
return std::make_pair(str, "");
}
示例10: is_palindrome
bool is_palindrome( const std::string_view str ){
const auto len = str.size();
const auto limit = (len / 2) + 1;
for( int i = 0 ; i < limit ; ++i ){
if( str[i] != str[len - 1 - i] ){
return false;
}
}
return true;
}
示例11: set_option
void job_implObj::set_option(const std::string_view &name,
const std::string_view &value)
{
size_t s=name.size();
char name_str[s+1];
std::copy(name.begin(), name.end(), name_str);
name_str[s]=0;
s=value.size();
char value_str[s+1];
std::copy(value.begin(), value.end(), value_str);
value_str[s]=0;
job_info_t::lock lock{job_info};
lock->num_options=cupsAddOption(name_str, value_str,
lock->num_options,
&lock->options);
}
示例12: decrypt_file
void decrypt_file(
fs::path const & sourcefile,
fs::path const & destfile,
std::string_view password)
{
CryptoPP::FileSource source(
sourcefile.c_str(),
true,
new CryptoPP::DefaultDecryptorWithMAC(
(CryptoPP::byte*)password.data(), password.size(),
new CryptoPP::FileSink(
destfile.c_str())
)
);
}
示例13: supported
bool destination_implObj::supported(const std::string_view &option,
const std::string_view &value) const
{
auto s=option.size();
char option_s[s+1];
std::copy(option.begin(), option.end(), option_s);
option_s[s]=0;
s=value.size();
char value_s[s+1];
std::copy(value.begin(), value.end(), value_s);
value_s[s]=0;
info_t::lock lock{*this};
return !!cupsCheckDestSupported(lock->http,
lock->dest,
lock->info,
option_s,
value_s);
}
示例14: Convert
std::string_view WesConverter::Convert(const std::string_view& str)
{
_Mybase::initialize("UI\\WorldEditStrings.txt");
if (0 == str.compare(0, _countof("WESTRING_") - 1, "WESTRING_"))
{
auto It = _Mybase::table_.find(std::string(str.data(), str.size()));
if (It != _Mybase::table_.end())
{
return It->second;
}
}
return str;
}
示例15: InitBackend
//初始化各项参数
bool InitBackend(std::string_view path,
int64_t maxSize = 0,
std::string_view prefix = "",
std::string_view fileLink = "")
{
if (path.size() <= 0) {
return false;
} else {
mPath = path;
}
if (prefix.size() > 0) {
mPrefix = prefix;
}
if (fileLink.size() > 0) {
mLink = fileLink;
}
if (maxSize > 0) {
mMaxSize = maxSize * 1024 * 1024;
}
if (!std::filesystem::exists(mPath)) {
if (!std::filesystem::create_directory(mPath)) {
return false;
}
}
mCurrentDay = TimeUtil::GetCurrentDay();
if (mChang) {
createFile();
}
return true;
}