本文整理汇总了C++中StringRef::front方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::front方法的具体用法?C++ StringRef::front怎么用?C++ StringRef::front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::front方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
Optional<ReplacementItem>
formatv_object_base::parseReplacementItem(StringRef Spec) {
StringRef RepString = Spec.trim("{}");
// If the replacement sequence does not start with a non-negative integer,
// this is an error.
char Pad = ' ';
std::size_t Align = 0;
AlignStyle Where = AlignStyle::Right;
StringRef Options;
size_t Index = 0;
RepString = RepString.trim();
if (RepString.consumeInteger(0, Index)) {
assert(false && "Invalid replacement sequence index!");
return ReplacementItem{};
}
RepString = RepString.trim();
if (!RepString.empty() && RepString.front() == ',') {
RepString = RepString.drop_front();
if (!consumeFieldLayout(RepString, Where, Align, Pad))
assert(false && "Invalid replacement field layout specification!");
}
RepString = RepString.trim();
if (!RepString.empty() && RepString.front() == ':') {
Options = RepString.drop_front().trim();
RepString = StringRef();
}
RepString = RepString.trim();
if (!RepString.empty()) {
assert(false && "Unexpected characters found in replacement string!");
}
return ReplacementItem{Spec, Index, Align, Where, Pad, Options};
}
示例2: return
static std::string
auxName(StringRef ModuleName,
StringRef InputName,
StringRef TripleName,
StringRef OutputType,
StringRef OptType) {
if (InputName.empty()) {
InputName = "all";
}
// Dispose of path prefix, which might make composite name too long.
InputName = path::filename(InputName);
if (OptType.empty()) {
OptType = "Onone";
}
if (!OutputType.empty() && OutputType.front() == '.') {
OutputType = OutputType.substr(1);
}
if (!OptType.empty() && OptType.front() == '-') {
OptType = OptType.substr(1);
}
return (cleanName(ModuleName)
+ "-" + cleanName(InputName)
+ "-" + cleanName(TripleName)
+ "-" + cleanName(OutputType)
+ "-" + cleanName(OptType));
}
示例3: unescapeQuotedString
/// Unescapes the given string value.
///
/// Expects the string value to be quoted.
static std::string unescapeQuotedString(StringRef Value) {
assert(Value.front() == '"' && Value.back() == '"');
Cursor C = Cursor(Value.substr(1, Value.size() - 2));
std::string Str;
Str.reserve(C.remaining().size());
while (!C.isEOF()) {
char Char = C.peek();
if (Char == '\\') {
if (C.peek(1) == '\\') {
// Two '\' become one
Str += '\\';
C.advance(2);
continue;
}
if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
Str += hexDigitValue(C.peek(1)) * 16 + hexDigitValue(C.peek(2));
C.advance(3);
continue;
}
}
Str += Char;
C.advance();
}
return Str;
}
示例4: getAsSignedInteger
bool llvm::getAsSignedInteger(StringRef Str, unsigned Radix,
long long &Result) {
unsigned long long ULLVal;
// Handle positive strings first.
if (Str.empty() || Str.front() != '-') {
if (getAsUnsignedInteger(Str, Radix, ULLVal) ||
// Check for value so large it overflows a signed value.
(long long)ULLVal < 0)
return true;
Result = ULLVal;
return false;
}
// Get the positive part of the value.
if (getAsUnsignedInteger(Str.substr(1), Radix, ULLVal) ||
// Reject values so large they'd overflow as negative signed, but allow
// "-0". This negates the unsigned so that the negative isn't undefined
// on signed overflow.
(long long)-ULLVal > 0)
return true;
Result = -ULLVal;
return false;
}
示例5: getInstTypeMethodFamily
ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
if (!first) return OIT_None;
StringRef name = first->getName();
if (name.empty()) return OIT_None;
switch (name.front()) {
case 'a':
if (startsWithWord(name, "alloc")) return OIT_MemManage;
else
if (startsWithWord(name, "array")) return OIT_Array;
break;
case 'd':
if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
break;
case 'i':
if (startsWithWord(name, "init")) return OIT_MemManage;
break;
case 's':
if (startsWithWord(name, "string")) return OIT_NSString;
else
if (startsWithWord(name, "set")) return OIT_NSSet;
break;
case 'U':
if (startsWithWord(name, "URL")) return OIT_NSURL;
break;
default:
break;
}
return OIT_None;
}
示例6: getInstTypeMethodFamily
ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
if (!first) return OIT_None;
StringRef name = first->getName();
if (name.empty()) return OIT_None;
switch (name.front()) {
case 'a':
if (startsWithWord(name, "array")) return OIT_Array;
break;
case 'd':
if (startsWithWord(name, "default")) return OIT_ReturnsSelf;
if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
break;
case 's':
if (startsWithWord(name, "shared")) return OIT_ReturnsSelf;
if (startsWithWord(name, "standard")) return OIT_Singleton;
case 'i':
if (startsWithWord(name, "init")) return OIT_Init;
default:
break;
}
return OIT_None;
}
示例7: unescapeQuotedStringValue
void MIToken::unescapeQuotedStringValue(std::string &Str) const {
assert(isStringValueQuoted() && "String value isn't quoted");
StringRef Value = Range.drop_front(StringOffset);
assert(Value.front() == '"' && Value.back() == '"');
Cursor C = Cursor(Value.substr(1, Value.size() - 2));
Str.clear();
Str.reserve(C.remaining().size());
while (!C.isEOF()) {
char Char = C.peek();
if (Char == '\\') {
if (C.peek(1) == '\\') {
// Two '\' become one
Str += '\\';
C.advance(2);
continue;
}
if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
Str += hexDigitValue(C.peek(1)) * 16 + hexDigitValue(C.peek(2));
C.advance(3);
continue;
}
}
Str += Char;
C.advance();
}
}
示例8: scalarString
void Output::scalarString(StringRef &S) {
const char ScalarSafeChars[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/^., \t";
this->newLineCheck();
if (S.empty()) {
// Print '' for the empty string because leaving the field empty is not
// allowed.
this->outputUpToEndOfLine("''");
return;
}
if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
!isspace(S.front()) && !isspace(S.back())) {
// If the string consists only of safe characters, print it out without
// quotes.
this->outputUpToEndOfLine(S);
return;
}
unsigned i = 0;
unsigned j = 0;
unsigned End = S.size();
output("'"); // Starting single quote.
const char *Base = S.data();
while (j < End) {
// Escape a single quote by doubling it.
if (S[j] == '\'') {
output(StringRef(&Base[i], j - i + 1));
output("'");
i = j + 1;
}
++j;
}
output(StringRef(&Base[i], j - i));
this->outputUpToEndOfLine("'"); // Ending single quote.
}
示例9: getStringFormatFamilyImpl
ObjCStringFormatFamily Selector::getStringFormatFamilyImpl(Selector sel) {
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
if (!first) return SFF_None;
StringRef name = first->getName();
switch (name.front()) {
case 'a':
if (name == "appendFormat") return SFF_NSString;
break;
case 'i':
if (name == "initWithFormat") return SFF_NSString;
break;
case 'l':
if (name == "localizedStringWithFormat") return SFF_NSString;
break;
case 's':
if (name == "stringByAppendingFormat" ||
name == "stringWithFormat") return SFF_NSString;
break;
}
return SFF_None;
}
示例10: getMethodFamilyImpl
ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
if (!first) return OMF_None;
StringRef name = first->getName();
if (sel.isUnarySelector()) {
if (name == "autorelease") return OMF_autorelease;
if (name == "dealloc") return OMF_dealloc;
if (name == "finalize") return OMF_finalize;
if (name == "release") return OMF_release;
if (name == "retain") return OMF_retain;
if (name == "retainCount") return OMF_retainCount;
if (name == "self") return OMF_self;
if (name == "initialize") return OMF_initialize;
}
if (name == "performSelector" || name == "performSelectorInBackground" ||
name == "performSelectorOnMainThread")
return OMF_performSelector;
// The other method families may begin with a prefix of underscores.
while (!name.empty() && name.front() == '_')
name = name.substr(1);
if (name.empty()) return OMF_None;
switch (name.front()) {
case 'a':
if (startsWithWord(name, "alloc")) return OMF_alloc;
break;
case 'c':
if (startsWithWord(name, "copy")) return OMF_copy;
break;
case 'i':
if (startsWithWord(name, "init")) return OMF_init;
break;
case 'm':
if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
break;
case 'n':
if (startsWithWord(name, "new")) return OMF_new;
break;
default:
break;
}
return OMF_None;
}
示例11: getMDKindID
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
unsigned LLVMContext::getMDKindID(StringRef Name) const {
assert(!std::isdigit(Name.front()) &&
"Named metadata may not start with a digit");
// If this is new, assign it its ID.
return pImpl->CustomMDKindNames.insert(std::make_pair(
Name,
pImpl->CustomMDKindNames.size()))
.first->second;
}
示例12: lookupTypeForExtension
ID types::lookupTypeForExtension(StringRef Ext) {
if (Ext.empty())
return TY_INVALID;
assert(Ext.front() == '.' && "not a file extension");
return llvm::StringSwitch<types::ID>(Ext.drop_front())
#define TYPE(NAME, ID, SUFFIX, FLAGS) \
.Case(SUFFIX, TY_##ID)
#include "swift/Driver/Types.def"
.Default(TY_INVALID);
}
示例13: isValidUnquotedName
bool HSAILELFMCAsmInfo::isValidUnquotedName(StringRef Name) const {
char First = Name.front();
assert((First == '%' || First == '&' || First == '@') &&
"Missing valid prefix character");
Name = Name.drop_front(1);
if (!Name.empty()) {
if (!isValidFirstChar(Name.front()))
return false;
Name = Name.drop_front();
}
for (char C : Name) {
if (!isValidChar(C))
return false;
}
return true;
}
示例14: caseFoldingDjbHash
uint32_t llvm::caseFoldingDjbHash(StringRef Buffer, uint32_t H) {
while (!Buffer.empty()) {
unsigned char C = Buffer.front();
if (LLVM_LIKELY(C <= 0x7f)) {
// US-ASCII, encoded as one character in utf-8.
// This is by far the most common case, so handle this specially.
if (C >= 'A' && C <= 'Z')
C = 'a' + (C - 'A'); // fold uppercase into lowercase
H = (H << 5) + H + C;
Buffer = Buffer.drop_front();
continue;
}
H = caseFoldingDjbHashCharSlow(Buffer, H);
}
return H;
}
示例15: while
size_t CaseInsensitiveHashTable<T>::get_indices(StringRef name, IndexVec* result) const {
result->clear();
bool is_case_sensitive = false;
if (name.size() > 0 && name.front() == '"' && name.back() == '"') {
is_case_sensitive = true;
name = name.substr(1, name.size() - 2);
}
size_t h = fnv1a_hash_lower(name) & index_mask_;
size_t start = h;
while (index_[h] != NULL && !iequals(name, index_[h]->name)) {
h = (h + 1) & index_mask_;
if (h == start) {
return 0;
}
}
const T* entry = index_[h];
if (entry == NULL) {
return 0;
}
if (!is_case_sensitive) {
while (entry != NULL) {
result->push_back(entry->index);
entry = entry->next;
}
} else {
while (entry != NULL) {
if (name.equals(entry->name)) {
result->push_back(entry->index);
}
entry = entry->next;
}
}
return result->size();
}