本文整理汇总了C++中boost::string_ref::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string_ref::substr方法的具体用法?C++ string_ref::substr怎么用?C++ string_ref::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::string_ref
的用法示例。
在下文中一共展示了string_ref::substr方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckProtocol
Protocol CHttpUrl::CheckProtocol(boost::string_ref const &url, size_t &index)
{
Protocol protocol;
auto pos = url.find("://");
if (pos != url.size())
{
if (url.substr(0, pos) == "https")
{
protocol = Protocol::HTTPS;
}
else if (url.substr(0, pos) == "http")
{
protocol = Protocol::HTTP;
}
else
{
throw std::invalid_argument("Protocol uncorrect.");
}
if (index == url.size())
{
throw std::invalid_argument("Invalid url was introduced");
}
}
index = pos + 3;
return protocol;
}
示例2: ParsePort
unsigned short CHttpUrl::ParsePort(boost::string_ref & str)
{
if (str.front() == ':')
{
auto portPos = str.find('/');
string port;
if (portPos == boost::string_ref::npos)
{
port = str.substr(1, str.size()).to_string();
}
else
{
port = str.substr(1, portPos - 1).to_string();
}
str = str.substr(port.size() + 1, str.size());
bool portOk = !port.empty();
if (portOk)
{
try
{
return boost::lexical_cast<unsigned short>(port);
}
catch (...)
{
portOk = false;
}
}
if (!portOk)
{
throw CUrlParsingError("Port parsing error");
}
}
return 0;
}
示例3: ParseDomain
std::string CHttpUrl::ParseDomain(boost::string_ref & url)
{
auto domainPos = url.find(':');
if (domainPos == boost::string_ref::npos)
{
domainPos = url.find("/");
domainPos = (domainPos == boost::string_ref::npos ? url.size() : domainPos);
}
auto domain = url.substr(0, domainPos).to_string();
url = url.substr(domainPos, url.size());
return domain;
}
示例4: ParseProtocol
Protocol CHttpUrl::ParseProtocol(boost::string_ref & str)
{
const string schemeDelimiter = "://";
auto schemePos = str.find(schemeDelimiter);
if (schemePos == boost::string_ref::npos)
{
throw CUrlParsingError("Protocol parsing error");
}
string protocol = str.substr(0, schemePos).to_string();
str = str.substr(schemePos + schemeDelimiter.size() , str.size() - 1);
return ToProtocol(protocol);
}
示例5: ParseDomainName
std::string CHttpUrl::ParseDomainName(boost::string_ref const &url, size_t &index)
{
for (size_t i = 0; i != url.size(); ++i)
{
if (url[i] == '/')
{
index += i;
return std::string(url.substr(0, i));
}
if (url[i] == ':')
{
m_port = ParsePort(url, i + 1);
return std::string(url.substr(0, i));
}
}
index += url.size();
return std::string(url);
}
示例6:
boost::iterator_range<
boost::filter_iterator<glob_matcher, directory_iterator>
>
match_files(const boost::string_ref glob)
{
auto end = glob.rfind(PLATFORM_DIRECTORY_SEPARATOR);
if (end == boost::string_ref::npos) {
throw std::invalid_argument{"Invalid glob string."};
}
return {
boost::make_filter_iterator(
glob_matcher{glob.substr(end + 1)},
directory_iterator{glob.substr(0, end)},
directory_iterator{}
),
boost::make_filter_iterator(
glob_matcher{},
directory_iterator{},
directory_iterator{}
)
};
}
示例7: IsMatch
bool HttpAbpBaseFilter::IsMatch(boost::string_ref data, const HttpAbpFilterSettings dataSettings, boost::string_ref dataHost) const
{
if (!SettingsApply(dataSettings, m_settings))
{
return false;
}
size_t i = 0;
auto len = m_ruleParts.size();
size_t lastMatch = 0;
for (i = 0; i < m_ruleParts.size(); ++i)
{
switch (m_rulePartTypes[i])
{
// Anchored address matching is basically a confusing way to say that we
// must match against the host of the request, AFAIK.
//
// However, we have a double wammy. If we match against the host, we
// need to then find that same matched string in the full request and
// substring the data from beyond our matched address string. This is a
// PITA and a bit of a waste, but we check the dataHost member first
// specifically, to avoid false positives, such as Google search results
// that embed a URL we're trying to match against in GET parameters.
case RulePartType::AnchoredAddress:
{
auto hostLen = dataHost.size();
auto plen = m_ruleParts[i].size();
if (plen <= hostLen)
{
auto res = dataHost.find(m_ruleParts[i]);
if (res != boost::string_ref::npos)
{
auto hostInReqPos = data.find(dataHost);
if (hostInReqPos != boost::string_ref::npos)
{
lastMatch = hostInReqPos + res + plen;
continue;
}
}
}
return false;
}
break;
case RulePartType::Wildcard:
{
// Wildcard, so as long as we have one additional character, we can move on.
if (lastMatch + 1 <= data.size())
{
++lastMatch;
continue;
}
return false;
}
break;
case RulePartType::Separator:
{
if (lastMatch < data.size())
{
data = data.substr(lastMatch);
auto sepPosition = data.find_first_of(SeparatorStrRef);
if (sepPosition != boost::string_ref::npos)
{
lastMatch = sepPosition + 1;
continue;
}
}
return false;
}
break;
case RulePartType::StringLiteral:
{
if (lastMatch < data.size())
{
data = data.substr(lastMatch);
size_t literalTextPosition = data.find(m_ruleParts[i]);
if(literalTextPosition != boost::string_ref::npos)
{
lastMatch = literalTextPosition + m_ruleParts[i].size();
continue;
}
}
return false;
}
break;
//.........这里部分代码省略.........
示例8: pdibuf
/* irc_inline() - 1 single line received from serv */
void
server::p_inline (const boost::string_ref& text)
{
session *sess;
char *type;
char *word[PDIWORDS+1];
char *word_eol[PDIWORDS+1];
message_tags_data tags_data = message_tags_data();
std::string pdibuf(text.size(), '\0');
sess = this->front_session;
/* Python relies on this */
word[PDIWORDS] = NULL;
word_eol[PDIWORDS] = NULL;
std::string buf;
if (text.starts_with('@'))
{
auto sep = text.find_first_of(' ');
if (sep == boost::string_ref::npos)
return;
/* skip the '@' */
auto tags = text.substr(1, sep - 1);
buf = text.substr(sep + 1).to_string();
handle_message_tags(*this, tags, tags_data);
}
else
{
buf = text.to_string();
}
url_check_line(buf.data(), buf.size());
/* split line into words and words_to_end_of_line */
process_data_init (&pdibuf[0], &buf[0], word, word_eol, false, false);
if (buf[0] == ':')
{
/* find a context for this message */
if (this->is_channel_name (word[3]))
{
auto tmp = find_channel (word[3]);
if (tmp)
sess = &(*tmp);
}
/* for server messages, the 2nd word is the "message type" */
type = word[2];
word[0] = type;
word_eol[1] = &buf[0]; /* keep the ":" for plugins */
if (plugin_emit_server(sess, type, word, word_eol,
tags_data.timestamp))
{
return;
}
word[1]++;
word_eol[1] = &buf[1]; /* but not for HexChat internally */
} else
{
word[0] = type = word[1];
if (plugin_emit_server(sess, type, word, word_eol,
tags_data.timestamp))
{
return;
}
}
if (buf[0] != ':')
{
process_named_servermsg (sess, &buf[0], word[0], word_eol, &tags_data);
return;
}
/* see if the second word is a numeric */
std::locale locale;
if (std::isdigit (word[2][0], locale))
{
char* t = word_eol[4];
if (*t == ':')
t++;
process_numeric (sess, atoi (word[2]), word, word_eol, t, &tags_data);
} else
{
process_named_msg (sess, type, word, word_eol, &tags_data);
}
}