本文整理汇总了C++中std::basic_string::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::begin方法的具体用法?C++ basic_string::begin怎么用?C++ basic_string::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
std::vector<std::basic_string<T_Char>> split(
const std::basic_string<T_Char>& src,
const std::basic_string<T_Char>& delimit) {
std::vector<std::basic_string<T_Char>> array;
typedef typename std::basic_string<T_Char>::size_type size_type;
typedef typename std::basic_string<T_Char>::const_iterator const_iterator;
std::basic_string<T_Char> tmp;
if (src.empty())
return array;
if (delimit.empty()) {
array.reserve(array.size() + src.size());
for (const_iterator it = src.begin(); it != src.end(); ++it)
array.push_back(std::basic_string<T_Char>(1, *it));
return array;
}
size_type src_pos = 0;
while (src.begin() + src_pos != src.end()) {
size_type fnd_pos = src.find(delimit, src_pos);
if (fnd_pos == std::basic_string<T_Char>::npos) {
array.push_back(std::basic_string<T_Char>(src, src_pos));
break;
}
array.push_back(
std::basic_string<T_Char>(src, src_pos, fnd_pos - src_pos));
src_pos = fnd_pos + delimit.length();
}
return array;
}
示例2: regex_split
std::size_t regex_split(OutputIterator out,
std::basic_string<charT, Traits1, Alloc1>& s,
const basic_regex<charT, Traits2>& e,
match_flag_type flags,
std::size_t max_split)
{
typedef typename std::basic_string<charT, Traits1, Alloc1>::const_iterator ci_t;
//typedef typename match_results<ci_t>::allocator_type match_allocator;
ci_t last = s.begin();
std::size_t init_size = max_split;
re_detail::split_pred<OutputIterator, charT, Traits1, Alloc1> pred(&last, &out, &max_split);
ci_t i, j;
i = s.begin();
j = s.end();
regex_grep(pred, i, j, e, flags);
//
// if there is still input left, do a final push as long as max_split
// is not exhausted, and we're not splitting sub-expressions rather
// than whitespace:
if(max_split && (last != s.end()) && (e.mark_count() == 0))
{
*out = std::basic_string<charT, Traits1, Alloc1>((ci_t)last, (ci_t)s.end());
++out;
last = s.end();
--max_split;
}
//
// delete from the string everything that has been processed so far:
s.erase(0, last - s.begin());
//
// return the number of new records pushed:
return init_size - max_split;
}
示例3: compare
bool compare(const std::basic_string<CharT> &lhs, const std::basic_string<CharT> &rhs)
{
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), [](const CharT l, const CharT r)->bool
{
return ::toupper(l) == ::toupper(r);
});
}
示例4: is_palindrome
bool is_palindrome(std::basic_string<Char, Traits, Allocater> str) {
typedef typename std::basic_string<Char, Traits, Allocater> string;
typename string::iterator end {std::remove_if(str.begin(), str.end(), non_letter<Char>)};
string reversed{str.begin(), end};
std::reverse(reversed.begin(), reversed.end());
return not reversed.empty() and std::equal(str.begin(), end, reversed.begin(), is_same_character<Char>);
}
示例5: assert
void
test(const std::basic_string<CharT>& x, const std::basic_string<CharT>& y, bool doCStrTests = true)
{
typedef std::basic_string<CharT> string;
typedef std::sub_match<typename string::const_iterator> sub_match;
sub_match sm1;
sm1.first = x.begin();
sm1.second = x.end();
sm1.matched = true;
sub_match sm2;
sm2.first = y.begin();
sm2.second = y.end();
sm2.matched = true;
assert((sm1 == sm2) == (x == y));
assert((sm1 != sm2) == (x != y));
assert((sm1 < sm2) == (x < y));
assert((sm1 > sm2) == (x > y));
assert((sm1 <= sm2) == (x <= y));
assert((sm1 >= sm2) == (x >= y));
assert((x == sm2) == (x == y));
assert((x != sm2) == (x != y));
assert((x < sm2) == (x < y));
assert((x > sm2) == (x > y));
assert((x <= sm2) == (x <= y));
assert((x >= sm2) == (x >= y));
assert((sm1 == y) == (x == y));
assert((sm1 != y) == (x != y));
assert((sm1 < y) == (x < y));
assert((sm1 > y) == (x > y));
assert((sm1 <= y) == (x <= y));
assert((sm1 >= y) == (x >= y));
if (doCStrTests) {
assert((x.c_str() == sm2) == (x == y));
assert((x.c_str() != sm2) == (x != y));
assert((x.c_str() < sm2) == (x < y));
assert((x.c_str() > sm2) == (x > y));
assert((x.c_str() <= sm2) == (x <= y));
assert((x.c_str() >= sm2) == (x >= y));
assert((sm1 == y.c_str()) == (x == y));
assert((sm1 != y.c_str()) == (x != y));
assert((sm1 < y.c_str()) == (x < y));
assert((sm1 > y.c_str()) == (x > y));
assert((sm1 <= y.c_str()) == (x <= y));
assert((sm1 >= y.c_str()) == (x >= y));
}
assert((x[0] == sm2) == (string(1, x[0]) == y));
assert((x[0] != sm2) == (string(1, x[0]) != y));
assert((x[0] < sm2) == (string(1, x[0]) < y));
assert((x[0] > sm2) == (string(1, x[0]) > y));
assert((x[0] <= sm2) == (string(1, x[0]) <= y));
assert((x[0] >= sm2) == (string(1, x[0]) >= y));
assert((sm1 == y[0]) == (x == string(1, y[0])));
assert((sm1 != y[0]) == (x != string(1, y[0])));
assert((sm1 < y[0]) == (x < string(1, y[0])));
assert((sm1 > y[0]) == (x > string(1, y[0])));
assert((sm1 <= y[0]) == (x <= string(1, y[0])));
assert((sm1 >= y[0]) == (x >= string(1, y[0])));
}
示例6: move
std::basic_string < Elem, Traits > cell_encode(std::basic_string < Elem, Traits > Str, Elem Sep_, Elem Esc){
if(Str.find(Sep_) < Str.size() || Str.find(Esc) < Str.size()){
for(auto itr = Str.begin(); itr != Str.end(); ++itr){
if(*itr == Esc){
itr = Str.insert(++itr, Esc);
}
}
Str.insert(Str.begin(), Esc);
Str.push_back(Esc);
}
return std::move(Str);
}
示例7: if
std::basic_string<CharType> escape_argument(const std::basic_string<CharType>& arg)
{
std::basic_string<CharType> result(1, argument_helper<CharType>::QUOTE_CHARACTER);
for (auto it = arg.begin();; ++it)
{
unsigned int escapes_count = 0;
while ((it != arg.end()) && (*it == argument_helper<CharType>::ESCAPE_CHARACTER))
{
++it;
++escapes_count;
}
if (it == arg.end())
{
result.append(escapes_count * 2, argument_helper<CharType>::ESCAPE_CHARACTER);
break;
}
else if (*it == argument_helper<CharType>::QUOTE_CHARACTER)
{
result.append(escapes_count * 2 + 1, argument_helper<CharType>::ESCAPE_CHARACTER);
result.push_back(*it);
}
else
{
result.append(escapes_count, argument_helper<CharType>::ESCAPE_CHARACTER);
result.push_back(*it);
}
}
result.push_back(argument_helper<CharType>::QUOTE_CHARACTER);
return result;
}
示例8: regex_grep
inline unsigned int regex_grep(bool (*foo)(const match_results<std::basic_string<wchar_t>::const_iterator>&),
const std::basic_string<wchar_t>& s,
const wregex& e,
match_flag_type flags = match_default)
{
return regex_grep(foo, s.begin(), s.end(), e, flags);
}
示例9: xml_parser_error
std::basic_string<Ch> decode_char_entities(const std::basic_string<Ch> &s)
{
typedef typename std::basic_string<Ch> Str;
Str r;
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin(); it != end; ++it)
{
if (*it == Ch('&'))
{
typename Str::const_iterator semicolon = std::find(it + 1, end, Ch(';'));
if (semicolon == end)
throw xml_parser_error("invalid character entity", "", 0);
Str ent(it + 1, semicolon);
if (ent == detail::widen<Ch>("lt")) r += Ch('<');
else if (ent == detail::widen<Ch>("gt")) r += Ch('>');
else if (ent == detail::widen<Ch>("amp")) r += Ch('&');
else
throw xml_parser_error("invalid character entity", "", 0);
it = semicolon;
}
else
r += *it;
}
return r;
}
示例10: regex_match
inline bool regex_match(const std::basic_string<wchar_t>& s,
match_results<std::basic_string<wchar_t>::const_iterator>& m,
const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
示例11: regex_search
inline bool regex_search(const std::basic_string<wchar_t>& s,
wsmatch& m,
const wregex& e,
match_flag_type flags = match_default)
{
return regex_search(s.begin(), s.end(), m, e, flags);
}
示例12: TrimRight
void IO::TrimRight(std::basic_string<charType> & str, const char* chars2remove)
{
if (!str.empty()) { //trim the characters in chars2remove from the right
std::string::size_type pos = 0;
if (chars2remove != NULL) {
pos = str.find_last_not_of(chars2remove);
if (pos != std::string::npos)
str.erase(pos+1);
else
str.erase( str.begin() , str.end() ); // make empty
}
else { //trim space
pos = std::string::npos;
for (int i = str.size()-1; i >= 0; --i) {
if (!isspace(str[i])) {
pos = i;
break;
}
}
if (pos != std::string::npos) {
if (pos+1 != str.size())
str.resize(pos+1);
}
else {
str.clear();
}
}
}
}
示例13: sp
std::basic_string<Ch> encode_char_entities(const std::basic_string<Ch> &s)
{
// Don't do anything for empty strings.
if(s.empty()) return s;
typedef typename std::basic_string<Ch> Str;
Str r;
// To properly round-trip spaces and not uglify the XML beyond
// recognition, we have to encode them IF the text contains only spaces.
Str sp(1, Ch(' '));
if(s.find_first_not_of(sp) == Str::npos) {
// The first will suffice.
r = detail::widen<Ch>(" ");
r += Str(s.size() - 1, Ch(' '));
} else {
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin(); it != end; ++it)
{
switch (*it)
{
case Ch('<'): r += detail::widen<Ch>("<"); break;
case Ch('>'): r += detail::widen<Ch>(">"); break;
case Ch('&'): r += detail::widen<Ch>("&"); break;
case Ch('"'): r += detail::widen<Ch>("""); break;
case Ch('\''): r += detail::widen<Ch>("'"); break;
default: r += *it; break;
}
}
}
return r;
}
示例14: trim
std::basic_string<Ch> trim(const std::basic_string<Ch> &s,
const std::locale &loc = std::locale())
{
typename std::basic_string<Ch>::const_iterator first = s.begin();
typename std::basic_string<Ch>::const_iterator end = s.end();
while (first != end && std::isspace(*first, loc))
++first;
if (first == end)
return std::basic_string<Ch>();
typename std::basic_string<Ch>::const_iterator last = end;
do --last; while (std::isspace(*last, loc));
if (first != s.begin() || last + 1 != end)
return std::basic_string<Ch>(first, last + 1);
else
return s;
}
示例15: while
//! Converts escape sequences to the corresponding characters
void char_constants< char >::translate_escape_sequences(std::basic_string< char_type >& str)
{
using namespace std; // to make sure we can use C functions unqualified
std::basic_string< char_type >::iterator it = str.begin();
while (it != str.end())
{
it = std::find(it, str.end(), '\\');
if (std::distance(it, str.end()) >= 2)
{
it = str.erase(it);
switch (*it)
{
case 'n':
*it = '\n'; break;
case 'r':
*it = '\r'; break;
case 'a':
*it = '\a'; break;
case '\\':
++it; break;
case 't':
*it = '\t'; break;
case 'b':
*it = '\b'; break;
case 'x':
{
std::basic_string< char_type >::iterator b = it;
if (std::distance(++b, str.end()) >= 2)
{
char_type c1 = *b++, c2 = *b++;
if (isxdigit(c1) && isxdigit(c2))
{
*it++ = char_type((to_number(c1) << 4) | to_number(c2));
it = str.erase(it, b);
}
}
break;
}
default:
{
if (*it >= '0' && *it <= '7')
{
std::basic_string< char_type >::iterator b = it;
int c = (*b++) - '0';
if (*b >= '0' && *b <= '7')
c = c * 8 + (*b++) - '0';
if (*b >= '0' && *b <= '7')
c = c * 8 + (*b++) - '0';
*it++ = char_type(c);
it = str.erase(it, b);
}
break;
}
}
}
}
}