本文整理汇总了C++中llvm::StringRef::size方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::size方法的具体用法?C++ StringRef::size怎么用?C++ StringRef::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::StringRef
的用法示例。
在下文中一共展示了StringRef::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: quoteArg
std::string quoteArg(llvm::StringRef arg) {
if (!needsQuotes(arg))
return arg;
std::string quotedArg;
quotedArg.reserve(3 + 2 * arg.size()); // worst case
quotedArg.push_back('"');
const size_t argLength = arg.size();
for (size_t i = 0; i < argLength; ++i) {
if (arg[i] == '"') {
// Escape all preceding backslashes (if any).
// Note that we *don't* need to escape runs of backslashes that don't
// precede a double quote! See MSDN:
// http://msdn.microsoft.com/en-us/library/17w5ykft%28v=vs.85%29.aspx
quotedArg.append(countPrecedingBackslashes(arg, i), '\\');
// Escape the double quote.
quotedArg.push_back('\\');
}
quotedArg.push_back(arg[i]);
}
// Make sure our final double quote doesn't get escaped by a trailing
// backslash.
quotedArg.append(countPrecedingBackslashes(arg, argLength), '\\');
quotedArg.push_back('"');
return quotedArg;
}
示例2: new
void
StringLiteral::setString(ASTContext &C, llvm::StringRef Str) {
char *AStrData = new (C, 1) char[Str.size()];
memcpy(AStrData, Str.data(), Str.size());
StrData = AStrData;
ByteLength = Str.size();
}
示例3: writeFile
static bool writeFile(llvm::StringRef file_name, llvm::StringRef data) {
std::error_code error_code;
llvm::raw_fd_ostream file(file_name, error_code, llvm::sys::fs::F_RW);
if (error_code)
return false;
int uncompressed_size = data.size();
// Write the uncompressed size to the beginning of the file as a simple checksum.
// It looks like each lz4 block has its own data checksum, but we need to also
// make sure that we have all the blocks that we expected.
// In particular, without this, an empty file seems to be a valid lz4 stream.
file.write(reinterpret_cast<const char*>(&uncompressed_size), 4);
LZ4F_preferences_t preferences;
memset(&preferences, 0, sizeof(preferences));
preferences.frameInfo.contentChecksumFlag = contentChecksumEnabled;
preferences.frameInfo.contentSize = data.size();
std::vector<char> compressed;
size_t max_size = LZ4F_compressFrameBound(data.size(), &preferences);
compressed.resize(max_size);
size_t compressed_size = LZ4F_compressFrame(&compressed[0], max_size, data.data(), data.size(), &preferences);
if (LZ4F_isError(compressed_size))
return false;
file.write(compressed.data(), compressed_size);
return true;
}
示例4: GetStringSize
std::size_t WireEncoder::GetStringSize(llvm::StringRef str) const {
if (m_proto_rev < 0x0300u) {
std::size_t len = str.size();
if (len > 0xffff) len = 0xffff; // Limited to 64K length; truncate
return 2 + len;
}
return SizeUleb128(str.size()) + str.size();
}
示例5: SetString
void PythonString::SetString(llvm::StringRef string) {
#if PY_MAJOR_VERSION >= 3
PyObject *unicode = PyUnicode_FromStringAndSize(string.data(), string.size());
PythonObject::Reset(PyRefType::Owned, unicode);
#else
PyObject *str = PyString_FromStringAndSize(string.data(), string.size());
PythonObject::Reset(PyRefType::Owned, str);
#endif
}
示例6: emitRecord
void ClangDocBitcodeWriter::emitRecord(llvm::StringRef Str, RecordId ID) {
assert(RecordIdNameMap[ID] && "Unknown RecordId.");
assert(RecordIdNameMap[ID].Abbrev == &StringAbbrev &&
"Abbrev type mismatch.");
if (!prepRecordData(ID, !Str.empty()))
return;
assert(Str.size() < (1U << BitCodeConstants::StringLengthSize));
Record.push_back(Str.size());
Stream.EmitRecordWithBlob(Abbrevs.get(ID), Record, Str);
}
示例7: EscapeBackticks
static void EscapeBackticks(llvm::StringRef str, std::string &dst) {
dst.clear();
dst.reserve(str.size());
for (size_t i = 0, e = str.size(); i != e; ++i) {
char c = str[i];
if (c == '`') {
if (i == 0 || str[i - 1] != '\\')
dst += '\\';
}
dst += c;
}
}
示例8: PreprocessingDirective
InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
InclusionKind Kind,
llvm::StringRef FileName,
bool InQuotes, const FileEntry *File,
SourceRange Range)
: PreprocessingDirective(InclusionDirectiveKind, Range),
InQuotes(InQuotes), Kind(Kind), File(File)
{
char *Memory
= (char*)PPRec.Allocate(FileName.size() + 1, llvm::alignOf<char>());
memcpy(Memory, FileName.data(), FileName.size());
Memory[FileName.size()] = 0;
this->FileName = llvm::StringRef(Memory, FileName.size());
}
示例9: 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);
}
示例10: loadDictionaryEntry
void TemplightProtobufReader::loadDictionaryEntry(llvm::StringRef aSubBuffer) {
// Set default values:
std::string name = "";
llvm::SmallVector<std::size_t,8> markers;
while ( aSubBuffer.size() ) {
unsigned int cur_wire = llvm::protobuf::loadVarInt(aSubBuffer);
switch( cur_wire ) {
case llvm::protobuf::getStringWire<1>::value:
name = llvm::protobuf::loadString(aSubBuffer);
break;
case llvm::protobuf::getVarIntWire<2>::value:
markers.push_back(llvm::protobuf::loadVarInt(aSubBuffer));
break;
default:
llvm::protobuf::skipData(aSubBuffer, cur_wire);
break;
}
}
std::string::iterator it_name = std::find(name.begin(), name.end(), '\0');
llvm::SmallVector<std::size_t,8>::iterator it_mark = markers.begin();
while ( ( it_name != name.end() ) && ( it_mark != markers.end() ) ) {
std::size_t offset = it_name - name.begin();
name.replace(it_name, it_name + 1, templateNameMap[*it_mark]);
it_name = std::find(name.begin() + offset, name.end(), '\0');
++it_mark;
}
templateNameMap.push_back(name);
}
示例11: loadTemplateName
void TemplightProtobufReader::loadTemplateName(llvm::StringRef aSubBuffer) {
// Set default values:
LastBeginEntry.Name = "";
while ( aSubBuffer.size() ) {
unsigned int cur_wire = llvm::protobuf::loadVarInt(aSubBuffer);
switch( cur_wire ) {
case llvm::protobuf::getStringWire<1>::value:
LastBeginEntry.Name = llvm::protobuf::loadString(aSubBuffer);
break;
case llvm::protobuf::getStringWire<2>::value: {
LastBeginEntry.Name = llvm::protobuf::loadString(aSubBuffer);
llvm::SmallVector<char,32> UBuf;
if ( llvm::zlib::uncompress(LastBeginEntry.Name, UBuf, LastBeginEntry.Name.size() * 2)
== llvm::zlib::StatusOK )
LastBeginEntry.Name.assign(UBuf.begin(), UBuf.end());
else
LastBeginEntry.Name = "";
break;
}
case llvm::protobuf::getVarIntWire<3>::value: {
LastBeginEntry.Name = templateNameMap[llvm::protobuf::loadVarInt(aSubBuffer)];
break;
}
default:
llvm::protobuf::skipData(aSubBuffer, cur_wire);
break;
}
}
}
示例12: ReverseFindMatchingChars
bool ReverseFindMatchingChars(const llvm::StringRef &s,
const llvm::StringRef &left_right_chars,
size_t &left_pos, size_t &right_pos,
size_t pos = llvm::StringRef::npos) {
assert(left_right_chars.size() == 2);
left_pos = llvm::StringRef::npos;
const char left_char = left_right_chars[0];
const char right_char = left_right_chars[1];
pos = s.find_last_of(left_right_chars, pos);
if (pos == llvm::StringRef::npos || s[pos] == left_char)
return false;
right_pos = pos;
uint32_t depth = 1;
while (pos > 0 && depth > 0) {
pos = s.find_last_of(left_right_chars, pos);
if (pos == llvm::StringRef::npos)
return false;
if (s[pos] == left_char) {
if (--depth == 0) {
left_pos = pos;
return left_pos < right_pos;
}
} else if (s[pos] == right_char) {
++depth;
}
}
return false;
}
示例13: PutString
size_t DiagnosticManager::PutString(DiagnosticSeverity severity,
llvm::StringRef str) {
if (str.empty())
return 0;
AddDiagnostic(str, severity, eDiagnosticOriginLLDB);
return str.size();
}
示例14: 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);
}
示例15: getThunkTarget
std::string Context::getThunkTarget(llvm::StringRef MangledName) {
if (!isThunkSymbol(MangledName))
return std::string();
if (isMangledName(MangledName)) {
// The targets of those thunks not derivable from the mangling.
if (MangledName.endswith("TR") ||
MangledName.endswith("Tr") ||
MangledName.endswith("TW") )
return std::string();
if (MangledName.endswith("fC")) {
std::string target = MangledName.str();
target[target.size() - 1] = 'c';
return target;
}
return MangledName.substr(0, MangledName.size() - 2).str();
}
// Old mangling.
assert(MangledName.startswith("_T"));
StringRef Remaining = MangledName.substr(2);
if (Remaining.startswith("PA_"))
return Remaining.substr(3).str();
if (Remaining.startswith("PAo_"))
return Remaining.substr(4).str();
assert(Remaining.startswith("To") || Remaining.startswith("TO"));
return std::string("_T") + Remaining.substr(2).str();
}