本文整理汇总了C++中boost::string_ref::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string_ref::size方法的具体用法?C++ string_ref::size怎么用?C++ string_ref::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::string_ref
的用法示例。
在下文中一共展示了string_ref::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: write_stream
std::shared_ptr<Response> request(const std::string& request_type, const std::string& path = "/", boost::string_ref content = "",
const std::map<std::string, std::string>& header = std::map<std::string, std::string>()) {
std::string corrected_path = path;
if (corrected_path == "")
corrected_path = "/";
boost::asio::streambuf write_buffer;
std::ostream write_stream(&write_buffer);
write_stream << request_type << " " << corrected_path << " HTTP/1.1\r\n";
write_stream << "Host: " << host << "\r\n";
for (auto& h : header) {
write_stream << h.first << ": " << h.second << "\r\n";
}
if (content.size()>0)
write_stream << "Content-Length: " << content.size() << "\r\n";
write_stream << "\r\n";
try {
connect();
boost::asio::write(*socket, write_buffer);
if (content.size()>0)
boost::asio::write(*socket, boost::asio::buffer(content.data(), content.size()));
}
catch (const std::exception& e) {
socket_error = true;
throw std::invalid_argument(e.what());
}
return request_read();
}
示例3: 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;
}
示例4: 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;
}
示例5: operator
bool operator()(const boost::string_ref& strRef1, const boost::string_ref& strRef2) const
{
auto oneSize = strRef1.size();
auto twoSize = strRef2.size();
if (oneSize != twoSize)
{
return false;
}
return std::memcmp(strRef1.begin(), strRef2.begin(), oneSize) == 0;
}
示例6:
void
on_request(
boost::string_ref const& method_,
boost::string_ref const& path_,
int version_, error_code& ec)
{
method = std::string(
method_.data(), method_.size());
path = std::string(
path_.data(), path_.size());
version = version_;
got_on_begin = true;
if(fc_)
fc_->fail(ec);
}
示例7: sizeof
table_features(
std::uint8_t const table_id
, boost::string_ref const name
, std::uint64_t const metadata_match
, std::uint64_t const metadata_write
, std::uint32_t const config
, std::uint32_t const max_entries
, properties_type properties)
: table_features_{
properties.calc_ofp_length(sizeof(ofp_type))
, table_id
, { 0, 0, 0, 0, 0 }
, ""
, metadata_match
, metadata_write
, config
, max_entries
}
, properties_(std::move(properties))
{
auto const name_size
= std::min(name.size(), sizeof(table_features_.name) - 1);
using boost::adaptors::sliced;
boost::copy(name | sliced(0, name_size), table_features_.name);
}
示例8: SkipSpaces
void CInfixExpressionCalculator::SkipSpaces(boost::string_ref &ref)
{
size_t i = 0;
while (i < ref.size() && std::isspace(ref[i]))
++i;
ref.remove_prefix(i);
}
示例9: find_if
std::vector<std::pair<boost::string_ref, boost::string_ref>>::const_iterator find(const boost::string_ref key) const
{
return std::find_if(m_collection.begin(), m_collection.end(),
[key](const std::pair<boost::string_ref, boost::string_ref>& str)-> bool
{
auto oneSize = str.first.size();
auto twoSize = key.size();
if (oneSize != twoSize)
{
return false;
}
if (oneSize >= 4)
{
if ((str.first[0] == key[0]) &&
(str.first[1] == key[1]) &&
(str.first[oneSize - 1] == key[oneSize - 1]) &&
(str.first[oneSize - 2] == key[oneSize - 2]))
{
return std::memcmp(str.first.begin(), key.begin(), oneSize) == 0;
}
}
else
{
return std::memcmp(str.first.begin(), key.begin(), oneSize) == 0;
}
return false;
}
);
}
示例10:
inline boost::string_ref remove_leading_spaces(boost::string_ref string, const char* spaces = " \t\r\n")
{
auto pos = string.find_first_not_of(spaces);
if (pos == std::string::npos) pos = string.size();
string.remove_prefix(pos);
return string;
}
示例11: checkSimpleArgumentFor
void DatabaseImpl::checkSimpleArgumentFor(const boost::string_ref& key, partNum_t partNum) const
{
RAISE_INVALID_ARGUMENT_IF(key.size() > MAX_KEY_SIZE, "key too long");
RAISE_INVALID_ARGUMENT_IF(key.empty(), "empty key is not allowed");
RAISE_INVALID_ARGUMENT_IF(partNum > MAX_PARTNUM, "partNum is too large");
RAISE_INVALID_ARGUMENT_IF(partNum == ALL_PARTS, "partNum ALL_PARTS is not allowed");
RAISE_INVALID_ARGUMENT_IF(partNum < 0, "negative partNum is not allowed");
}
示例12: ParsePort
unsigned short CHttpUrl::ParsePort(boost::string_ref const &url, size_t index)
{
std::string port;
if (index == url.size() || (index < url.size() && !isdigit(url[index])))
{
throw CUrlParsingError("Unknown port in the url address");
}
for (; index != url.size(); ++index)
{
if (!isdigit(url[index]))
{
break;
}
port += url[index];
}
return static_cast<unsigned short>(atoi(port.c_str()));
}
示例13: marker
SimpleTemplate::SimpleTemplate(boost::string_ref text)
{
static char const rawMarker[] = "@@";
static boost::string_ref const marker(rawMarker, sizeof(rawMarker) - 1);
auto beg = text.find(marker);
while (beg != boost::string_ref::npos) {
m_literals.emplace_back(text.data(), beg);
text.remove_prefix(beg + marker.size());
auto end = text.find(marker);
if (end == boost::string_ref::npos) {
std::string& lit = m_literals.back();
lit.reserve(lit.size() + marker.size() + text.size());
lit.append(marker.data(), marker.size());
lit.append(text.data(), text.size());
assert(m_literals.size() == m_insertionKeys.size() + 1);
return;
}
m_insertionKeys.emplace_back(text.data(), end);
text.remove_prefix(end + marker.size());
beg = text.find(marker);
}
m_literals.emplace_back(text.data(), text.size());
assert(m_literals.size() == m_insertionKeys.size() + 1);
}
示例14: 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);
}
示例15: string_ref
inline boost::string_ref extract_word(boost::string_ref string)
{
const char spaces[] = " \t\r\n";
string = remove_leading_spaces(string, spaces);
auto new_size = string.find_first_of(spaces);
if (new_size == boost::string_ref::npos) new_size = string.size();
return boost::string_ref(string.data(), new_size);
}