本文整理汇总了C++中llvm::StringRef::back方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::back方法的具体用法?C++ StringRef::back怎么用?C++ StringRef::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::StringRef
的用法示例。
在下文中一共展示了StringRef::back方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StripSpaces
static inline void StripSpaces(llvm::StringRef &Str)
{
while (!Str.empty() && isspace(Str[0]))
Str = Str.substr(1);
while (!Str.empty() && isspace(Str.back()))
Str = Str.substr(0, Str.size()-1);
}
示例2: IsValidBasename
static bool IsValidBasename(const llvm::StringRef &basename) {
// Check that the basename matches with the following regular expression or is
// an operator name:
// "^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$"
// We are using a hand written implementation because it is significantly more
// efficient then
// using the general purpose regular expression library.
size_t idx = 0;
if (basename.size() > 0 && basename[0] == '~')
idx = 1;
if (basename.size() <= idx)
return false; // Empty string or "~"
if (!std::isalpha(basename[idx]) && basename[idx] != '_')
return false; // First charater (after removing the possible '~'') isn't in
// [A-Za-z_]
// Read all characters matching [A-Za-z_0-9]
++idx;
while (idx < basename.size()) {
if (!std::isalnum(basename[idx]) && basename[idx] != '_')
break;
++idx;
}
// We processed all characters. It is a vaild basename.
if (idx == basename.size())
return true;
// Check for basename with template arguments
// TODO: Improve the quality of the validation with validating the template
// arguments
if (basename[idx] == '<' && basename.back() == '>')
return true;
// Check if the basename is a vaild C++ operator name
if (!basename.startswith("operator"))
return false;
static RegularExpression g_operator_regex(
llvm::StringRef("^(operator)( "
"?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|"
"\\[\\]|[\\^<>=!\\/"
"*+-]+)(<.*>)?(\\[\\])?$"));
std::string basename_str(basename.str());
return g_operator_regex.Execute(basename_str, nullptr);
}
示例3: 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;
}
示例4: needsQuotes
bool needsQuotes(const llvm::StringRef &arg) {
return // not already quoted
!(arg.size() > 1 && arg[0] == '"' &&
arg.back() == '"') && // empty or min 1 space or min 1 double quote
(arg.empty() || arg.find(' ') != arg.npos || arg.find('"') != arg.npos);
}
示例5: RStrip
static inline void RStrip(llvm::StringRef &Str, char c)
{
if (!Str.empty() && Str.back() == c)
Str = Str.substr(0, Str.size()-1);
}