本文整理汇总了C++中basic_string::size方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::size方法的具体用法?C++ basic_string::size怎么用?C++ basic_string::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类basic_string
的用法示例。
在下文中一共展示了basic_string::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end,
ios_base& __s,
ios_base::iostate& __err, bool& __x) const
{
if (__s.flags() & ios_base::boolalpha) {
locale __loc = __s.getloc();
const _Numpunct& __np = *(const _Numpunct*)__s._M_numpunct_facet();
// const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc) ;
// const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc) ;
const basic_string<_CharT> __truename = __np.truename();
const basic_string<_CharT> __falsename = __np.falsename();
bool __true_ok = true;
bool __false_ok = true;
size_t __n = 0;
for ( ; __in != __end; ++__in) {
_CharT __c = *__in;
__true_ok = __true_ok && (__c == __truename[__n]);
__false_ok = __false_ok && (__c == __falsename[__n]);
++__n;
if ((!__true_ok && !__false_ok) ||
(__true_ok && __n >= __truename.size()) ||
(__false_ok && __n >= __falsename.size())) {
++__in;
break;
}
}
if (__true_ok && __n < __truename.size()) __true_ok = false;
if (__false_ok && __n < __falsename.size()) __false_ok = false;
if (__true_ok || __false_ok) {
__err = ios_base::goodbit;
__x = __true_ok;
}
else
__err = ios_base::failbit;
if (__in == __end)
__err |= ios_base::eofbit;
return __in;
}
else {
long __lx;
_InputIter __tmp = this->do_get(__in, __end, __s, __err, __lx);
if (!(__err & ios_base::failbit)) {
if (__lx == 0)
__x = false;
else if (__lx == 1)
__x = true;
else
__err |= ios_base::failbit;
}
return __tmp;
}
}
示例2: str_common
size_t str_common(const basic_string<C>& s1, const basic_string<C>& s2, size_t start = 0) noexcept {
if (start >= s1.size() || start >= s2.size())
return 0;
auto p = s1.data() + start;
for (auto q = s2.data() + start, endp = p + std::min(s1.size(), s2.size()); p != endp && *p == *q; ++p, ++q) {}
return p - s1.data() - start;
}
示例3: out_of_range
bitstring::bitstring ( size_t size, const basic_string<charT,traits,Allocator>& str,
typename basic_string<charT,traits,Allocator>::size_type pos,
typename basic_string<charT,traits,Allocator>::size_type n) {
if (pos > str.size()) {
throw out_of_range("initial position not valid");
}
data = new bool[size];
sz = size;
const size_t nbits = std::min(size, std::min(n, str.size() - pos));
for (size_t i = 0; i < nbits; i++)
{
switch(str[pos + nbits - i - 1])
{
case '0':
break;
case '1':
set(i);
break;
default:
throw invalid_argument("invalid string format");
}
}
}
示例4: strip
template<class CharType> basic_string<CharType> strip(const basic_string<CharType>& str) {
basic_string<CharType>::size_type hp = 0;
basic_string<CharType>::size_type tp = str.size();
while ((hp < str.size()) && ((static_cast<unsigned>(str[hp]) <= 0x20) || (str[hp] == 0x7F)))
hp++;
if (hp < str.size())
while ((static_cast<unsigned>(str[tp - 1]) <= 0x20) || (str[tp - 1] == 0x7F))
tp--;
return str.substr(hp, tp - hp);
}
示例5: handle_command
bool co_logger::handle_command(int command, basic_string<int32_t> & command_data)
{{{
string *s;
int level;
switch(command) {
case LOGGER_RECEIVE_AND_FLUSH:
if(command_data.size() != 0)
return this->sv->send_errno(ERR_BAD_PARAMETER_COUNT);
s = o->receive_and_flush();
if(!this->sv->send_errno(ERR_SUCCESS)) {
delete s;
return false;
}
if(!this->sv->client->stream_send_string(s->c_str())) {
delete s;
return false;
}
delete s;
return true;
case LOGGER_SET_MIN_LOGLEVEL:
if(command_data.size() != 1)
return this->sv->send_errno(ERR_BAD_PARAMETER_COUNT);
level = ntohl(command_data[0]);
if(level < 1 || level > 4)
return this->sv->send_errno(ERR_BAD_PARAMETERS);
o->set_minimal_loglevel((enum logger_loglevel) level);
return this->sv->send_errno(ERR_SUCCESS);
case LOGGER_LOG_ALGORITHM:
if(command_data.size() != 0)
return this->sv->send_errno(ERR_BAD_PARAMETER_COUNT);
o->set_log_algorithm(true);
return this->sv->send_errno(ERR_SUCCESS);
case LOGGER_NOT_LOG_ALGORITHM:
if(command_data.size() != 0)
return this->sv->send_errno(ERR_BAD_PARAMETER_COUNT);
o->set_log_algorithm(false);
return this->sv->send_errno(ERR_SUCCESS);
default:
return this->sv->send_errno(ERR_BAD_COMMAND);
}
return false;
}}};
示例6: min
ostream& __STL_CALL operator<<(ostream& __os,
const basic_string<_CharT,_Traits,_Alloc>& __s)
{
__STL_USING_VENDOR_STD
streambuf* __buf = __os.rdbuf();
if (__buf) {
size_t __n = __s.size();
size_t __pad_len = 0;
const bool __left = (__os.flags() & ios::left) !=0;
const size_t __w = __os.width();
if (__w > 0) {
__n = min(__w, __n);
__pad_len = __w - __n;
}
if (!__left)
__sgi_string_fill(__os, __buf, __pad_len);
const size_t __nwritten = __buf->sputn(__s.data(), __n);
if (__left)
__sgi_string_fill(__os, __buf, __pad_len);
if (__nwritten != __n)
__os.clear(__os.rdstate() | ios::failbit);
__os.width(0);
}
else
__os.clear(__os.rdstate() | ios::badbit);
return __os;
}
示例7:
basic_string(const basic_string &other,
size_type pos,
size_type count = npos)
: m_data(other.begin() + pos,
other.begin() + (std::min)(other.size(), count))
{
}
示例8: str_expect
bool str_expect(UtfIterator<C>& i, const UtfIterator<C>& end, const basic_string<C>& prefix) {
size_t psize = prefix.size();
if (psize == 0 || end.offset() - i.offset() < psize
|| memcmp(i.source().data() + i.offset(), prefix.data(), psize) != 0)
return false;
i = utf_iterator(i.source(), i.offset() + psize);
return true;
}
示例9:
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in_ite, _InputIter __end,
ios_base& __s,
ios_base::iostate& __err, bool& __x) const {
if (__s.flags() & ios_base::boolalpha) {
locale __loc = __s.getloc();
const _Numpunct& __np = *__STATIC_CAST(const _Numpunct*, __s._M_numpunct_facet());
// const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc) ;
// const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc) ;
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > __truename = __np.truename();
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > __falsename = __np.falsename();
bool __true_ok = true;
bool __false_ok = true;
size_t __n = 0;
for ( ; __in_ite != __end; ++__in_ite) {
_CharT __c = *__in_ite;
__true_ok = __true_ok && (__c == __truename[__n]);
__false_ok = __false_ok && (__c == __falsename[__n]);
++__n;
if ((!__true_ok && !__false_ok) ||
(__true_ok && __n >= __truename.size()) ||
(__false_ok && __n >= __falsename.size())) {
++__in_ite;
break;
}
}
if (__true_ok && __n < __truename.size()) __true_ok = false;
if (__false_ok && __n < __falsename.size()) __false_ok = false;
if (__true_ok || __false_ok) {
__err = ios_base::goodbit;
__x = __true_ok;
}
else
__err = ios_base::failbit;
if (__in_ite == __end)
__err |= ios_base::eofbit;
return __in_ite;
}
示例10:
node_piece_v<char_type> parse_path(const basic_string<char_type>& path) {
node_piece_v<char_type> re;
size_t current = 0;
for (size_t found; basic_string<char_type>::npos != (found = path.find_first_of(' ', current)); current = found + 1) {
//call basic_string<char_type> ->node_select_piece<char_type> convert constructor
re.emplace_back(std::basic_string<char_type>(path, current, found - current));
}
auto&& str = path.substr(current, path.size() - current);
re.emplace_back(std::move(str));
return re;//expect NRVO
}
示例11: has
bool has (basic_string <char> s)
{
trie* curr = children [s [0] - 'a'];
for (int i = 1 ; i < (int)s.size () ; i ++)
{
if (curr == nullptr)
return false;
curr = curr->children [s [i] - 'a'];
}
return curr->is_end;
}
示例12: remove
void remove (basic_string <char> s)
{
trie* curr = children [s [0] - 'a'];
trie* for_del = nullptr; int j = -1;
for (int i = 1 ; i < (int)s.size () ; i ++)
{
if (curr->is_end)
{
for_del = curr;
j = i;
}
curr = curr->children [s [i] - 'a'];
}
curr->is_end = false;
for (int i = j + 1 ; i < (int)s.size () ; i ++)
{
curr = for_del->children [s [i] - 'a'];
delete[] for_del;
for_del = curr;
}
}
示例13:
bool operator==(const basic_string& rhs) const {
if(size() != rhs.size()){
return false;
}
for(size_t i = 0; i < size(); ++i){
if(_data[i] != rhs._data[i]){
return false;
}
}
return true;
}
示例14: substr
basic_string<T> substr(basic_string<T> const &s, int b, int e)
{
int n = s.size();
if(b<0) b=b+n;
if(b<0) b=0;
if(b>=n) b=n;
if(e<0) e=e+n;
if(e<0) e=0;
if(e>=n) e=n;
int m = e-b;
if(m<0) m=0;
return s.substr(b,m);
}
示例15:
_InputIter _STLP_CALL
__do_get_alphabool(_InputIter& __in_ite, _InputIter& __end, ios_base& __str,
ios_base::iostate& __err, bool& __x, _CharT* /*__pc*/) {
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__str.getloc());
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > __truename = __np.truename();
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > __falsename = __np.falsename();
bool __true_ok = true;
bool __false_ok = true;
size_t __n = 0;
for ( ; __in_ite != __end; ++__in_ite) {
_CharT __c = *__in_ite;
__true_ok = __true_ok && (__c == __truename[__n]);
__false_ok = __false_ok && (__c == __falsename[__n]);
++__n;
if ((!__true_ok && !__false_ok) ||
(__true_ok && __n >= __truename.size()) ||
(__false_ok && __n >= __falsename.size())) {
++__in_ite;
break;
}
}
if (__true_ok && __n < __truename.size()) __true_ok = false;
if (__false_ok && __n < __falsename.size()) __false_ok = false;
if (__true_ok || __false_ok) {
__err = ios_base::goodbit;
__x = __true_ok;
}
else
__err = ios_base::failbit;
if (__in_ite == __end)
__err |= ios_base::eofbit;
return __in_ite;
}