本文整理汇总了C++中std::string::rend方法的典型用法代码示例。如果您正苦于以下问题:C++ string::rend方法的具体用法?C++ string::rend怎么用?C++ string::rend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::rend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rstrncmp
//compare two strings starting from the end
//returns similar to strncmp
int rstrncmp(std::string lhs, std::string rhs, int rnum) {
auto lit = lhs.rbegin();
auto rit = rhs.rbegin();
int ret = 0;
while (rnum-- > 0) {
if (*lit < *rit) {
ret = -1;
break;
}
if (*lit > *rit) {
ret = 1;
break;
}
//check if the "end" of the string has been reached
if (lit++ == lhs.rend()) {
rnum = -1;
ret += -1;
}
if (rit++ == rhs.rend()) {
rnum = -1;
ret += 1;
}
}
//rnum ran out or was set to -1
return ret;
}
示例2: HasExtension
bool URIUtils::HasExtension(const std::string& strFileName, const std::string& strExtensions)
{
if (IsURL(strFileName))
{
CURL url(strFileName);
return HasExtension(url.GetFileName(), strExtensions);
}
// Search backwards so that '.' can be used as a search terminator.
std::string::const_reverse_iterator itExtensions = strExtensions.rbegin();
while (itExtensions != strExtensions.rend())
{
// Iterate backwards over strFileName untill we hit a '.' or a mismatch
for (std::string::const_reverse_iterator itFileName = strFileName.rbegin();
itFileName != strFileName.rend() && itExtensions != strExtensions.rend() &&
tolower(*itFileName) == *itExtensions;
++itFileName, ++itExtensions)
{
if (*itExtensions == '.')
return true; // Match
}
// No match. Look for more extensions to try.
while (itExtensions != strExtensions.rend() && *itExtensions != '|')
++itExtensions;
while (itExtensions != strExtensions.rend() && *itExtensions == '|')
++itExtensions;
}
return false;
}
示例3: remove_extension
std::string util::remove_extension( std::string const& filename ) {
auto pivot = std::find(filename.rbegin(), filename.rend(), '.');
if (pivot == filename.rend()) {
return filename;
}
return std::string(filename.begin(), pivot.base() - 1);
}
示例4: string
IGL_INLINE std::string igl::dirname(const std::string & path)
{
if(path == "")
{
return std::string("");
}
#if defined (WIN32)
char del('\\');
#else
char del('/');
#endif
// http://stackoverflow.com/questions/5077693/dirnamephp-similar-function-in-c
std::string::const_reverse_iterator last_slash =
std::find(
path.rbegin(),
path.rend(),del);
if( last_slash == path.rend() )
{
// No slashes found
return std::string(".");
}else if(1 == (last_slash.base() - path.begin()))
{
// Slash is first char
return std::string(&del);
}else if(path.end() == last_slash.base() )
{
// Slash is last char
std::string redo = std::string(path.begin(),path.end()-1);
return igl::dirname(redo);
}
return std::string(path.begin(),last_slash.base()-1);
}
示例5: loadAsset
virtual SharedAssetTypeT loadAsset( const std::string& name ) noexcept override
{
SharedAssetTypeT shared;
auto rit( name.rbegin() );
while ( rit != name.rend() )
{
if ( *rit == ':' )
{
break;
}
++rit;
}
if ( rit == name.rend() )
{
assert( false && "FontMgr can't parse willing font ptsize from asset name" );
}
auto fit = --( rit.base() ); //forward iterator
std::string fileName{ name.begin(), fit };
std::string ptStr{ ++fit, name.end() };
int ptSize{ std::stoi( ptStr ) };
TTF_Font* rawFont{ TTF_OpenFontIndex( fileName.c_str(), ptSize, 0 ) };
if ( rawFont == nullptr )
{
//TODO: some logging lib needed
}
else
{
shared = Font::create( rawFont, ptSize );
}
return ( shared );
}
示例6:
void
check_lcs_delta_algorithm()
{
cout << "******* check_lcs_delta_algorithm()" << endl;
const std::string nano = "nano";
const std::string aano = "aano";
const std::string ano = "ano";
const std::string anoo = "anoo";
const std::string nematode_knowledge = "nematode knowledge";
const std::string empty_bottle = "empty bottle";
test_lcs_delta(nano, aano, "ano");
test_lcs_delta(nano, ano, "ano");
test_lcs_delta(nano, anoo, "ano");
test_lcs_delta(ano, ano, "ano");
test_lcs_delta(nano, nematode_knowledge, "nano");
test_lcs_delta(empty_bottle, nematode_knowledge, "emt ole");
//use an equals with a wildcard
{
const std::string x = "nano";
const std::string y = "aaao";
std::string result_x;
std::string result_y;
lcs_delta(
x.rbegin(),
x.rend(),
y.rbegin(),
y.rend(),
make_lcs_inserter(result_x, result_y),
WildcardNsEqualTo());
BOOST_CHECK_EQUAL(y, result_y);
BOOST_CHECK_EQUAL(x, result_x);
}
//test on real sequences
{
#ifdef VERBOSE_CHECKING
cout << "Testing DLX5 remo 1" << endl;
#endif
build_test_remos();
#ifdef VERBOSE_CHECKING
boost::progress_timer timer;
#endif
seq_t result;
lcs_delta(
test_remos["dlx5_1"]->map[MOUSE_SPECIES].rbegin(),
test_remos["dlx5_1"]->map[MOUSE_SPECIES].rend(),
test_remos["dlx5_1"]->map[HUMAN_SPECIES].rbegin(),
test_remos["dlx5_1"]->map[HUMAN_SPECIES].rend(),
make_lcs_inserter(result));
BOOST_CHECK_EQUAL(result.size(), 574u);
}
}
示例7: getFilename
std::string FileSystem::getFilename(const std::string &filePath)
{
auto lastSlashPos = std::find_if(filePath.rbegin(), filePath.rend(), [](char ch) { return ch == '/' || ch == '\\'; });
if (lastSlashPos == filePath.rend())
return "";
return std::string(lastSlashPos.base(), filePath.end());
}
示例8: get_txt_file_for
std::string get_txt_file_for(const std::string file_path) {
auto it = file_path.rbegin();
for (; it != file_path.rend() && *it != '.'; ++it);
if (it == file_path.rend())
return file_path + ".txt";
else
return std::string(file_path.begin(), file_path.end() - (it - file_path.rbegin())) + "txt";
}
示例9: removePath
std::string removePath( std::string const& filename )
{
std::string::const_reverse_iterator
pivot
= std::find( filename.rbegin(), filename.rend(), '/' );
return pivot == filename.rend()
? filename
: std::string( pivot.base(), filename.end() );
}
示例10: removeExtension
std::string removeExtension( std::string const& filename )
{
std::string::const_reverse_iterator
pivot
= std::find( filename.rbegin(), filename.rend(), '.' );
return pivot == filename.rend()
? filename
: std::string( filename.begin(), pivot.base() - 1 );
}
示例11: matches2
OutT matches2 (std::string const& ws, std::string const& s, OutT dst) {
std::string sw (ws.rbegin (), ws.rend ());
std::size_t num_chars=s.size ();
for (std::size_t i = 0; i < num_chars; ++i) {
std::string::const_reverse_iterator rbegin = s.rbegin ();
std::advance (rbegin, num_chars - i);
if (prefix (sw.begin (), sw.end (), rbegin, s.rend ())) {
*dst++ = i;
}
}
return dst;
}
示例12: getNext
bool getNext(std::string& s, char skip) {
std::string::reverse_iterator j = s.rbegin();
while (j != s.rend()) {
*j = '0' + (*j - '0' + 1) % 10;
bool carry = *j == '0';
if (*j == skip) {
*j = '0' + (*j - '0' + 1) % 10;
carry |= *j == '0';
}
if (carry) ++j;
else break;
}
return j != s.rend();
}
示例13: basename
std::string basename( std::string const& pathname )
{
return std::string(
std::find_if( pathname.rbegin(), pathname.rend(),
MatchPathSeparator() ).base(),
pathname.end() );
}
示例14: trim
/**
* Trim spaces
* @param strig
*/
void IniConfigs::trim(std::string &str) const
{
// trim from start
str.erase(str.begin(), std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
// trim from end
str.erase(std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());
}
示例15: test_both
void test_both(std::string const& caseid,
T pi_x, T pi_y, T pj_x, T pj_y, T pk_x, T pk_y,
T qi_x, T qi_y, T qj_x, T qj_y, T qk_x, T qk_y,
bg::detail::overlay::method_type method
= bg::detail::overlay::method_none,
T ip_x = -1, T ip_y = -1,
std::string const& expected = "",
T ip_x2 = -1, T ip_y2 = -1)
{
test_with_point<P, double>(caseid,
pi_x, pi_y, pj_x, pj_y, pk_x, pk_y,
qi_x, qi_y, qj_x, qj_y, qk_x, qk_y,
method, ip_x, ip_y, expected, ip_x2, ip_y2);
//return;
std::string reversed(expected.rbegin(), expected.rend());
if (ip_x2 >= 0 && ip_y2 >= 0)
{
std::swap(ip_x, ip_x2);
std::swap(ip_y, ip_y2);
}
test_with_point<P, double>(caseid + "_r",
qi_x, qi_y, qj_x, qj_y, qk_x, qk_y, // q
pi_x, pi_y, pj_x, pj_y, pk_x, pk_y, // p
method, ip_x, ip_y, reversed, ip_x2, ip_y2);
}