本文整理汇总了C++中std::string::end方法的典型用法代码示例。如果您正苦于以下问题:C++ string::end方法的具体用法?C++ string::end怎么用?C++ string::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LookupCommand
int Server::LookupCommand(const std::string& uri, const std::string& http_verb, std::wstring* session_id, std::wstring* locator) {
int value = NoCommand;
UrlMap::const_iterator it = this->commands_.begin();
for (; it != this->commands_.end(); ++it) {
std::vector<std::string> locator_param_names;
std::string url_candidate = it->first;
size_t param_start_pos = url_candidate.find_first_of(":");
while (param_start_pos != std::string::npos) {
size_t param_len = std::string::npos;
size_t param_end_pos = url_candidate.find_first_of("/", param_start_pos);
if (param_end_pos != std::string::npos) {
param_len = param_end_pos - param_start_pos;
}
// Skip the colon
std::string param_name = url_candidate.substr(param_start_pos + 1, param_len - 1);
locator_param_names.push_back(param_name);
if (param_name == "sessionid" || param_name == "id") {
url_candidate.replace(param_start_pos, param_len, "([0-9a-fA-F-]+)");
} else {
url_candidate.replace(param_start_pos, param_len, "([^/]+)");
}
param_start_pos = url_candidate.find_first_of(":");
}
std::string::const_iterator uri_start = uri.begin();
std::string::const_iterator uri_end = uri.end();
std::tr1::regex matcher("^" + url_candidate + "$");
std::tr1::match_results<std::string::const_iterator> matches;
if (std::tr1::regex_search(uri_start, uri_end, matches, matcher)) {
VerbMap::const_iterator verb_iterator = it->second.find(http_verb);
if (verb_iterator != it->second.end()) {
value = verb_iterator->second;
std::string param = "{";
size_t param_count = locator_param_names.size();
for (unsigned int i = 0; i < param_count; i++) {
if (i != 0) {
param += ",";
}
std::string locator_param_value(matches[i + 1].first, matches[i + 1].second);
param += " \"" + locator_param_names[i] + "\" : \"" + locator_param_value + "\"";
if (locator_param_names[i] == "sessionid") {
session_id->append(CA2W(locator_param_value.c_str(), CP_UTF8));
}
}
param += " }";
std::wstring wide_param(param.begin(), param.end());
locator->append(wide_param);
break;
} else {
verb_iterator = it->second.begin();
for (; verb_iterator != it->second.end(); ++verb_iterator) {
if (locator->size() != 0) {
locator->append(L",");
}
locator->append(CA2W(verb_iterator->first.c_str(), CP_UTF8));
}
}
}
}
return value;
}
示例2: is_number
bool is_number(const std::string& s)
{
std::string::const_iterator it = s.begin();
while (it != s.end() && (isdigit(*it) || (*it == '.') || (*it == '-') || (*it == ' ') || (*it == 0x00))) ++it;
return !s.empty() && it == s.end();
}
示例3: copy_call_graph
void copy_call_graph( std::string const & input, std::string & output )
{
#if defined(_MSC_VER) && 0
output.reserve( input.size() );
unsigned int pos ( 0 );
unsigned int counter( 0 );
bool matched( false );
std::string buffer;
std::string::const_iterator p_ch ( input.begin() );
std::string::const_iterator const input_end( input.end () );
while ( p_ch != input_end )
{
char const ch( *p_ch++ );
buffer.push_back( ch );
if ( ch == '\n' )
{
if ( matched )
{
output.append( buffer );
if ( ++counter % 200 == 0 ) std::fprintf( stderr, "On Instantiation %d\n", counter/2 );
buffer.clear();
matched = false;
// process instantiation back-trace
pos = 0;
while ( p_ch != input_end )
{
char const ch( *p_ch++ );
if ( ch == ' ' )
{
buffer.push_back( ch );
while ( p_ch != input_end )
{
char const ch( *p_ch++ );
buffer.push_back( ch );
if ( ch == '\n' )
{
if ( matched )
{
output.append( buffer );
}
buffer.clear();
matched = false;
pos = 0;
break;
}
if ( ch == back_trace_search[ pos ] )
{
++pos;
if ( back_trace_search[ pos ] == '\0' )
{
matched = true;
}
}
else
{
pos = 0;
}
}
}
else
{
--p_ch;
break;
}
}
}
buffer.clear();
matched = false;
pos = 0;
}
if ( ch == search[ pos ] )
{
++pos;
if ( search[ pos ] == '\0' )
{
matched = true;
}
}
else
{
pos = 0;
}
}
#elif defined(__GNUC__) || 1
// trying to figure out what we should copy is too hard.
output = input;
#else
#error Unknown compiler
#endif
}
示例4: setQuirksSignature
void Signature::setQuirksSignature( std::string fp )
{
quirks_ = 0;
/*
* Quirks section is usually an empty list ('.') of oddities or bugs of this
* particular stack. List items are not separated in any way. Possible values:
*
* P - options past EOL,
* Z - zero IP ID,
* I - IP options specified,
* U - urg pointer non-zero,
* X - unused (x2) field non-zero,
* A - ACK number non-zero,
* T - non-zero second timestamp,
* F - unusual flags (PUSH, URG, etc),
* D - data payload,
* ! - broken options segment.
*/
std::string::iterator itr;
for( itr = fp.begin(); itr != fp.end(); ++itr )
{
switch( tolower(*itr) )
{
case 'p':
quirks_ |= QUIRK_PAST;
break;
case 'z':
quirks_ |= QUIRK_ZEROID;
break;
case 'i':
quirks_ |= QUIRK_IPOPT;
break;
case 'u':
quirks_ |= QUIRK_URG;
break;
case 'x':
quirks_ |= QUIRK_X2;
break;
case 'a':
quirks_ |= QUIRK_ACK;
break;
case 't':
quirks_ |= QUIRK_T2;
break;
case 'f':
quirks_ |= QUIRK_FLAGS;
break;
case 'd':
quirks_ |= QUIRK_DATA;
break;
case '!':
quirks_ |= QUIRK_BROKEN;
break;
case 'k':
quirks_ |= QUIRK_RSTACK;
break;
case 'q':
quirks_ |= QUIRK_SEQEQ;
break;
case '0':
quirks_ |= QUIRK_SEQ0;
break;
}
}
}
示例5: SerializeString
void ByteBuffer::SerializeString(const std::string &str) {
for (std::string::const_iterator i = str.begin();
i != str.end(); ++i)
buffer.push_back(*i);
buffer.push_back('\0');
}
示例6: handle_request
void RequestHandler::handle_request(const http::Request &req, http::Reply &reply)
{
// parse command
try
{
std::string request;
URIDecode(req.uri, request);
// deactivated as GCC apparently does not implement that, not even in 4.9
// std::time_t t = std::time(nullptr);
// SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
// " " << req.endpoint.to_string() << " " <<
// req.referrer << ( 0 == req.referrer.length() ? "- " :" ") <<
// req.agent << ( 0 == req.agent.length() ? "- " :" ") << request;
time_t ltime;
struct tm *Tm;
ltime = time(nullptr);
Tm = localtime(<ime);
// log timestamp
SimpleLogger().Write() << (Tm->tm_mday < 10 ? "0" : "") << Tm->tm_mday << "-"
<< (Tm->tm_mon + 1 < 10 ? "0" : "") << (Tm->tm_mon + 1) << "-"
<< 1900 + Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "")
<< Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "") << Tm->tm_min
<< ":" << (Tm->tm_sec < 10 ? "0" : "") << Tm->tm_sec << " "
<< req.endpoint.to_string() << " " << req.referrer
<< (0 == req.referrer.length() ? "- " : " ") << req.agent
<< (0 == req.agent.length() ? "- " : " ") << request;
RouteParameters route_parameters;
APIGrammarParser api_parser(&route_parameters);
auto iter = request.begin();
const bool result = boost::spirit::qi::parse(iter, request.end(), api_parser);
// check if the was an error with the request
if (!result || (iter != request.end()))
{
reply = http::Reply::StockReply(http::Reply::badRequest);
reply.content.clear();
const unsigned position = static_cast<unsigned>(std::distance(request.begin(), iter));
JSON::Object json_result;
json_result.values["status"] = 400;
std::string message = "Query string malformed close to position ";
message += UintToString(position);
json_result.values["status_message"] = message;
JSON::render(reply.content, json_result);
return;
}
// parsing done, lets call the right plugin to handle the request
BOOST_ASSERT_MSG(routing_machine != nullptr, "pointer not init'ed");
if (!route_parameters.jsonp_parameter.empty())
{ // prepend response with jsonp parameter
const std::string json_p = (route_parameters.jsonp_parameter + "(");
reply.content.insert(reply.content.end(), json_p.begin(), json_p.end());
}
routing_machine->RunQuery(route_parameters, reply);
if (!route_parameters.jsonp_parameter.empty())
{ // append brace to jsonp response
reply.content.push_back(')');
}
reply.headers.emplace_back("Access-Control-Allow-Origin", "*");
reply.headers.emplace_back("Access-Control-Allow-Methods", "GET");
reply.headers.emplace_back("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
// set headers
reply.headers.emplace_back("Content-Length",
UintToString(static_cast<unsigned>(reply.content.size())));
if ("gpx" == route_parameters.output_format)
{ // gpx file
reply.headers.emplace_back("Content-Type", "application/gpx+xml; charset=UTF-8");
reply.headers.emplace_back("Content-Disposition", "attachment; filename=\"route.gpx\"");
}
else if (route_parameters.jsonp_parameter.empty())
{ // json file
reply.headers.emplace_back("Content-Type", "application/json; charset=UTF-8");
reply.headers.emplace_back("Content-Disposition", "inline; filename=\"response.json\"");
}
else
{ // jsonp
reply.headers.emplace_back("Content-Type", "text/javascript; charset=UTF-8");
reply.headers.emplace_back("Content-Disposition", "inline; filename=\"response.js\"");
}
}
catch (const std::exception &e)
{
reply = http::Reply::StockReply(http::Reply::internalServerError);
SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
<< ", uri: " << req.uri;
return;
}
}
示例7: erase_all_characters
void Parser_XML::erase_all_characters(std::string& str, char character)
{
str.erase(std::remove(str.begin(), str.end(), character), str.end());
}
示例8: leftTrimString
void leftTrimString(std::string & str) noexcept {
auto begin(str.begin());
str.erase(begin, std::find_if_not(begin, str.end(), charIsSpace));
}
示例9: rightTrimString
void rightTrimString(std::string & str) noexcept {
str.erase(std::find_if_not(str.rbegin(), str.rend(), charIsSpace).base(),
str.end());
}
示例10: istringEqual
/** Test equality between two strings without regard to case. */
inline UTILITIES_API bool istringEqual(const std::string& x, const std::string& y){
return x.size() == y.size() &&
std::equal(x.begin(), x.end(), y.begin(), IcharCompare());
};
示例11: parseline
node parser::parseline(std::string linha){
linha.append(" "); // <--- super gambiarra, colocando espaço no final pro algoritmo funcionar
int flag_label = 0; //se ja tiver setado como 1, ou é o comando ou é parametro
int flag_comando = 0; //se ja tiver setado, primeiro parametro foi armazenado
int flag_parametro = 0; //para indicar se o primeiro parametro ja existe
std::string::iterator itr;
std::string buffer;
node r_node;
if(linha == "") //retorna nó vazio se a linha for vazia
return r_node;
//itera toda a linha
for(itr = linha.begin() ; itr != linha.end() ; itr++){
//se caractere nao for espaço, armazena na palavra
if((*itr) != ' ' && (*itr) != ',')
buffer.push_back((*itr));
/*
* se for espaço (final de palavra), verifica se é palavra chave.
* se for, armazena no atributo comando e seta flag comando para 1
* se nao for, armazena no atributo label, e seta label para 1
* se comando ja tiver setado em um, só pode ser parametro. seta parametro para 1
* se parametro ja tiver setado, só pode ser segundo parametro
*/
else{
std::cout << "WORD = " << buffer << std::endl;
//buffer.clear();
//caso seja palavra chave
if(iskeyword(buffer) && !(buffer.empty())){
flag_comando = 1;
r_node.comando = buffer;
buffer.clear();
}
//caso nao seja palavra chave e comando nao tenha sido encontrado ainda
if(flag_comando == 0 && !(buffer.empty())){
flag_label = 1;
r_node.label = buffer;
buffer.clear();
}
//caso comando ja tenha sido armazenado, prox palavra tem que ser parametro
if(flag_comando == 1 && flag_parametro == 0 && !(buffer.empty())){
flag_parametro = 1;
r_node.parametro1 = buffer;
buffer.clear();
}
//caso primeiro parametro ja exista
if(flag_parametro == 1 && !(buffer.empty())){
r_node.parametro2 = buffer;
buffer.clear();
}
/* ---------------------------- COMEÇO DO CODIGO ZUADO
if(iskeyword(buffer)){
flag_comando = 1;
return_node.comando = buffer;
buffer.clear();
}
else{
//se nao for keyword e label for zero, entao é label
if(flag_label == 0){
flag_label = 1;
return_node.label = buffer;
buffer.clear();
}
else{
//se comando e label ja existirem, entao é o primeiro parametro
if(flag_parametro == 0){
flag_parametro = 1;
return_node.parametro1 = buffer;
buffer.clear();
}
//se comando, label e o primeiro parametro ja existirem,
//entao é o segundo parametro
else{
return_node.parametro2 = buffer;
buffer.clear();
}
}
}
------------------------------- FIM DO CODIGO ZUADO */
}
}
return r_node;
}
示例12: put
void TickerInfoManager::put(std::string const& id, int total, int active) {
SharedString shid(id.begin(), id.end(), pimpl_->m_alloc);
lock_guard lock(pimpl_->mutex());
pimpl_->map()[shid] = { total, active };
}
示例13: string
static std::string unquote(std::string s)
{
if(s.empty() || s[0] != '"' || s.size() <= 2)
return s;
return std::string(++s.begin(), --s.end());
}
示例14: reverse
void reverse()
{
std::reverse(spattern.begin(),spattern.end());
pattern = spattern.c_str();
}
示例15: skill_string_to_enum
int skill_string_to_enum(std::string skillname)
{
std::transform(skillname.begin(), skillname.end(), skillname.begin(), ::tolower);
if (skillname == "handtohand")
return SKILL_HANDTOHAND;
else if (skillname == "knife")
return SKILL_KNIFE;
else if (skillname == "sword")
return SKILL_SWORD;
else if (skillname == "club")
return SKILL_CLUB;
else if (skillname == "axe")
return SKILL_AXE;
else if (skillname == "throwing")
return SKILL_THROWING;
else if (skillname == "pistol")
return SKILL_PISTOL;
else if (skillname == "rifle")
return SKILL_RIFLE;
else if (skillname == "smg")
return SKILL_SMG;
else if (skillname == "shotgun")
return SKILL_SHOTGUN;
else if (skillname == "persuasion")
return SKILL_PERSUASION;
else if (skillname == "psychology")
return SKILL_PSYCHOLOGY;
else if (skillname == "law")
return SKILL_LAW;
else if (skillname == "security")
return SKILL_SECURITY;
else if (skillname == "disguise")
return SKILL_DISGUISE;
else if (skillname == "computers")
return SKILL_COMPUTERS;
else if (skillname == "tailoring")
return SKILL_TAILORING;
else if (skillname == "driving")
return SKILL_DRIVING;
else if (skillname == "writing")
return SKILL_WRITING;
else if (skillname == "music")
return SKILL_MUSIC;
else if (skillname == "art")
return SKILL_ART;
else if (skillname == "religion")
return SKILL_RELIGION;
else if (skillname == "science")
return SKILL_SCIENCE;
else if (skillname == "business")
return SKILL_BUSINESS;
else if (skillname == "stealth")
return SKILL_STEALTH;
else if (skillname == "teaching")
return SKILL_TEACHING;
else if (skillname == "streetsense")
return SKILL_STREETSENSE;
else if (skillname == "seduction")
return SKILL_SEDUCTION;
else if (skillname == "firstaid")
return SKILL_FIRSTAID;
else if (skillname == "dodge")
return SKILL_DODGE;
else if (skillname == "heavyweapons")
return SKILL_HEAVYWEAPONS;
else
return -1;
}