本文整理汇总了C++中STR::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ STR::begin方法的具体用法?C++ STR::begin怎么用?C++ STR::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STR
的用法示例。
在下文中一共展示了STR::begin方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isPalindrome
/*
* Returns true if the specified string is a Palindrome.
*/
bool isPalindrome( STR str ) {
str.erase( std::remove_if( str.begin(), str.end(), ::isspace ), str.end() );
STR copy = str;
std::reverse( copy.begin(), copy.end() );
return ( strcmp( str.c_str(), copy.c_str() ) == 0 );
}
示例2: EndsWithT
bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) {
size_t str_length = str.length();
size_t search_length = search.length();
if (search_length > str_length)
return false;
if (case_sensitive)
return str.compare(str_length - search_length, search_length, search) == 0;
return std::equal(search.begin(), search.end(),
str.begin() + (str_length - search_length),
base::CaseInsensitiveCompare<typename STR::value_type>());
}
示例3: StartsWithT
bool StartsWithT(const STR& str, const STR& search, bool case_sensitive) {
if (case_sensitive) {
return str.compare(0, search.length(), search) == 0;
}
else {
if (search.size() > str.size())
return false;
return std::equal(search.begin(), search.end(), str.begin(),
base::CaseInsensitiveCompare<typename STR::value_type>());
}
}
示例4: scramble
/*
* Returns a scrambled string.
*/
STR scramble( STR str ) {
std::seed_seq sd( str.begin(), str.end() );
std::default_random_engine gen;
for ( int i = str.size() - 1; i > 0; --i ) {
gen.seed( sd );
std::uniform_int_distribution<int> dist( 0, i );
std::swap( str[i], str[dist( gen )] );
}
return str;
}
示例5: ContainsOnlyCharsT
static bool ContainsOnlyCharsT(const STR& input, const STR& characters)
{
for(typename STR::const_iterator iter=input.begin();
iter!=input.end(); ++iter)
{
if(characters.find(*iter) == STR::npos)
{
return false;
}
}
return true;
}
示例6: CollapseWhitespaceT
STR CollapseWhitespaceT(const STR& text,
bool trim_sequences_with_line_breaks)
{
STR result;
result.resize(text.size());
// 设置标志位为true假设已经在连续空白中, 这样可以移除开头的全部空白.
bool in_whitespace = true;
bool already_trimmed = true;
int chars_written = 0;
for(typename STR::const_iterator i=text.begin(); i!=text.end(); ++i)
{
if(IsWhitespace(*i))
{
if(!in_whitespace)
{
// 减少连续空白至一个空白.
in_whitespace = true;
result[chars_written++] = L' ';
}
if(trim_sequences_with_line_breaks && !already_trimmed &&
((*i=='\n') || (*i=='\r')))
{
// 包含回车换行的空白序列全部移除.
already_trimmed = true;
--chars_written;
}
}
else
{
// 非空白字符直接拷贝.
in_whitespace = false;
already_trimmed = false;
result[chars_written++] = *i;
}
}
if(in_whitespace && !already_trimmed)
{
// 忽略末尾的全部空白.
--chars_written;
}
result.resize(chars_written);
return result;
}
示例7: CollapseWhitespaceT
STR CollapseWhitespaceT(const STR& text,
bool trim_sequences_with_line_breaks) {
STR result;
result.resize(text.size());
// Set flags to pretend we're already in a trimmed whitespace sequence, so we
// will trim any leading whitespace.
bool in_whitespace = true;
bool already_trimmed = true;
int chars_written = 0;
for (typename STR::const_iterator i(text.begin()); i != text.end(); ++i) {
if (IsWhitespace(*i)) {
if (!in_whitespace) {
// Reduce all whitespace sequences to a single space.
in_whitespace = true;
result[chars_written++] = L' ';
}
if (trim_sequences_with_line_breaks && !already_trimmed &&
((*i == '\n') || (*i == '\r'))) {
// Whitespace sequences containing CR or LF are eliminated entirely.
already_trimmed = true;
--chars_written;
}
}
else {
// Non-whitespace chracters are copied straight across.
in_whitespace = false;
already_trimmed = false;
result[chars_written++] = *i;
}
}
if (in_whitespace && !already_trimmed) {
// Any trailing whitespace is eliminated.
--chars_written;
}
result.resize(chars_written);
return result;
}
示例8: reverse_all
/*
* Returns the whole specified string, reversed.
*/
STR reverse_all( STR str ) {
std::reverse( str.begin(), str.end() );
return str;
}