当前位置: 首页>>代码示例>>C++>>正文


C++ StringRef::back方法代码示例

本文整理汇总了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);
}
开发者ID:AAZemlyanukhin,项目名称:freebsd,代码行数:7,代码来源:RegisterValue.cpp

示例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);
}
开发者ID:CodaFi,项目名称:swift-lldb,代码行数:48,代码来源:CPlusPlusLanguage.cpp

示例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;
}
开发者ID:llvm-project,项目名称:lldb,代码行数:75,代码来源:OptionValueString.cpp

示例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);
}
开发者ID:markos,项目名称:ldc,代码行数:6,代码来源:linker.cpp

示例5: RStrip

static inline void RStrip(llvm::StringRef &Str, char c)
{
    if (!Str.empty() && Str.back() == c)
        Str = Str.substr(0, Str.size()-1);
}
开发者ID:AAZemlyanukhin,项目名称:freebsd,代码行数:5,代码来源:RegisterValue.cpp


注:本文中的llvm::StringRef::back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。