本文整理汇总了C++中string_view::size方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::size方法的具体用法?C++ string_view::size怎么用?C++ string_view::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_view
的用法示例。
在下文中一共展示了string_view::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_pair
// 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);
}
示例2:
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())));
}
示例3: 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;
}
示例4: return
// 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] == '.'));
}
示例5:
std::wstring utf8_wchar(string_view utf8, error_code& ec)
{
// allocate space for worst-case
std::wstring wide;
wide.resize(utf8.size());
char const* src_start = utf8.data();
utf8_errors::error_code_enum const ret = convert_to_wide<sizeof(wchar_t)>::convert(
&src_start, src_start + utf8.size(), wide);
if (ret != utf8_errors::error_code_enum::conversion_ok)
ec = make_error_code(ret);
return wide;
}
示例6: name
bool
ShadingSystemImpl::LoadMemoryCompiledShader (string_view shadername,
string_view buffer)
{
if (! shadername.size()) {
error ("Attempt to load shader with empty name \"\".");
return false;
}
if (! buffer.size()) {
error ("Attempt to load shader \"%s\" with empty OSO data.", shadername);
return false;
}
ustring name (shadername);
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 ("Preload shader %s already exists in shader_masters", name.c_str());
return false;
}
// Not found in the map
OSOReaderToMaster reader (*this);
OIIO::Timer timer;
bool ok = reader.parse_memory (buffer);
ShaderMaster::ref r = ok ? reader.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)", shadername,
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 parse preloaded shader \"%s\"", shadername);
}
return true;
}
示例7: GetMountPointLen
size_t GetMountPointLen(string_view const abs_path, string_view const drive_root)
{
if (starts_with_icase(abs_path, drive_root))
return drive_root.size();
size_t dir_offset = 0;
if (ParsePath(abs_path, &dir_offset) == root_type::volume)
return dir_offset;
string vol_guid(drive_root);
switch (ParsePath(drive_root))
{
case root_type::volume:
break;
case root_type::drive_letter:
if (os::fs::GetVolumeNameForVolumeMountPoint(null_terminated(drive_root).c_str(), vol_guid))
break;
[[fallthrough]];
default:
return 0;
}
string mount_point = TryConvertVolumeGuidToDrivePath(vol_guid, abs_path);
return mount_point.size();
}
示例8: test_strview_basics
void test_strview_basics(const string_view& sv, const char *p, size_t n) {
ASSERT_EQ(p, sv.data());
ASSERT_EQ(n, sv.size());
ASSERT_EQ(n, sv.length());
ASSERT_EQ((n == 0), sv.empty());
ASSERT_EQ(p, sv.cbegin());
ASSERT_EQ(p, sv.begin());
ASSERT_EQ(p + n, sv.cend());
ASSERT_EQ(p + n, sv.end());
using reviter_t = std::reverse_iterator<string_view::const_iterator>;
ASSERT_EQ(reviter_t(sv.end()), sv.rbegin());
ASSERT_EQ(reviter_t(sv.begin()), sv.rend());
ASSERT_EQ(reviter_t(sv.cend()), sv.crbegin());
ASSERT_EQ(reviter_t(sv.cbegin()), sv.crend());
for (size_t i = 0; i < n; ++i) {
ASSERT_EQ(p[i], sv[i]);
ASSERT_EQ(p[i], sv.at(i));
}
ASSERT_THROW(sv.at(n), std::out_of_range);
ASSERT_THROW(sv.at(string_view::npos), std::out_of_range);
if (n > 0) {
ASSERT_EQ(p, &(sv.front()));
ASSERT_EQ(p + (n-1), &(sv.back()));
ASSERT_EQ(p[0], sv.front());
ASSERT_EQ(p[n-1], sv.back());
}
}
示例9:
std::size_t custom_parser<isRequest>::
on_body_impl(string_view body, error_code& ec)
{
boost::ignore_unused(body);
ec = {};
return body.size();
}
示例10: 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
}
示例11: 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();
}
示例12: is_brace_expansion
bool is_brace_expansion(string_view s)
{
int brace_count = 0;
int arr_count = 0;
bool b = false;
for (std::size_t i = 0; i < s.size(); i++)
{
if (s[i] == '{')
{
b = true;
brace_count++;
}
else if (s[i] == '[')
{
b = true;
arr_count++;
}
else if (s[i] == '}')
{
brace_count--;
if (brace_count < 0)
return false;
}
else if (s[i] == ']')
{
arr_count--;
if (arr_count < 0)
return false;
}
}
return b && brace_count == 0 && arr_count == 0;
}
示例13: 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();
}
示例14: switch
//===========================================================================
Count::Count(string_view path) {
auto * base = path.data();
auto * ptr = base;
auto * eptr = ptr + path.size();
char const * colon = nullptr; // first ':'
char const * slash = nullptr; // last '/' or '\'
char const * dot = nullptr; // last '.'
for (; ptr != eptr; ++ptr) {
switch(*ptr) {
case '.':
dot = ptr;
break;
case '/':
case '\\':
slash = ptr;
break;
case ':':
if (!colon)
colon = ptr;
break;
}
}
if (!slash) {
m_rootLen = colon ? unsigned(colon - base + 1) : 0;
m_dirLen = 0;
} else {
m_rootLen = (colon && colon < slash) ? unsigned(colon - base + 1) : 0;
m_dirLen = unsigned(slash - base + 1 - m_rootLen);
}
if (!dot || unsigned(dot - base) <= m_rootLen + m_dirLen) {
m_stemLen = unsigned(path.size() - m_rootLen - m_dirLen);
m_extLen = 0;
} else {
m_stemLen = unsigned(dot - base - m_rootLen - m_dirLen);
m_extLen = unsigned(eptr - dot);
if (m_extLen == 1 && m_stemLen == 1 && dot[-1] == '.') {
m_stemLen = 2;
m_extLen = 0;
} else if (!m_stemLen) {
m_stemLen = m_extLen;
m_extLen = 0;
}
}
assert(m_extLen == path.size() - m_rootLen - m_dirLen - m_stemLen);
}
示例15: 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);
}