本文整理汇总了C++中std::basic_string::size方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::size方法的具体用法?C++ basic_string::size怎么用?C++ basic_string::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_pair
std::pair<iterator, bool> insert_impl(trie_node_type& __node, const std::basic_string<T>& __word, size_t __at) {
if (__at == __word.size()) {
++__node._M_words;
++__node._M_prefix;
return std::make_pair(trie_iterator<trie_node_type>(__word, &__node), false);
}
++__node._M_prefix;
trie_node_type *_new_node = nullptr;
bool _new_insert = false;
auto _it = __node._M_children.find(__word[__at]);
if (_it == __node._M_children.end()) {
_new_node = new trie_node_type();
_new_insert = true;
__node._M_children[__word[__at]].reset(_new_node);
}
else {
_new_node = _it->second.get();
}
auto _ret = insert_impl(*_new_node, __word, ++__at);
_ret.second |= _new_insert;
return _ret;
}
示例2: kbe_split
inline void kbe_split(const std::basic_string<T>& s, T c, std::vector< std::basic_string<T> > &v)
{
if(s.size() == 0)
return;
typename std::basic_string< T >::size_type i = 0;
typename std::basic_string< T >::size_type j = s.find(c);
while(j != std::basic_string<T>::npos)
{
std::basic_string<T> buf = s.substr(i, j - i);
if(buf.size() > 0)
v.push_back(buf);
i = ++j; j = s.find(c, j);
}
if(j == std::basic_string<T>::npos)
{
std::basic_string<T> buf = s.substr(i, s.length() - i);
if(buf.size() > 0)
v.push_back(buf);
}
}
示例3: test_normc
void test_normc(std::basic_string<Char> orig,std::basic_string<Char> normal,boost::locale::norm_type type)
{
std::locale l = boost::locale::generator().generate("en_US.UTF-8");
TEST(normalize(orig,type,l)==normal);
TEST(normalize(orig.c_str(),type,l)==normal);
TEST(normalize(orig.c_str(),orig.c_str()+orig.size(),type,l)==normal);
}
示例4: TokenizerTest
void TokenizerTest()
{
const std::basic_string<utf16_t> xmlText =
Transcoder::UTF8toUTF16("<token1><token2 />\nhello world.\nhello xml.</token1>");
XMLParser<utf16_t>::Tokenizer tokenizer(xmlText.c_str(), xmlText.c_str() + xmlText.size());
std::basic_string<utf16_t> result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("<token1>"));
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("<token2 />"));
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("\nhello world.\nhello xml."));
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16("</token1>"));
CPPUNIT_ASSERT(tokenizer.isEof());
result = tokenizer.getToken();
CPPUNIT_ASSERT_MESSAGE(Transcoder::UTF16toUTF8(result),
result == Transcoder::UTF8toUTF16(""));
CPPUNIT_ASSERT(tokenizer.isEof());
}
示例5: split
static inline void split(_OutputIter iter,
const std::basic_string<_CharT, _Traits, _Alloc>& s,
int nsplits = -1) {
std::locale loc;
typedef std::basic_string<_CharT, _Traits, _Alloc> str_t;
int x = 0, rx = 0;
int y = (int)s.size() - 1;
while (std::isspace(s[x], loc))
x++;
rx = x;
while (y >= 0 && std::isspace(s[y], loc))
y--;
y++;
while (x < y) {
if (std::isspace(s[x], loc)) {
*iter++ = str_t(s, rx, x - rx);
while (x < y && std::isspace(s[x], loc))
x++;
rx = x;
if (!--nsplits) {
*iter++ = str_t(s, rx);
return;
}
} else {
x++;
}
}
if (rx != y) {
*iter++ = str_t(s, rx, y - rx);
}
}
示例6: 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;
}
示例7: benchmark1
Ret benchmark1(const std::basic_string<C>& str, const std::basic_string<C>& key, F f)
{
const int N = 1;
int val = 0;
f.set(str, key);
Xbyak::util::Clock clk;
for (int i = 0; i < N; i++) {
typename F::type p = f.begin();
typename F::type end = f.end();
for (;;) {
clk.begin();
typename F::type q = f.find(p);
clk.end();
if (q == end) break;
val += (int)(q - p);
p = q + 1;
}
}
if (val == 0) val = (int)(str.size()) * N;
Ret ret;
ret.val = val;
ret.clk = clk.getClock() / (double)val;
return ret;
}
示例8: testbuf
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
示例9: split
void split(charT pat,
const std::basic_string<charT, traits, Alloc>& s, Iter out) {
unsigned int pos = 0;
for (unsigned int i = 0; i < s.size(); ++i) {
if (s[i] == pat) {
if (i - pos > 0) {
*(out++) =
std::basic_string<charT, traits, Alloc>(s, pos, i - pos);
}
pos = i + 1;
}
}
*(out++) =
std::basic_string<charT, traits, Alloc>(s, pos, s.size() - pos);
} // split
示例10:
inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>
operator + (const sub_match<RandomAccessIterator>& m,
const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
{
std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result;
result.reserve(s.size() + m.length() + 1);
return result.append(m.first, m.second).append(s);
}
示例11: CreateGlobalData
HGLOBAL CreateGlobalData(const std::basic_string<charT>& str)
{
HGLOBAL data = ::GlobalAlloc(GMEM_MOVEABLE, ((str.size() + 1) * sizeof(charT)));
if (data)
{
charT* raw_data = static_cast<charT*>(::GlobalLock(data));
if (!raw_data)
{
::GlobalUnlock(data);
return nullptr;
}
memcpy(raw_data, str.data(), str.size() * sizeof(charT));
raw_data[str.size()] = '\0';
::GlobalUnlock(data);
}
return data;
}
示例12:
inline std::string u16tos(const std::basic_string<MIE_CHAR16>& str)
{
std::string ret;
for (size_t i = 0; i < str.size(); i++) {
ret += (char)str[i];
}
return ret;
}
示例13: matches
static bool matches(
std::basic_string< CharT, StringTraitsT, AllocatorT > const& str,
boost::basic_regex< CharT, ReTraitsT > const& expr,
boost::regex_constants::match_flag_type flags = boost::regex_constants::match_default)
{
const CharT* p = str.c_str();
return boost::regex_match(p, p + str.size(), expr, flags);
}
示例14: main
int main()
{
std::locale l = std::locale::classic();
const F& f = std::use_facet<F>(l);
{
const std::basic_string<F::intern_type> from(L"some text");
std::vector<char> to(from.size()+1);
std::mbstate_t mbs = {};
const F::intern_type* from_next = 0;
char* to_next = 0;
F::result r = f.out(mbs, from.data(), from.data() + from.size(), from_next,
to.data(), to.data() + to.size(), to_next);
assert(r == F::ok);
assert(static_cast<std::size_t>(from_next - from.data()) == from.size());
assert(static_cast<std::size_t>(to_next - to.data()) == from.size());
assert(to.data() == std::string("some text"));
}
{
std::basic_string<F::intern_type> from(L"some text");
from[4] = '\0';
std::vector<char> to(from.size()+1);
std::mbstate_t mbs = {};
const F::intern_type* from_next = 0;
char* to_next = 0;
F::result r = f.out(mbs, from.data(), from.data() + from.size(), from_next,
to.data(), to.data() + to.size(), to_next);
assert(r == F::ok);
assert(static_cast<std::size_t>(from_next - from.data()) == from.size());
assert(static_cast<std::size_t>(to_next - to.data()) == from.size());
assert(memcmp(to.data(), "some\0text", from.size()) == 0);
}
{
std::basic_string<F::intern_type> from(L"some text");
std::vector<char> to(from.size()-1);
std::mbstate_t mbs = {};
const F::intern_type* from_next = 0;
char* to_next = 0;
F::result r = f.out(mbs, from.data(), from.data() + from.size(), from_next,
to.data(), to.data() + to.size()-1, to_next);
assert(r == F::partial);
assert(static_cast<std::size_t>(from_next - from.data()) == to.size()-1);
assert(static_cast<std::size_t>(to_next - to.data()) == to.size()-1);
assert(to.data() == std::string("some te"));
}
}
示例15: cstr
cstr(const std::basic_string<char_type, CharTraits, Allocator>& s)
{
if (s.empty()) {
clear();
} else {
buf_ = s.c_str();
size_ = s.size();
}
}