本文整理汇总了C++中llvm::StringRef::front方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::front方法的具体用法?C++ StringRef::front怎么用?C++ StringRef::front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::StringRef
的用法示例。
在下文中一共展示了StringRef::front方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
lldb::OptionValueSP
OptionValueArray::GetSubValue(const ExecutionContext *exe_ctx,
llvm::StringRef name, bool will_modify,
Status &error) const {
if (name.empty() || name.front() != '[') {
error.SetErrorStringWithFormat(
"invalid value path '%s', %s values only support '[<index>]' subvalues "
"where <index> is a positive or negative array index",
name.str().c_str(), GetTypeAsCString());
return nullptr;
}
name = name.drop_front();
llvm::StringRef index, sub_value;
std::tie(index, sub_value) = name.split(']');
if (index.size() == name.size()) {
// Couldn't find a closing bracket
return nullptr;
}
const size_t array_count = m_values.size();
int32_t idx = 0;
if (index.getAsInteger(0, idx))
return nullptr;
uint32_t new_idx = UINT32_MAX;
if (idx < 0) {
// Access from the end of the array if the index is negative
new_idx = array_count - idx;
} else {
// Just a standard index
new_idx = idx;
}
if (new_idx < array_count) {
if (m_values[new_idx]) {
if (!sub_value.empty())
return m_values[new_idx]->GetSubValue(exe_ctx, sub_value,
will_modify, error);
else
return m_values[new_idx];
}
} else {
if (array_count == 0)
error.SetErrorStringWithFormat(
"index %i is not valid for an empty array", idx);
else if (idx > 0)
error.SetErrorStringWithFormat(
"index %i out of range, valid values are 0 through %" PRIu64,
idx, (uint64_t)(array_count - 1));
else
error.SetErrorStringWithFormat("negative index %i out of range, "
"valid values are -1 through "
"-%" PRIu64,
idx, (uint64_t)array_count);
}
return OptionValueSP();
}
示例2: SetValueFromString
Status OptionValueString::SetValueFromString(llvm::StringRef value,
VarSetOperationType op) {
Status error;
std::string value_str = value.str();
value = value.trim();
if (value.size() > 0) {
switch (value.front()) {
case '"':
case '\'': {
if (value.size() <= 1 || value.back() != value.front()) {
error.SetErrorString("mismatched quotes");
return error;
}
value = value.drop_front().drop_back();
} break;
}
value_str = value.str();
}
switch (op) {
case eVarSetOperationInvalid:
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
case eVarSetOperationRemove:
if (m_validator) {
error = m_validator(value_str.c_str(), m_validator_baton);
if (error.Fail())
return error;
}
error = OptionValue::SetValueFromString(value, op);
break;
case eVarSetOperationAppend: {
std::string new_value(m_current_value);
if (value.size() > 0) {
if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
std::string str;
Args::EncodeEscapeSequences(value_str.c_str(), str);
new_value.append(str);
} else
new_value.append(value);
}
if (m_validator) {
error = m_validator(new_value.c_str(), m_validator_baton);
if (error.Fail())
return error;
}
m_current_value.assign(new_value);
NotifyValueChanged();
} break;
case eVarSetOperationClear:
Clear();
NotifyValueChanged();
break;
case eVarSetOperationReplace:
case eVarSetOperationAssign:
if (m_validator) {
error = m_validator(value_str.c_str(), m_validator_baton);
if (error.Fail())
return error;
}
m_value_was_set = true;
if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
Args::EncodeEscapeSequences(value_str.c_str(), m_current_value);
} else {
SetCurrentValue(value_str);
}
NotifyValueChanged();
break;
}
return error;
}
示例3: LStrip
static inline void LStrip(llvm::StringRef &Str, char c)
{
if (!Str.empty() && Str.front() == c)
Str = Str.substr(1);
}