本文整理汇总了C++中boost::string_ref类的典型用法代码示例。如果您正苦于以下问题:C++ string_ref类的具体用法?C++ string_ref怎么用?C++ string_ref使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了string_ref类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: request
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();
}
开发者ID:boobamo1,项目名称:durian,代码行数:32,代码来源:client_http.hpp
示例2: 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);
}
开发者ID:ps-group,项目名称:algorithm-samples,代码行数:7,代码来源:InfixExpressionCalculator.cpp
示例3: 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;
}
开发者ID:Smi1le,项目名称:OOP,代码行数:26,代码来源:HTTPUrl.cpp
示例4: ParseExprSum
double CInfixExpressionCalculator::ParseExprSum(boost::string_ref &ref)
{
double value = ParseExprMul(ref);
while (true)
{
SkipSpaces(ref);
if (!ref.empty() && ref[0] == '+')
{
ref.remove_prefix(1);
value += ParseExprMul(ref);
}
else if (!ref.empty() && ref[0] == '-')
{
ref.remove_prefix(1);
value -= ParseExprMul(ref);
}
else
{
break;
}
}
return value;
}
开发者ID:ps-group,项目名称:algorithm-samples,代码行数:25,代码来源:InfixExpressionCalculator.cpp
示例5: find
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;
}
);
}
开发者ID:Sentimentron,项目名称:GQ,代码行数:32,代码来源:Node.hpp
示例6: print_string
void print_string(boost::string_ref str, std::ostream& out)
{
for (boost::string_ref::const_iterator cur = str.begin();
cur != str.end(); ++cur)
{
print_char(*cur, out);
}
}
开发者ID:OggYiu,项目名称:rag-engine,代码行数:8,代码来源:utils.cpp
示例7: 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");
}
开发者ID:Kerio,项目名称:hashdb,代码行数:8,代码来源:DatabaseImpl.cpp
示例8: remove_leading_spaces
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;
}
开发者ID:mnewhouse,项目名称:tselements,代码行数:8,代码来源:string_utilities.hpp
示例9: cpp_name
std::string codegen_base::cpp_name(boost::string_ref name)
{
std::string result;
if (!std::isalpha(name[0]))
result = "_";
std::transform(name.begin(), name.end(), std::back_inserter(result),
[] (char c) { return std::isalnum(c) ? c : '_'; });
return result;
}
开发者ID:cuavas,项目名称:mFAST,代码行数:9,代码来源:codegen_base.cpp
示例10: extract_word
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);
}
开发者ID:mnewhouse,项目名称:tselements,代码行数:10,代码来源:string_utilities.hpp
示例11: is_emm_file
inline bool is_emm_file(boost::string_ref path)
{
std::ifstream ifs( convert_code( path, CP_UTF8, CP_OEMCP ), std::ios::binary );
if( ifs.fail() ) {
return false;
}
std::istreambuf_iterator< char > first( ifs ), last;
boost::string_ref const seg( "[Info]\r\nVersion = 3\r\n" );
return std::search( first, last, seg.begin(), seg.end() ) != last;
}
开发者ID:LNSEAB,项目名称:pmm_lookupper,代码行数:12,代码来源:emm.hpp
示例12: 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;
}
开发者ID:TechnikEmpire,项目名称:GQ,代码行数:12,代码来源:StrRefHash.hpp
示例13: on_response
void
on_response(int status_,
boost::string_ref const& reason_,
int version_, error_code& ec)
{
status = status_;
reason = std::string(
reason_.data(), reason_.size());
version = version_;
got_on_begin = true;
if(fc_)
fc_->fail(ec);
}
开发者ID:cbodley,项目名称:Beast,代码行数:13,代码来源:test_parser.hpp
示例14: m_operator
AttributeSelector::AttributeSelector(SelectorOperator op, boost::string_ref key, boost::string_ref value) :
m_operator(op),
m_attributeNameString(key.to_string()),
m_attributeNameRef(m_attributeNameString),
m_attributeValueString(value.to_string()),
m_attributeValueRef(m_attributeValueString)
{
if (m_attributeNameRef.size() == 0)
{
throw std::runtime_error(u8"In AttributeSelector::AttributeSelector(SelectorOperator, boost::string_ref, const bool) - Supplied attribute identifier has zero length.");
}
if (m_attributeValueRef.size() == 0)
{
throw std::runtime_error(u8"In AttributeSelector::AttributeSelector(SelectorOperator, boost::string_ref, const bool) - Supplied attribute value has zero length.");
}
if (m_operator == SelectorOperator::ValueContainsElementInWhitespaceSeparatedList)
{
if (m_attributeNameRef.find_first_of(u8"\t\r\n ") != std::string::npos)
{
throw std::runtime_error(u8"In AttributeSelector::AttributeSelector(SelectorOperator, boost::string_ref, const bool) - Constructed ValueContainsElementInWhitespaceSeparatedList attribute selector, but spaces exist in the search value. This is not allowed.");
}
}
#ifndef NDEBUG
#ifdef GQ_VERBOSE_DEBUG_NFO
std::cout << "Built AttributeSelector with operator " << static_cast<size_t>(m_operator) << " with key " << m_attributeNameRef << " looking for value " << m_attributeValueRef << std::endl;
#endif
#endif
switch (m_operator)
{
case SelectorOperator::ValueEquals:
case SelectorOperator::ValueContainsElementInWhitespaceSeparatedList:
{
AddMatchTrait(m_attributeNameRef, m_attributeValueRef);
}
break;
case SelectorOperator::Exists:
case SelectorOperator::ValueContains:
case SelectorOperator::ValueHasPrefix:
case SelectorOperator::ValueHasSuffix:
case SelectorOperator::ValueIsHyphenSeparatedListStartingWith:
{
AddMatchTrait(m_attributeNameRef, SpecialTraits::GetAnyValue());
}
break;
}
}
开发者ID:Sentimentron,项目名称:GQ,代码行数:51,代码来源:AttributeSelector.cpp
示例15: 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);
}
开发者ID:Vladi1996mir,项目名称:OOP,代码行数:14,代码来源:HttpUrl.cpp
示例16: on_request
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);
}
开发者ID:cbodley,项目名称:Beast,代码行数:15,代码来源:test_parser.hpp
示例17: rebuild
void url::
rebuild(const boost::string_ref &scheme,
const boost::optional<boost::string_ref> &host,
const boost::optional<uint16_t> &port,
const boost::optional<boost::string_ref> &path,
const boost::optional<boost::string_ref> &query,
const boost::optional<boost::string_ref> &fragment,
const boost::optional<boost::string_ref> &user_info)
{
std::string str;
str.append(scheme.data(), scheme.size());
if (has_authority()) {
str.append("://");
if (user_info) {
str.append(user_info->data(), user_info->size());
str.append("@");
}
str.append(host->data(), host->size());
if (port) {
str.append(":");
str.append(std::to_string(*port));
}
}
else {
str.append(":");
}
if (path) {
str.append(path->data(), path->size());
}
if (query) {
str.append("?");
str.append(query->data(), query->size());
}
if (fragment) {
str.append("#");
str.append(fragment->data(), fragment->size());
}
url new_url { std::move(str) };
swap(new_url);
}
开发者ID:stream009,项目名称:libstream9,代码行数:48,代码来源:url.cpp
示例18: get_directory_listing
std::string get_directory_listing( boost::string_ref folder ) {
namespace fs = boost::filesystem;
fs::path p { folder.to_string( ) };
std::ostringstream ss;
try {
if( exists( p ) ) {
if( fs::is_regular_file( p ) ) {
ss << p << " size is " << fs::file_size( p ) << "\r\n";
} else if( fs::is_directory( p ) ) {
ss << p << " is a directory containing:\n";
std::copy( fs::directory_iterator( p ), fs::directory_iterator( ), std::ostream_iterator<fs::directory_entry>( ss, "\r\n" ) );
} else {
ss << p << " exists, but is neither a regular file nor a directory\n";
}
} else {
ss << p << " does not exist\n";
}
}
catch( const fs::filesystem_error& ex ) {
ss << "ERROR: " << ex.what( ) << '\n';
}
return ss.str( );
}
开发者ID:xeroskiller,项目名称:nodepp,代码行数:25,代码来源:example_server.cpp
示例19: index
id_placeholder::id_placeholder(
unsigned index,
boost::string_ref id,
id_category category,
id_placeholder const* parent_)
: index(index),
unresolved_id(parent_ ?
parent_->unresolved_id + '.' + detail::to_s(id) :
detail::to_s(id)),
id(id.begin(), id.end()),
parent(parent_),
category(category),
num_dots(boost::range::count(id, '.') +
(parent_ ? parent_->num_dots + 1 : 0))
{
}
开发者ID:AlexMioMio,项目名称:boost,代码行数:16,代码来源:document_state.cpp
示例20: table_features
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);
}
开发者ID:amedama41,项目名称:bulb,代码行数:25,代码来源:table_features.hpp
注:本文中的boost::string_ref类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论