本文整理汇总了C++中boost::starts_with方法的典型用法代码示例。如果您正苦于以下问题:C++ boost::starts_with方法的具体用法?C++ boost::starts_with怎么用?C++ boost::starts_with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost
的用法示例。
在下文中一共展示了boost::starts_with方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_frame
static inline std::streamsize
get_frame(std::istream& is, std::vector<char>& buf)
{
using boost::lexical_cast;
using boost::starts_with;
static const std::string b{"--RaNd0m"};
static const std::string cl{"Content-length: "};
std::string line{};
do {
std::getline(is, line);
}
while (is.good() && !starts_with(line, b));
do {
std::getline(is, line);
}
while (is.good() && !starts_with(line, cl));
if (is.eof()) {
return false;
}
else if (is.bad()) {
throw std::runtime_error{"Error finding start of frame."};
}
std::size_t n;
try {
auto s = line.substr(cl.length(), line.length() - cl.length() - 1);
n = boost::lexical_cast<std::size_t>(std::move(s));
}
catch (boost::bad_lexical_cast& e) {
throw std::runtime_error{"Error parsing content length."};
}
if (n <= 0) {
throw std::runtime_error{"Content length not positive."};
}
if (buf.size() < n) {
buf.resize(n);
}
std::getline(is, line);
if (!(line.length() == 1 && line[0] == '\r')) {
throw std::runtime_error{"Expected \"\\r\\n\" before frame contents."};
}
is.read(buf.data(), n);
if (is.bad()) {
throw std::runtime_error{"Error reading frame contents."};
}
else {
return true;
}
}
示例2: TranslateRequest
void UploaderImp::TranslateRequest()
{
std::istream s( &request_ );
std::string line;
s >> line; //method
if( line == "GET" ) method_ = GET;
else if( line == "HEAD" ) method_ = HEAD;
else throw Unhandled(400, "Unknown method" );
s >> line; //object
if( !starts_with( line, "/uri-res/N2R?" ) )
throw Unhandled(400, "Requested uri type is not supported");
std::string last = urn_;
urn_ = line.substr(line.find('?') + 1);
fileInfo_ = System::GetShareMgr()->GetByUrn( urn_ );
if(last != urn_)
{
System::LogBas() << "Host " << endpoint_ << " requested file: " << fileInfo_.Name() << std::endl;
fileInfo_.IncreaseRequests();
}
while( std::getline( s, line ) && line != "\r" )
{
std::string value = boost::trim_copy( line.substr( line.find( ':' ) + 1 ) );
if( istarts_with( line, "Connection:" ) )
keepAlive_ = iequals( value, "keep-alive" );
else if( istarts_with( line, "X-Nick:" ) )
nick_ = value;
else if(istarts_with(line, "User-Agent:") && client_ != value)
{
client_ = value;
if(System::GetSecurity()->AgentRestricted(client_))
throw Unhandled(403, "Client software is restricted");
}
else if( istarts_with( line, "Range:" ) )
{
file_offset_t first = 0;
file_offset_t last = 0;
int result = sscanf( value.c_str(), "bytes=%llu-%llu", &first, &last );
if( result == 0 ) throw Unhandled(416, "Couldn't parse range");
if( result == 1 ) range_.SetBoundary( first, fileInfo_.Size() - 1);
if( result == 2 ) range_.SetBoundary( first, last );
}
}
if( range_.Empty() ) throw std::range_error( "Range is empty" );
// std::cout << range_.Last() << " " << fileInfo.Size() << std::endl;
if( range_.Last() >= fileInfo_.Size() )
throw Unhandled(416, "Range is too large" );
}
示例3: assert
void mdb_shell::filter_metaprogram() {
assert(mp);
using boost::starts_with;
using boost::ends_with;
using boost::trim_copy;
using vertex_descriptor = metaprogram::vertex_descriptor;
using edge_descriptor = metaprogram::edge_descriptor;
using edge_property = metaprogram::edge_property;
using discovered_t = metaprogram::discovered_t;
static const std::string wrap_prefix = "metashell::impl::wrap<";
static const std::string wrap_suffix = ">";
// TODO this check could be made more strict,
// since we now whats inside wrap<...> (mp->get_evaluation_result)
auto is_wrap_type = [](const std::string& type) {
return starts_with(type, wrap_prefix) && ends_with(type, wrap_suffix);
};
std::string env_buffer = env.get();
int line_number = std::count(env_buffer.begin(), env_buffer.end(), '\n');
// First disable everything
for (edge_descriptor edge : mp->get_edges()) {
mp->get_edge_property(edge).enabled = false;
}
// We will traverse the interesting edges later
std::stack<edge_descriptor> edge_stack;
// Enable the interesting root edges
for (edge_descriptor edge : mp->get_out_edges(mp->get_root_vertex())) {
edge_property& property = mp->get_edge_property(edge);
const std::string& target_name =
mp->get_vertex_property(mp->get_target(edge)).name;
// Filter out edges, that is not instantiated by the entered type
if (property.point_of_instantiation.name == internal_file_name &&
property.point_of_instantiation.row == line_number + 2 &&
(property.kind == instantiation_kind::template_instantiation ||
property.kind == instantiation_kind::memoization) &&
(!is_wrap_type(target_name) ||
property.kind != instantiation_kind::memoization))
{
property.enabled = true;
edge_stack.push(edge);
}
}
discovered_t discovered(mp->get_num_vertices());
// Traverse the graph to enable all edges which are reachable from the
// edges enabled above
while (!edge_stack.empty()) {
edge_descriptor edge = edge_stack.top();
edge_stack.pop();
assert(mp->get_edge_property(edge).enabled);
vertex_descriptor vertex = mp->get_target(edge);
if (discovered[vertex]) {
continue;
}
for (edge_descriptor out_edge : mp->get_out_edges(vertex)) {
edge_property& property = mp->get_edge_property(out_edge);
if (property.kind == instantiation_kind::template_instantiation ||
property.kind == instantiation_kind::memoization)
{
property.enabled = true;
edge_stack.push(out_edge);
}
}
}
// Unwrap vertex names
for (metaprogram::vertex_descriptor vertex : mp->get_vertices()) {
std::string& name = mp->get_vertex_property(vertex).name;
if (is_wrap_type(name)) {
name = trim_copy(name.substr(
wrap_prefix.size(),
name.size() - wrap_prefix.size() - wrap_suffix.size()));
if (!is_template_type(name)) {
for (metaprogram::edge_descriptor in_edge : mp->get_in_edges(vertex)) {
mp->get_edge_property(in_edge).kind =
instantiation_kind::non_template_type;
}
}
}
}
// Clang sometimes produces equivalent instantiations events from the same
// point. Filter out all but one of each
for (metaprogram::vertex_descriptor vertex : mp->get_vertices()) {
typedef std::tuple<file_location, instantiation_kind, vertex_descriptor>
set_element_t;
std::set<set_element_t> similar_edges;
//.........这里部分代码省略.........
示例4: if
void
FortranProgramDeclarationsAndDefinitions::visit (SgNode * node)
{
using boost::filesystem::path;
using boost::filesystem::system_complete;
using boost::iequals;
using boost::starts_with;
using boost::lexical_cast;
using std::string;
if (isSgSourceFile (node))
{
path p = system_complete (path (isSgSourceFile (node)->getFileName ()));
currentSourceFile = p.filename ();
Debug::getInstance ()->debugMessage ("Source file '" + currentSourceFile
+ "' detected", Debug::OUTER_LOOP_LEVEL, __FILE__, __LINE__ );
}
else if (Globals::getInstance ()->isInputFile (currentSourceFile))
{
/*
* ======================================================
* Only process this portion of the AST if we recognise
* this source file as one passed on the command line. In
* Fortran, .rmod files are sometimes generated whose
* traversal should be avoided
* ======================================================
*/
switch (node->variantT ())
{
case V_SgModuleStatement:
{
SgModuleStatement * moduleStatement = isSgModuleStatement (node);
currentModuleName = moduleStatement->get_name ().getString ();
fileNameToModuleNames[currentSourceFile].push_back (currentModuleName);
moduleNameToFileName[currentModuleName] = currentSourceFile;
Debug::getInstance ()->debugMessage ("Module '" + currentModuleName
+ "' in file '" + currentSourceFile + "'", Debug::OUTER_LOOP_LEVEL,
__FILE__, __LINE__ );
break;
}
case V_SgProcedureHeaderStatement:
{
/*
* ======================================================
* We need to store all subroutine definitions since we
* later have to copy and modify the user kernel subroutine
* ======================================================
*/
SgProcedureHeaderStatement * procedureHeaderStatement =
isSgProcedureHeaderStatement (node);
string const subroutineName =
procedureHeaderStatement->get_name ().getString ();
subroutinesInSourceCode[subroutineName] = procedureHeaderStatement;
ROSE_ASSERT (currentModuleName.size() > 0);
moduleNameToSubroutines[currentModuleName].push_back (subroutineName);
subroutineToFileName[subroutineName] = currentSourceFile;
Debug::getInstance ()->debugMessage (
"Found procedure header statement '"
+ procedureHeaderStatement->get_name ().getString ()
+ "' in file '" + currentSourceFile + "', and module '"
+ currentModuleName + "'", Debug::FUNCTION_LEVEL, __FILE__,
__LINE__);
break;
}
case V_SgFunctionCallExp:
{
/*
* ======================================================
* Function call found in the AST. Get its actual arguments
* and the callee name
* ======================================================
*/
SgFunctionCallExp * functionCallExp = isSgFunctionCallExp (node);
SgExprListExp * actualArguments = functionCallExp->get_args ();
string const
calleeName =
functionCallExp->getAssociatedFunctionSymbol ()->get_name ().getString ();
Debug::getInstance ()->debugMessage ("Found function call '"
+ calleeName + "'", Debug::OUTER_LOOP_LEVEL, __FILE__, __LINE__);
//.........这里部分代码省略.........
示例5: auto_match_karaoke
karaoke_match_result auto_match_karaoke(std::vector<std::string> const& source_strings, std::string const& dest_string) {
karaoke_match_result result = { 0, 0 };
if (source_strings.empty()) return result;
using namespace boost::locale::boundary;
using boost::starts_with;
result.source_length = 1;
ssegment_index destination_characters(character, begin(dest_string), end(dest_string));
auto src = boost::to_lower_copy(source_strings[0]);
auto dst = destination_characters.begin();
auto dst_end = destination_characters.end();
// Eat all the whitespace at the beginning of the source and destination
// syllables and exit if either ran out.
auto eat_whitespace = [&]() -> bool {
size_t i = 0, first_non_whitespace = 0;
while (is_whitespace(next_codepoint(src.c_str(), &i)))
first_non_whitespace = i;
if (first_non_whitespace)
src = src.substr(first_non_whitespace);
while (dst != dst_end && is_whitespace(dst->str())) {
++dst;
++result.destination_length;
}
// If we ran out of dest then this needs to match the rest of the
// source syllables (this probably means the user did something wrong)
if (dst == dst_end) {
result.source_length = source_strings.size();
return true;
}
return src.empty();
};
if (eat_whitespace()) return result;
// We now have a non-whitespace character at the beginning of both source
// and destination. Check if the source starts with a romanized kana, and
// if it does then check if the destination also has the appropriate
// character. If it does, match them and repeat.
while (!src.empty()) {
// First check for a basic match of the first character of the source and dest
auto first_src_char = ssegment_index(character, begin(src), end(src)).begin()->str();
if (compare(first_src_char, dst->str()) == 0) {
++dst;
++result.destination_length;
src.erase(0, first_src_char.size());
if (eat_whitespace()) return result;
continue;
}
auto check = [&](kana_pair const& kp) -> bool {
if (!starts_with(&*dst->begin(), kp.kana)) return false;
src = src.substr(strlen(kp.romaji));
for (size_t i = 0; kp.kana[i]; ) {
i += dst->length();
++result.destination_length;
++dst;
}
return true;
};
bool matched = false;
for (auto const& match : romaji_to_kana(src)) {
if (check(match)) {
if (eat_whitespace()) return result;
matched = true;
break;
}
}
if (!matched) break;
}
// Source and dest are now non-empty and start with non-whitespace.
// If there's only one character left in the dest, it obviously needs to
// match all of the source syllables left.
if (std::distance(dst, dst_end) == 1) {
result.source_length = source_strings.size();
++result.destination_length;
return result;
}
// We couldn't match the current character, but if we can match the *next*
// syllable then we know that everything in between must belong to the
// current syllable. Do this by looking up to KANA_SEARCH_DISTANCE
// characters ahead in destination and seeing if we can match them against
// the beginning of a syllable after this syllable.
// If a match is found, make a guess at how much source and destination
// should be selected based on the distances it was found at.
// The longest kanji are 'uketamawa.ru' and 'kokorozashi', each with a
// reading consisting of five kana. This means each each character from
// the destination can match at most five syllables from the source.
static const int max_character_length = 5;
// Arbitrarily chosen limit on the number of dest characters to try
//.........这里部分代码省略.........