本文整理汇总了C++中std::string_view::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::empty方法的具体用法?C++ string_view::empty怎么用?C++ string_view::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string_view
的用法示例。
在下文中一共展示了string_view::empty方法的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: 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;
}
示例3: 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);
}
}
示例4: parseDouble
double Calculator::parseDouble(std::string_view &ref)
{
double value = 0;
bool isNegative = false;
bool parsedAny = false;
skipSpaces(ref);
if (!ref.empty() && ref[0] == '-')
{
isNegative = true;
ref.remove_prefix(1);
}
skipSpaces(ref);
while (!ref.empty() && std::isdigit(ref[0]))
{
parsedAny = true;
const int digit = ref[0] - '0';
value = value * 10.0f + double(digit);
ref.remove_prefix(1);
}
if (!parsedAny)
{
return std::numeric_limits<double>::quiet_NaN();
}
if (isNegative)
{
value *= -1;
}
if (ref.empty() || (ref[0] != '.'))
{
m_printStrategy->printNumber(value);
return value;
}
ref.remove_prefix(1);
double factor = 1.f;
while (!ref.empty() && std::isdigit(ref[0]))
{
const int digit = ref[0] - '0';
factor *= 0.1f;
value += factor * double(digit);
ref.remove_prefix(1);
}
m_printStrategy->printNumber(value);
return value;
}
示例5:
//连接到网络地址
bool
Dial(std::string_view network, std::string_view ip, unsigned short port)
{
if (network.empty() || ip.empty() || port <= 0) {
return false;
}
mRemoteAddr = std::move(ip);
mPort = port;
if (!mSocket.NewSocket(network))
return false;
return mSocket.Connect(port, ip) == 0 ? true : false;
}
示例6: Init
void CArchiveExtractCallback::Init(std::string_view pw, std::shared_ptr<ISequentialOutStream> const & outFileStream)
{
_outFileStream = outFileStream;
password_is_defined_ = !pw.empty();
Convert(password_, pw);
}
示例7: setProperty
void Player::setProperty(const std::string_view prop, const Variable& val)
{
if (prop.empty() == true)
{
return;
}
auto propHash16 = str2int16(prop);
switch (propHash16)
{
case str2int16("name"):
{
if (std::holds_alternative<std::string>(val) == true)
{
Name(std::get<std::string>(val));
}
}
break;
default:
{
if (std::holds_alternative<int64_t>(val) == true)
{
if (setNumberByHash(propHash16, (LevelObjValue)std::get<int64_t>(val), nullptr))
{
updateProperties();
}
}
}
break;
}
}
示例8: 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;
}
示例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: 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);
}
示例11: destroy_userdata
int32_t easy_lua::destroy_userdata(
const int32_t stackpos,
const std::string_view& name ) const
{
if( is_userdata( stackpos ) && !name.empty() ) {
const auto data = get_userdata<uintptr_t>( stackpos, name );
delete data;
}
return 0;
}
示例12: parseExpr
double Calculator::parseExpr(std::string_view &ref)
{
double result = parseExprSum(ref);
if (!ref.empty())
{
return std::numeric_limits<double>::quiet_NaN();
}
return result;
}
示例13: getNumberProp
bool Player::getNumberProp(const std::string_view prop, Number32& value) const
{
if (prop.empty() == true)
{
return false;
}
auto props = Utils::splitStringIn2(prop, '.');
auto propHash = str2int16(props.first);
return getNumberByHash(propHash, props.second, value);
}
示例14: ParseArguments
double Calculator::ParseArguments(std::string_view &ref)
{
double value = 0;
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
{
return std::numeric_limits<double>::quiet_NaN();
}
}
示例15: ToValue
bool CSeqConversionDefault::ToValue(std::string_view sv)
{
m_bReady = false;
if (sv == "$$") {
m_bHex = true;
return true;
}
if (auto nextTerm = GetNextTerm(sv)) {
m_iTargetValue = m_iCurrentValue = *nextTerm;
m_iRepeat = m_iValueDiv = 1;
if (!sv.empty() && sv.front() == ':') {
if (sv.remove_prefix(1), !sv.empty()) {
if (auto divTerm = GetNextInteger(sv)) {
m_iValueDiv = *divTerm;
if (m_iValueDiv <= 0)
return false;
if (!sv.empty() && sv.front() == ':') {
if (sv.remove_prefix(1), sv.empty())
return false;
if (auto target = GetNextTerm(sv))
m_iTargetValue = *target;
else
return false;
}
}
else
return false;
}
else
return false;
}
if (!sv.empty() && sv.front() == '\'') {
if (sv.remove_prefix(1), !sv.empty()) {
if (auto repTerm = GetNextInteger(sv)) {
m_iRepeat = *repTerm;
if (m_iRepeat <= 0)
return false;
}
}
else
return false;
}
if (sv.empty()) {
m_iValueInc = m_iTargetValue - m_iCurrentValue;
m_iRepeatCounter = m_iCounter = m_iValueMod = 0;
return m_bReady = true;
}
}
return false;
}