本文整理汇总了C++中StringRef::consume_front方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::consume_front方法的具体用法?C++ StringRef::consume_front怎么用?C++ StringRef::consume_front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::consume_front方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: URI
Expected<URI> uriFromAbsolutePath(StringRef AbsolutePath) const override {
StringRef Body = AbsolutePath;
if (!Body.consume_front(testRoot()))
return make_error<StringError>(AbsolutePath + "does not start with " +
testRoot(),
inconvertibleErrorCode());
return URI(Scheme, /*Authority=*/"", sys::path::convert_to_slash(Body));
}
示例2: HandleComment
bool HandleComment(Preprocessor &PP, SourceRange Range) override {
StringRef Text =
Lexer::getSourceText(CharSourceRange::getCharRange(Range),
PP.getSourceManager(), PP.getLangOpts());
if (!Text.consume_front(IWYUPragma))
return false;
// FIXME(ioeric): resolve the header and store actual file path. For now,
// we simply assume the written header is suitable to be #included.
Includes->addMapping(PP.getSourceManager().getFilename(Range.getBegin()),
isLiteralInclude(Text) ? Text.str()
: ("\"" + Text + "\"").str());
return false;
}
示例3: testPath
Expected<std::string> getAbsolutePath(StringRef /*Authority*/, StringRef Body,
StringRef HintPath) const override {
if (!HintPath.startswith(testRoot()))
return make_error<StringError>(
"Hint path doesn't start with test root: " + HintPath,
inconvertibleErrorCode());
if (!Body.consume_front("/"))
return make_error<StringError>(
"Body of an unittest: URI must start with '/'",
inconvertibleErrorCode());
SmallString<16> Path(Body.begin(), Body.end());
sys::path::native(Path);
return testPath(Path);
}
示例4: parseCommand
static bool parseCommand(StringRef InputString, bool &IsData,
std::string &ModuleName, uint64_t &ModuleOffset) {
const char kDelimiters[] = " \n\r";
ModuleName = "";
if (InputString.consume_front("CODE ")) {
IsData = false;
} else if (InputString.consume_front("DATA ")) {
IsData = true;
} else {
// If no cmd, assume it's CODE.
IsData = false;
}
const char *pos = InputString.data();
// Skip delimiters and parse input filename (if needed).
if (ClBinaryName.empty()) {
pos += strspn(pos, kDelimiters);
if (*pos == '"' || *pos == '\'') {
char quote = *pos;
pos++;
const char *end = strchr(pos, quote);
if (!end)
return false;
ModuleName = std::string(pos, end - pos);
pos = end + 1;
} else {
int name_length = strcspn(pos, kDelimiters);
ModuleName = std::string(pos, name_length);
pos += name_length;
}
} else {
ModuleName = ClBinaryName;
}
// Skip delimiters and parse module offset.
pos += strspn(pos, kDelimiters);
int offset_length = strcspn(pos, kDelimiters);
return !StringRef(pos, offset_length).getAsInteger(0, ModuleOffset);
}
示例5: server_thread
TEST_F(GDBRemoteCommunicationClientTest, TestPacketSpeedJSON) {
std::thread server_thread([this] {
for (;;) {
StringExtractorGDBRemote request;
PacketResult result = server.GetPacket(request);
if (result == PacketResult::ErrorDisconnected)
return;
ASSERT_EQ(PacketResult::Success, result);
StringRef ref = request.GetStringRef();
ASSERT_TRUE(ref.consume_front("qSpeedTest:response_size:"));
int size;
ASSERT_FALSE(ref.consumeInteger(10, size)) << "ref: " << ref;
std::string response(size, 'X');
ASSERT_EQ(PacketResult::Success, server.SendPacket(response));
}
});
StreamString ss;
client.TestPacketSpeed(10, 32, 32, 4096, true, ss);
client.Disconnect();
server_thread.join();
GTEST_LOG_(INFO) << "Formatted output: " << ss.GetData();
auto object_sp = StructuredData::ParseJSON(ss.GetString());
ASSERT_TRUE(bool(object_sp));
auto dict_sp = object_sp->GetAsDictionary();
ASSERT_TRUE(bool(dict_sp));
object_sp = dict_sp->GetValueForKey("packet_speeds");
ASSERT_TRUE(bool(object_sp));
dict_sp = object_sp->GetAsDictionary();
ASSERT_TRUE(bool(dict_sp));
int num_packets;
ASSERT_TRUE(dict_sp->GetValueForKeyAsInteger("num_packets", num_packets))
<< ss.GetString();
ASSERT_EQ(10, num_packets);
}
示例6: getMVTName
StringRef ValueTypeByHwMode::getMVTName(MVT T) {
StringRef N = llvm::getEnumName(T.SimpleTy);
N.consume_front("MVT::");
return N;
}