本文整理汇总了C++中string_view::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ string_view::empty方法的具体用法?C++ string_view::empty怎么用?C++ string_view::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_view
的用法示例。
在下文中一共展示了string_view::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TryConvertVolumeGuidToDrivePath
// try to replace volume GUID (if present) with drive letter
// used by ConvertNameToReal() only
static string TryConvertVolumeGuidToDrivePath(string_view const Path, const string_view AbsPath = {})
{
string Result(Path);
size_t DirectoryOffset;
if (ParsePath(Path, &DirectoryOffset) == root_type::volume)
{
if (imports.GetVolumePathNamesForVolumeNameW)
{
string VolumePathNames;
if (os::fs::GetVolumePathNamesForVolumeName(ExtractPathRoot(Path), VolumePathNames))
{
for(const auto& i: enum_substrings(VolumePathNames.c_str()))
{
if (!AbsPath.empty() && starts_with_icase(AbsPath, i))
return string(i);
if (IsRootPath(i))
{
Result.replace(0, DirectoryOffset, i.data(), i.size());
break;
}
}
}
if (!AbsPath.empty())
Result.clear();
}
else if (!AbsPath.empty())
Result.clear();
else
{
string strVolumeGuid;
const os::fs::enum_drives Enumerator(os::fs::get_logical_drives());
const auto ItemIterator = std::find_if(ALL_CONST_RANGE(Enumerator), [&](const auto& i)
{
return os::fs::GetVolumeNameForVolumeMountPoint(os::fs::get_root_directory(i), strVolumeGuid) && starts_with(Path, string_view(strVolumeGuid).substr(0, DirectoryOffset));
});
if (ItemIterator != Enumerator.cend())
{
Result.replace(0, DirectoryOffset, os::fs::get_drive(*ItemIterator));
}
}
}
else if (!AbsPath.empty())
Result.clear();
return Result;
}
示例2: 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;
}
示例3: oso
bool
OSLQuery::open (string_view shadername,
string_view searchpath)
{
OSOReaderQuery oso (*this);
std::string filename = shadername;
// Add file extension if not already there
if (Filesystem::extension (filename) != std::string(".oso"))
filename += ".oso";
// Apply search paths
if (! searchpath.empty ()) {
std::vector<std::string> dirs;
Filesystem::searchpath_split (searchpath, dirs);
filename = Filesystem::searchpath_find (filename, dirs);
}
if (filename.empty()) {
error ("File \"%s\" could not be found.", shadername);
return false;
}
bool ok = oso.parse_file (filename);
return ok;
}
示例4: lock
bool
ImageBufAlgo::ociofiletransform (ImageBuf &dst, const ImageBuf &src,
string_view name, bool inverse, bool unpremult,
ColorConfig *colorconfig, ROI roi, int nthreads)
{
if (name.empty()) {
dst.error ("Unknown filetransform name");
return false;
}
ColorProcessor *processor = NULL;
{
spin_lock lock (colorconfig_mutex);
if (! colorconfig)
colorconfig = default_colorconfig.get();
if (! colorconfig)
default_colorconfig.reset (colorconfig = new ColorConfig);
processor = colorconfig->createFileTransform (name, inverse);
if (! processor) {
if (colorconfig->error())
dst.error ("%s", colorconfig->geterror());
else
dst.error ("Could not construct the color transform");
return false;
}
}
bool ok = colorconvert (dst, src, processor, unpremult, roi, nthreads);
if (ok)
dst.specmod().attribute ("oiio:ColorSpace", name);
{
spin_lock lock (colorconfig_mutex);
colorconfig->deleteColorProcessor (processor);
}
return ok;
}
示例5: save
// -----------------------------------------------------------------------------
// This is the general, all-purpose 'save archive' function.
// Takes into account whether the archive is contained within another, is
// already on the disk, etc etc.
// Does a 'save as' if [filename] is specified, unless the archive is contained
// within another.
// Returns false if saving was unsuccessful, true otherwise
// -----------------------------------------------------------------------------
bool Archive::save(string_view filename)
{
bool success = false;
// Check if the archive is read-only
if (read_only_)
{
Global::error = "Archive is read-only";
return false;
}
// If the archive has a parent ArchiveEntry, just write it to that
if (parent_)
{
success = write(parent_->data());
parent_->setState(ArchiveEntry::State::Modified);
}
else
{
// Otherwise, file stuff
if (!filename.empty())
{
// New filename is given (ie 'save as'), write to new file and change archive filename accordingly
success = write(filename);
if (success)
filename_ = filename;
// Update variables
on_disk_ = true;
}
else if (!filename_.empty())
{
// No filename is given, but the archive has a filename, so overwrite it (and make a backup)
// Create backup
if (backup_archives && wxFileName::FileExists(filename_) && save_backup)
{
// Copy current file contents to new backup file
auto bakfile = filename_ + ".bak";
Log::info("Creating backup {}", bakfile);
wxCopyFile(filename_, bakfile, true);
}
// Write it to the file
success = write(filename_);
// Update variables
on_disk_ = true;
}
}
// If saving was successful, update variables and announce save
if (success)
{
setModified(false);
announce("saved");
}
return success;
}
示例6: addRoot
//===========================================================================
static void addRoot(string * out, string_view val) {
if (val.empty())
return;
out->append(val);
if (out->back() != ':')
out->push_back(':');
}
示例7: 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());
}
}
示例8: 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();
}
示例9: tiff_compression_code
static int tiff_compression_code (string_view name)
{
if (name.empty())
COMPRESSION_ADOBE_DEFLATE; // default
for (int i = 0; tiff_compressions[i].name; ++i)
if (Strutil::iequals (name, tiff_compressions[i].name))
return tiff_compressions[i].code;
return COMPRESSION_ADOBE_DEFLATE; // default
}
示例10: 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();
}
示例11: addExt
//===========================================================================
static void addExt(string * out, string_view ext) {
if (ext.empty())
return;
if (ext[0] != '.')
out->push_back('.');
out->append(ext);
while (!out->empty() && out->back() == '.')
out->pop_back();
}
示例12: normalize_path_segments
std::string normalize_path_segments(string_view path) {
std::string result;
if (!path.empty()) {
std::vector<std::string> path_segments;
network_boost::split(path_segments, path, [](char ch) {
return ch == '/';
});
// remove single dot segments
detail::remove_erase_if(
path_segments, [](const std::string& s) { return (s == "."); });
// remove double dot segments
std::vector<std::string> normalized_segments;
for (auto& segment : path_segments) {
if (segment == "..") {
if (normalized_segments.size() <= 1) {
throw uri_builder_error();
}
normalized_segments.pop_back();
}
else {
normalized_segments.push_back(segment);
}
}
// remove adjacent slashes
optional<std::string> prev_segment;
detail::remove_erase_if(
normalized_segments, [&prev_segment](const std::string& segment) {
bool has_adjacent_slash =
((prev_segment && prev_segment->empty()) && segment.empty());
if (!has_adjacent_slash) {
prev_segment = segment;
}
return has_adjacent_slash;
});
result = network_boost::join(normalized_segments, "/");
}
if (result.empty()) {
result = "/";
}
return result;
}
示例13: invalid_argument
response<empty_body>
do_head_request(
SyncStream& stream,
DynamicBuffer& buffer,
string_view target,
error_code& ec)
{
// Do some type checking to be a good citizen
static_assert(is_sync_stream<SyncStream>::value,
"SyncStream requirements not met");
static_assert(is_dynamic_buffer<DynamicBuffer>::value,
"DynamicBuffer requirments not met");
// The interfaces we are using are low level and do not
// perform any checking of arguments; so we do it here.
if(target.empty())
throw std::invalid_argument("target may not be empty");
// Build the HEAD request for the target
request<empty_body> req;
req.version = 11;
req.method(verb::head);
req.target(target);
req.set(field::user_agent, "test");
// A client MUST send a Host header field in all HTTP/1.1 request messages.
// https://tools.ietf.org/html/rfc7230#section-5.4
req.set(field::host, "localhost");
// Now send it
write(stream, req, ec);
if(ec)
return {};
// Create a parser to read the response.
// Responses to HEAD requests MUST NOT include
// a body, so we use the `empty_body` type and
// only attempt to read the header.
parser<false, empty_body> p;
read_header(stream, buffer, p, ec);
if(ec)
return {};
// Transfer ownership of the response to the caller.
return p.release();
}
示例14: open_wd
static bool open_wd(gitdb & db, git_wd & wd, string_view path)
{
std::string apath = absolute_path(clean_path(path));
path = apath;
while (!path.empty())
{
std::string nonbare_path = join_paths(path, ".git");
if (file::is_directory(nonbare_path))
{
db.open(nonbare_path);
wd.open(db, path);
return true;
}
path = path_head(path);
}
return false;
}
示例15: parse_lng_line
static lng_line_type parse_lng_line(const string_view str, bool ParseLabels, string_view& Label, string_view& Data)
{
Label = {};
Data = {};
//-- "Text"
if (starts_with(str, L'"'))
{
Data = str.substr(1, str.size() - (ends_with(str, L'"')? 2 : 1));
return lng_line_type::text;
}
//-- //[Label]
if (ParseLabels)
{
const auto Prefix = L"//["sv, Suffix = L"]"sv;
if (starts_with(str, Prefix) && ends_with(str, Suffix))
{
Label = str.substr(Prefix.size(), str.size() - Prefix.size() - Suffix.size());
return lng_line_type::label;
}
}
//-- MLabel="Text"
if (ParseLabels && !str.empty() && str.back() == L'"')
{
const auto eq_pos = str.find(L'=');
if (eq_pos != str.npos && std::iswalpha(str[0]))
{
const auto Value = trim(str.substr(eq_pos + 1));
if (starts_with(Value, L'"'))
{
Label = trim(str.substr(0, eq_pos));
Data = Value.substr(1, Value.size() - 2);
return lng_line_type::both;
}
}
}
return lng_line_type::none;
}