本文整理汇总了C++中StringView::size方法的典型用法代码示例。如果您正苦于以下问题:C++ StringView::size方法的具体用法?C++ StringView::size怎么用?C++ StringView::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringView
的用法示例。
在下文中一共展示了StringView::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveString
void SaveString(const char* filename, StringView data)
{
FILE* f = 0;
fopen_s(&f, filename, "wb");
if (!f)
{
ghlib::Log::Error("Could not open file `", filename, "`");
return;
}
fwrite(data.begin(), data.size(), 1, f);
fclose(f);
}
示例2: make_tuple
// TODO US-ASCII support only, no UTF-8 support
// While UTF-8 might work in some cases, we do not guarantee full functionality
template <typename StringView> inline auto decompose(const StringView &lhs, const StringView &rhs)
{
auto const lcs = longest_common_substring(lhs, rhs);
// trim spaces, transform to lower
const auto trim = [](StringView view) {
// we compare suffixes based on this value, it might break UTF chars, but as long as we are
// consistent in handling, we do not create bad results
std::string str = boost::to_lower_copy(view.to_string());
auto front = str.find_first_not_of(" ");
if (front == std::string::npos)
return str;
auto back = str.find_last_not_of(" ");
return str.substr(front, back - front + 1);
};
if (lcs.empty())
{
return std::make_tuple(trim(lhs), trim(rhs), std::string(), std::string());
}
// find the common substring in both
auto lhs_pos = lhs.find(lcs);
auto rhs_pos = rhs.find(lcs);
BOOST_ASSERT(lhs_pos + lcs.size() <= lhs.size());
BOOST_ASSERT(rhs_pos + lcs.size() <= rhs.size());
// prefixes
auto lhs_prefix = (lhs_pos > 0) ? lhs.substr(0, lhs_pos) : StringView();
auto rhs_prefix = (rhs_pos > 0) ? rhs.substr(0, rhs_pos) : StringView();
// suffices
auto lhs_suffix = lhs.substr(lhs_pos + lcs.size());
auto rhs_suffix = rhs.substr(rhs_pos + lcs.size());
return std::make_tuple(trim(lhs_prefix), trim(lhs_suffix), trim(rhs_prefix), trim(rhs_suffix));
}
示例3: execute
void ExtractProtocol::execute(Pos data, size_t size, Pos & res_data, size_t & res_size)
{
res_data = data;
res_size = 0;
StringView scheme = getURLScheme(StringView(data, size));
Pos pos = data + scheme.size();
if (scheme.empty() || (data + size) - pos < 4)
return;
if (pos[0] == ':')
res_size = pos - data;
}
示例4: CreateParentDirs
bool CreateParentDirs(StringView PathArgument)
{
auto Sep = "/\\"_sv;
auto FirstIndex = PathArgument.find_first_of(Sep);
if (FirstIndex == PathArgument.npos)
return true; // No directories.
// Create our own copy so we can add zeroes.
char Path[MFile::MaxPath];
strcpy_safe(Path, PathArgument);
auto End = Path + PathArgument.size();
char* p = Path + FirstIndex;
while (true)
{
// Set the current slash to zero, and revert this change before the next loop iteration.
auto OldValue = *p;
*p = 0;
// Capture by value to ignore the change to p at the end.
DEFER([=] { *p = OldValue; });
if (!MFile::IsDir(Path))
{
if (!MFile::CreateDir(Path))
{
return false;
}
}
p = std::find_first_of(p + 1, End, Sep.begin(), Sep.end());
if (p == End)
break;
}
return true;
}
示例5: digestUnmodifiedString
void EnzymaticDigestion::digestUnmodifiedString(const StringView sequence, std::vector<StringView>& output, Size min_length, Size max_length) const
{
// initialization
output.clear();
// naive cleavage sites
std::vector<Size> pep_positions = tokenize_(sequence.getString());
Size count = pep_positions.size();
// disable max length filter by setting to maximum length
if (max_length == 0)
{
max_length = sequence.size();
}
// no cleavage sites? return full string
if (count == 0)
{
if (sequence.size() >= min_length && sequence.size() <= max_length)
{
output.push_back(sequence);
}
return;
}
for (Size i = 1; i != count; ++i)
{
// add if cleavage product larger then min length
Size l = pep_positions[i] - pep_positions[i - 1];
if (l >= min_length && l <= max_length)
{
output.push_back(sequence.substr(pep_positions[i - 1], pep_positions[i] - 1));
}
}
// add last cleavage product (need to add because end is not a cleavage site) if larger then min length
Size l = sequence.size() - pep_positions[count - 1];
if (l >= min_length && l <= max_length)
{
output.push_back(sequence.substr(pep_positions[count - 1], sequence.size() - 1));
}
// generate fragments with missed cleavages
for (Size i = 1; ((i <= missed_cleavages_) && (i < count)); ++i)
{
for (Size j = 1; j < count - i; ++j)
{
Size l = pep_positions[j + i] - pep_positions[j - 1];
if (l >= min_length && l <= max_length)
{
output.push_back(sequence.substr(pep_positions[j - 1], pep_positions[j + i] - 1));
}
}
// add last cleavage product (need to add because end is not a cleavage site)
Size l = sequence.size() - pep_positions[count - i - 1];
if (l >= min_length && l <= max_length)
{
output.push_back(sequence.substr(pep_positions[count - i - 1], sequence.size() - 1 ));
}
}
}
示例6: strncmp
inline
bool StringView::operator==(StringView const& rhs) const {
return rhs.size() == _size && strncmp(_beg, rhs._beg, _size) == 0;
}