本文整理汇总了C++中string_view类的典型用法代码示例。如果您正苦于以下问题:C++ string_view类的具体用法?C++ string_view怎么用?C++ string_view使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了string_view类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: write_buffer
void
write_buffer(DynamicBuffer& b, string_view s)
{
b.commit(boost::asio::buffer_copy(
b.prepare(s.size()), boost::asio::buffer(
s.data(), s.size())));
}
开发者ID:dreamsxin,项目名称:rippled,代码行数:7,代码来源:buffer_test.hpp
示例2: main
int main()
{
using string_view = std::experimental::string_view;
using u16string_view = std::experimental::u16string_view;
using u32string_view = std::experimental::u32string_view;
using wstring_view = std::experimental::wstring_view;
test(string_view {});
test(string_view { "123"});
test(u16string_view{});
test(u16string_view{u"123"});
test(u32string_view{});
test(u32string_view{U"123"});
test(wstring_view {});
test(wstring_view {L"123"});
{
constexpr string_view sv { "123", 3 };
constexpr u16string_view u16sv {u"123", 3 };
constexpr u32string_view u32sv {U"123", 3 };
constexpr wstring_view wsv {L"123", 3 };
static_assert ( sv.begin() != sv.end(), "" );
static_assert ( u16sv.begin() != u16sv.end(), "" );
static_assert ( u32sv.begin() != u32sv.end(), "" );
static_assert ( wsv.begin() != wsv.end(), "" );
static_assert ( sv.begin() != sv.cend(), "" );
static_assert ( u16sv.begin() != u16sv.cend(), "" );
static_assert ( u32sv.begin() != u32sv.cend(), "" );
static_assert ( wsv.begin() != wsv.cend(), "" );
}
}
开发者ID:massa,项目名称:string_view,代码行数:33,代码来源:end.pass.cpp
示例3: dict_find
bdecode_node bdecode_node::dict_find(string_view key) const
{
TORRENT_ASSERT(type() == dict_t);
bdecode_token const* tokens = m_root_tokens;
// this is the first item
int token = m_token_idx + 1;
while (tokens[token].type != bdecode_token::end)
{
bdecode_token const& t = tokens[token];
TORRENT_ASSERT(t.type == bdecode_token::string);
int const size = m_root_tokens[token + 1].offset - t.offset - t.start_offset();
if (int(key.size()) == size
&& std::equal(key.data(), key.data() + size, m_buffer
+ t.offset + t.start_offset()))
{
// skip key
token += t.next_item;
TORRENT_ASSERT(tokens[token].type != bdecode_token::end);
return bdecode_node(tokens, m_buffer, m_buffer_size, token);
}
// skip key
token += t.next_item;
TORRENT_ASSERT(tokens[token].type != bdecode_token::end);
// skip value
token += tokens[token].next_item;
}
return bdecode_node();
}
开发者ID:krattai,项目名称:AEBL,代码行数:35,代码来源:bdecode.cpp
示例4: deconstruct_uri
/// Deconstruct a "URI" string into the "fllename" part (returned) and turn
/// the "query" part into a series of pairs of id and value. For example,
/// deconstruct_uri("foo.tif?bar=1&blah=\"hello world\"", args)
/// would be expected to return "foo.tif" and *args would contain two
/// pairs: ("foo","1") and ("bar","\"hello world\"").
static string_view
deconstruct_uri (string_view uri,
std::vector<std::pair<string_view,string_view> > *args=NULL)
{
if (args)
args->clear ();
size_t arg_start = uri.find ('?');
if (arg_start == string_view::npos)
return uri;
string_view argstring = uri.substr (arg_start+1);
string_view filename = uri.substr (0, arg_start);
if (! args)
return filename;
while (! argstring.empty()) {
string_view id = Strutil::parse_until (argstring, "=&");
string_view value;
if (! id.size())
break;
if (! Strutil::parse_char (argstring, '=') || argstring.empty())
break;
if (argstring[0] == '\"')
Strutil::parse_string (argstring, value, true, Strutil::KeepQuotes);
else
value = Strutil::parse_until (argstring, "&\t\r\n");
args->push_back (std::make_pair(id, value));
Strutil::parse_char (argstring, '&');
}
return filename;
}
开发者ID:FrankFirsching,项目名称:OpenShadingLanguage,代码行数:34,代码来源:oslinput.cpp
示例5: onFileRead
//===========================================================================
bool ConsoleReader::onFileRead(
size_t * bytesRead,
string_view data,
bool more,
int64_t offset,
FileHandle f
) {
*bytesRead = data.size();
auto bytes = (int) data.size();
socketWrite(&s_socket, move(m_buffer), bytes);
// stop reading (return false) so we can get a new buffer
if (m_input) {
if (m_isFile) {
if (!bytes || (size_t) offset == fileSize(f)) {
fileClose(m_input);
consoleResetStdin();
init();
}
} else {
if (!bytes) {
m_buffer.reset();
return false;
}
}
if (m_suspended) {
m_offset = offset;
} else {
read(offset);
}
} else {
m_buffer.reset();
}
return false;
}
开发者ID:gknowles,项目名称:dimapp,代码行数:36,代码来源:tnet.cpp
示例6: parse_utf8_codepoint
// returns the unicode codepoint and the number of bytes of the utf8 sequence
// that was parsed. The codepoint is -1 if it's invalid
std::pair<std::int32_t, int> parse_utf8_codepoint(string_view str)
{
int const sequence_len = trailingBytesForUTF8[static_cast<std::uint8_t>(str[0])] + 1;
if (sequence_len > int(str.size())) return std::make_pair(-1, static_cast<int>(str.size()));
if (sequence_len > 4)
{
return std::make_pair(-1, sequence_len);
}
if (!isLegalUTF8(reinterpret_cast<UTF8 const*>(str.data()), sequence_len))
{
return std::make_pair(-1, sequence_len);
}
std::uint32_t ch = 0;
for (int i = 0; i < sequence_len; ++i)
{
ch <<= 6;
ch += static_cast<std::uint8_t>(str[static_cast<std::size_t>(i)]);
}
ch -= offsetsFromUTF8[sequence_len-1];
if (ch > 0x7fffffff)
{
return std::make_pair(-1, sequence_len);
}
return std::make_pair(static_cast<std::int32_t>(ch), sequence_len);
}
开发者ID:ajax16384,项目名称:libtorrent,代码行数:32,代码来源:utf8.cpp
示例7: shouldConsiderUnaryLiteral
static bool shouldConsiderUnaryLiteral(string_view& stream, Location& pos)
{
// check the previous token
bool should = (prevType != TokenType::Invalid && prevID == pos.fileID && (
prevType != TokenType::RParen &&
prevType != TokenType::RSquare &&
prevType != TokenType::Identifier &&
prevType != TokenType::Number &&
prevType != TokenType::Dollar &&
prevType != TokenType::StringLiteral
));
if(!should) return false;
// check if the current char is a + or -
if(stream.length() == 0) return false;
if(stream[0] != '+' && stream[0] != '-') return false;
// check if there's only spaces between this and the number itself
for(size_t i = 1; i < stream.length(); i++)
{
if(isdigit(stream[i])) return true;
else if(stream[i] != ' ') return false;
}
return false;
}
开发者ID:flax-lang,项目名称:flax,代码行数:27,代码来源:lexer.cpp
示例8: test_strview_compare
void test_strview_compare(const string_view& a, const string_view& b) {
std::string as = a.to_string();
std::string bs = b.to_string();
auto sg = [](int x) { return x == 0 ? 0 : (x < 0 ? -1 : 1); };
int c = as.compare(bs);
ASSERT_EQ(sg(c), sg(a.compare(b)));
ASSERT_EQ(sg(c), sg(a.compare(bs.c_str())));
ASSERT_EQ(c == 0, a == b);
ASSERT_EQ(c != 0, a != b);
ASSERT_EQ(c < 0, a < b);
ASSERT_EQ(c <= 0, a <= b);
ASSERT_EQ(c > 0, a > b);
ASSERT_EQ(c >= 0, a >= b);
ASSERT_EQ((-c) == 0, b == a);
ASSERT_EQ((-c) != 0, b != a);
ASSERT_EQ((-c) < 0, b < a);
ASSERT_EQ((-c) <= 0, b <= a);
ASSERT_EQ((-c) > 0, b > a);
ASSERT_EQ((-c) >= 0, b >= a);
}
开发者ID:clarkong,项目名称:CLUE,代码行数:25,代码来源:test_string_view.cpp
示例9: getImpl
bool
ColorConfig::reset (string_view filename)
{
bool ok = true;
delete m_impl;
m_impl = new ColorConfig::Impl;
#ifdef USE_OCIO
OCIO::SetLoggingLevel (OCIO::LOGGING_LEVEL_NONE);
try {
if (filename.empty()) {
getImpl()->config_ = OCIO::GetCurrentConfig();
} else {
getImpl()->config_ = OCIO::Config::CreateFromFile (filename.c_str());
}
}
catch(OCIO::Exception &e) {
getImpl()->error_ = e.what();
ok = false;
}
catch(...) {
getImpl()->error_ = "An unknown error occurred in OpenColorIO creating the config";
ok = false;
}
#endif
getImpl()->inventory ();
// If we populated our own, remove any errors.
if (getNumColorSpaces() && !getImpl()->error_.empty())
getImpl()->error_.clear();
return ok;
}
开发者ID:,项目名称:,代码行数:34,代码来源:
示例10: readIntegerFile
vector<int> readIntegerFile(string_view fileName)
{
ifstream inputStream(fileName.data());
if (inputStream.fail()) {
// We failed to open the file: throw an exception
const string error = "Unable to open file "s + fileName.data();
throw invalid_argument(error);
}
// Read the integers one-by-one and add them to a vector
vector<int> integers;
int temp;
while (inputStream >> temp) {
integers.push_back(temp);
}
if (!inputStream.eof()) {
// We did not reach the end-of-file.
// This means that some error occurred while reading the file.
// Throw an exception.
const string error = "Unable to read file "s + fileName.data();
throw runtime_error(error);
}
return integers;
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:26,代码来源:03_CatchingPolymorphicallyCorrectTwo.cpp
示例11: stdLogger
void stdLogger(int level, string_view msg) noexcept
{
const auto now = UnixClock::now();
const auto t = UnixClock::to_time_t(now);
const auto ms = timeToMs(now);
struct tm tm;
localtime_r(&t, &tm);
// The following format has an upper-bound of 42 characters:
// "%b %d %H:%M:%S.%03d %-7s [%d]: "
//
// Example:
// Mar 14 00:00:00.000 WARNING [0123456789]: msg...
// <---------------------------------------->
char head[42 + 1];
size_t hlen = strftime(head, sizeof(head), "%b %d %H:%M:%S", &tm);
hlen += sprintf(head + hlen, ".%03d %-7s [%d]: ", static_cast<int>(ms % 1000), logLabel(level),
static_cast<int>(getpid()));
char tail = '\n';
iovec iov[] = {
{head, hlen}, //
{const_cast<char*>(msg.data()), msg.size()}, //
{&tail, 1} //
};
int fd{level > LogWarning ? STDOUT_FILENO : STDERR_FILENO};
// Best effort given that this is the logger.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
writev(fd, iov, sizeof(iov) / sizeof(iov[0]));
#pragma GCC diagnostic pop
}
开发者ID:swirlycloud,项目名称:swirly,代码行数:33,代码来源:Log.cpp
示例12: to_rna
string transcription::to_rna(string_view strand)
{
string result;
transform(strand.begin(), strand.end(), back_inserter(result),
static_cast<char (*)(char)>(to_rna));
return result;
}
开发者ID:JIghtuse,项目名称:exercism-solutions,代码行数:7,代码来源:rna_transcription.cpp
示例13: add_line_to_multiline_header
void Request::add_line_to_multiline_header(const string_view& line,
const string_view& header)
{
auto non_whitespace_pos = line.find_first_not_of("\t ");
if (non_whitespace_pos != line.end())
if (!header.empty())
headers_[header.str()] += line.substr(non_whitespace_pos).str();
}
开发者ID:csuvbakka,项目名称:strippy,代码行数:8,代码来源:http_request.cpp
示例14: min
Exception::Exception(string_view what) noexcept
{
const auto len = min(what.size(), MaxErrMsg);
if (len > 0) {
memcpy(what_, what.data(), len);
}
what_[len] = '\0';
}
开发者ID:swirlycloud,项目名称:swirly,代码行数:8,代码来源:Exception.cpp
示例15: is_or_endswithdot
// Is name the same as suffix, or does it end in ".suffix"?
inline bool
is_or_endswithdot (string_view name, string_view suffix)
{
return (Strutil::iequals (name, suffix) ||
(name.size() > suffix.size() &&
Strutil::iends_with (name, suffix) &&
name[name.size()-suffix.size()-1] == '.'));
}
开发者ID:KelSolaar,项目名称:oiio,代码行数:9,代码来源:deepdata.cpp
示例16: copy_string
allocation_slot stack_allocator::copy_string(string_view str)
{
int const ret = int(m_storage.size());
m_storage.resize(ret + numeric_cast<int>(str.size()) + 1);
std::memcpy(&m_storage[ret], str.data(), str.size());
m_storage[ret + int(str.length())] = '\0';
return allocation_slot(ret);
}
开发者ID:ajax16384,项目名称:libtorrent,代码行数:8,代码来源:stack_allocator.cpp
示例17: find_icase
size_t find_icase(string_view const Str, wchar_t const What, size_t Pos)
{
if (Pos >= Str.size())
return Str.npos;
const auto It = std::find_if(Str.cbegin() + Pos, Str.cend(), [&](wchar_t const Char) { return equal_icase_t{}(What, Char); });
return It == Str.cend() ? Str.npos : It - Str.cbegin();
}
开发者ID:FarGroup,项目名称:FarManager,代码行数:8,代码来源:string_utils.cpp
示例18: if
size_t
TypeDesc::fromstring(string_view typestring)
{
*this = TypeDesc::UNKNOWN;
string_view orig = typestring;
if (typestring.empty()) {
return 0;
}
// The first "word" should be a type name.
string_view type = Strutil::parse_identifier(typestring);
// Check the scalar types in our table above
TypeDesc t;
for (int i = 0; i < LASTBASE; ++i) {
if (type == basetype_name[i]) {
t.basetype = i;
break;
}
}
// Some special case names for aggregates
if (t.basetype != UNKNOWN) {
// already solved
} else if (type == "color")
t = TypeColor;
else if (type == "point")
t = TypePoint;
else if (type == "vector")
t = TypeVector;
else if (type == "normal")
t = TypeNormal;
else if (type == "matrix33")
t = TypeMatrix33;
else if (type == "matrix" || type == "matrix44")
t = TypeMatrix44;
else if (type == "timecode")
t = TypeTimeCode;
else if (type == "rational")
t = TypeRational;
else {
return 0; // unknown
}
// Is there an array length following the type name?
if (Strutil::parse_char(typestring, '[')) {
int arraylen = -1;
Strutil::parse_int(typestring, arraylen);
if (!Strutil::parse_char(typestring, ']'))
return 0; // malformed
t.arraylen = arraylen;
}
*this = t;
return orig.length() - typestring.length();
}
开发者ID:appleseedhq,项目名称:appleseed-deps,代码行数:56,代码来源:typedesc.cpp
示例19: name
ShaderMaster::ref
ShadingSystemImpl::loadshader (string_view cname)
{
if (Strutil::ends_with (cname, ".oso"))
cname.remove_suffix (4); // strip superfluous .oso
if (! cname.size()) {
error ("Attempt to load shader with empty name \"\".");
return NULL;
}
++m_stat_shaders_requested;
ustring name (cname);
lock_guard guard (m_mutex); // Thread safety
ShaderNameMap::const_iterator found = m_shader_masters.find (name);
if (found != m_shader_masters.end()) {
// if (debug())
// info ("Found %s in shader_masters", name.c_str());
// Already loaded this shader, return its reference
return (*found).second;
}
// Not found in the map
OSOReaderToMaster oso (*this);
std::string filename = OIIO::Filesystem::searchpath_find (name.string() + ".oso",
m_searchpath_dirs);
if (filename.empty ()) {
error ("No .oso file could be found for shader \"%s\"", name.c_str());
return NULL;
}
OIIO::Timer timer;
bool ok = oso.parse_file (filename);
ShaderMaster::ref r = ok ? oso.master() : nullptr;
m_shader_masters[name] = r;
double loadtime = timer();
{
spin_lock lock (m_stat_mutex);
m_stat_master_load_time += loadtime;
}
if (ok) {
++m_stat_shaders_loaded;
info ("Loaded \"%s\" (took %s)", filename.c_str(),
Strutil::timeintervalformat(loadtime, 2).c_str());
ASSERT (r);
r->resolve_syms ();
// if (debug()) {
// std::string s = r->print ();
// if (s.length())
// info ("%s", s.c_str());
// }
} else {
error ("Unable to read \"%s\"", filename.c_str());
}
return r;
}
开发者ID:ElaraFX,项目名称:OpenShadingLanguage,代码行数:54,代码来源:loadshader.cpp
示例20: validDeckName
bool ParserKeyword::validDeckName( const string_view& name) {
if( !validNameStart( name ) )
return false;
const auto valid = []( char c ) {
return std::isalnum( c ) || c == '-' || c == '_' || c == '+';
};
return std::all_of( name.begin() + 1, name.end(), valid );
}
开发者ID:,项目名称:,代码行数:11,代码来源:
注:本文中的string_view类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论