当前位置: 首页>>代码示例>>C++>>正文


C++ basic_string::size方法代码示例

本文整理汇总了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;
  }
}
开发者ID:SwgSavior,项目名称:services,代码行数:60,代码来源:_num_get.c

示例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;
 }
开发者ID:kusl,项目名称:unicorn-lib,代码行数:7,代码来源:string-algorithm.hpp

示例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");
		}
	}
}
开发者ID:tmsf,项目名称:IT-AKA-Hash.shoup,代码行数:25,代码来源:bitstring.cpp

示例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);
}
开发者ID:AKKF,项目名称:altWinDirStat,代码行数:10,代码来源:strutils.cpp

示例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;
}}};
开发者ID:adamnagel,项目名称:libalf,代码行数:49,代码来源:co_logger.cpp

示例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;
}
开发者ID:rickyharis39,项目名称:nolf2,代码行数:34,代码来源:_string_io.c

示例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))
 {
 }
开发者ID:junmuz,项目名称:compute,代码行数:7,代码来源:basic_string.hpp

示例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;
 }
开发者ID:kusl,项目名称:unicorn-lib,代码行数:8,代码来源:string-algorithm.hpp

示例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;
  }
开发者ID:inetra,项目名称:peers1,代码行数:44,代码来源:_num_get.c

示例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
	}
开发者ID:yumetodo,项目名称:boost_html_parse,代码行数:11,代码来源:html_parse.cpp

示例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;
	}
开发者ID:Alex-Tsvetanov,项目名称:Informatics,代码行数:12,代码来源:trie.hpp

示例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;
		}
	}
开发者ID:Alex-Tsvetanov,项目名称:Informatics,代码行数:21,代码来源:trie.hpp

示例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;
    }
开发者ID:imzacm,项目名称:thor-os,代码行数:13,代码来源:string.hpp

示例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);
}
开发者ID:narychen,项目名称:felix,代码行数:13,代码来源:flx_strutil.hpp

示例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;
}
开发者ID:miaozhendaoren,项目名称:K2SAR_EMS,代码行数:38,代码来源:_num_get.c


注:本文中的basic_string::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。