本文整理汇总了C++中std::string_view类的典型用法代码示例。如果您正苦于以下问题:C++ string_view类的具体用法?C++ string_view怎么用?C++ string_view使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了string_view类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseExprSum
double Calculator::parseExprSum(std::string_view &ref)
{
double value = parseExprMul(ref);
while (true)
{
skipSpaces(ref);
if (!ref.empty() && ref[0] == '+')
{
ref.remove_prefix(1);
value += parseExprMul(ref);
m_printStrategy->printAddition();
}
else if (!ref.empty() && ref[0] == '-')
{
ref.remove_prefix(1);
value -= parseExprMul(ref);
m_printStrategy->printSubstraction();
}
else
{
break;
}
}
return value;
}
示例2: 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;
}
示例3: parseExprMul
double Calculator::parseExprMul(std::string_view &ref)
{
double value = parseSymbol(ref);
while (true)
{
skipSpaces(ref);
if (!ref.empty() && ref[0] == '*')
{
ref.remove_prefix(1);
value *= parseSymbol(ref);
m_printStrategy->printMultiplication();
}
else if (!ref.empty() && ref[0] == '/')
{
ref.remove_prefix(1);
value /= parseSymbol(ref);
m_printStrategy->printDivision();
}
else
{
break;
}
}
return value;
}
示例4: are_headers_split
bool are_headers_split(std::string_view headers) noexcept
{
char prev('0');
char pprev('0');
if (!headers.empty())
{
auto iter(headers.cbegin());
for(; iter != headers.cend(); ++iter)
{
if (*iter == '\n')
{
if (prev == '\n')
return true;
else if ((prev == '\r') && (pprev == '\n'))
return true;
}
pprev = prev;
prev = *iter;
}
}
return false;
}
示例5: splitAt
inline std::pair<std::string_view, std::string_view> splitAt( std::string_view str, char splitter ){
auto pos = str.find( splitter );
if( pos == std::string_view::npos )
return { str, {} };
else
return { str.substr( 0, pos ), str.substr( pos+1 ) };
}
示例6: parseSymbol
double Calculator::parseSymbol(std::string_view &ref)
{
double value = 0;
skipSpaces(ref);
if (!ref.empty() && ref[0] == '(')
{
ref.remove_prefix(1);
value = parseExprSum(ref);
skipSpaces(ref);
if (!ref.empty() && ref[0] == ')')
{
ref.remove_prefix(1);
return value;
}
else
{
return std::numeric_limits<double>::quiet_NaN();
}
}
else if (!ref.empty() && !std::isdigit(ref[0]) && ref[0] != '-')
{
return parseFunction(ref);
}
else
{
return parseDouble(ref);
}
}
示例7: 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);
}
示例8: 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);
}
示例9: loadFile
bool loadFile(const std::string_view file, Document& doc)
{
if (file.empty() == true)
{
return false;
}
return loadJson(FileUtils::readText(file.data()), doc);
}
示例10: 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);
}
示例11: 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);
}
示例12: operator
bool operator()(std::string_view lhs, std::string_view rhs) const {
#if _WIN32
if (_stricmp(lhs.data(), rhs.data()) < 0)
#else
if (strcasecmp(lhs.data(), rhs.data()) < 0)
#endif
return true;
return false;
}
示例13: replaceStringInPlace
void replaceStringInPlace(std::string& subject, const std::string_view search, const std::string_view replace)
{
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos)
{
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
}
示例14: hash_from_url
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 );
}
示例15: splitStringIn2
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, "");
}