本文整理汇总了C++中std::basic_string::length方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::length方法的具体用法?C++ basic_string::length怎么用?C++ basic_string::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
const std::basic_string<CharType> in(
const std::basic_string<Byte>& external_str,
const std::codecvt<CharType, Byte, mbstate_t>& codecvt)
{
typedef std::basic_string<CharType> wstring;
typedef std::basic_string<Byte> string;
typedef std::codecvt<CharType, Byte, mbstate_t> codecvt_type;
typename string::size_type external_str_size = external_str.length();
const Byte* first_external = external_str.data();
const Byte* last_external = first_external + external_str_size;
const Byte* next_external = last_external;
wstring internal_str;
typename codecvt_type::state_type state(0);
typename wstring::size_type out_buf_size =
static_cast<typename wstring::size_type>(
codecvt.length(state, first_external, last_external,
internal_str.max_size()));
#if defined(MA_USE_CXX11_STDLIB_MEMORY)
detail::unique_ptr<CharType[]> out_buf(new CharType[out_buf_size]);
#else
detail::scoped_array<CharType> out_buf(new CharType[out_buf_size]);
#endif
CharType* first_internal = out_buf.get();
CharType* last_internal = first_internal + out_buf_size;
CharType* next_internal = first_internal;
typename codecvt_type::result r = codecvt.in(state,
first_external, last_external, next_external,
first_internal, last_internal, next_internal);
if (codecvt_type::ok != r)
{
boost::throw_exception(bad_conversion());
}
else if (codecvt_type::noconv == r)
{
internal_str.assign(reinterpret_cast<const CharType*>(first_external),
reinterpret_cast<const CharType*>(last_external));
}
else
{
internal_str.assign(first_internal, last_internal);
}
return internal_str;
}
示例2: if
const std::basic_string<Byte> out(
const std::basic_string<CharType>& internal_str,
const std::codecvt<CharType, Byte, mbstate_t>& codecvt)
{
typedef std::basic_string<CharType> wstring;
typedef std::basic_string<Byte> string;
typedef std::codecvt<CharType, Byte, mbstate_t> codecvt_type;
string external_str;
typename wstring::size_type internal_str_size = internal_str.length();
typename wstring::size_type out_buf_size =
static_cast<typename wstring::size_type>(codecvt.max_length()) *
internal_str_size;
#if defined(MA_USE_CXX11_STDLIB_MEMORY)
std::unique_ptr<Byte[]> out_buf(new Byte[out_buf_size]);
#else
boost::scoped_array<Byte> out_buf(new Byte[out_buf_size]);
#endif
const CharType* first_internal = internal_str.data();
const CharType* last_internal = first_internal + internal_str_size;
const CharType* next_internal = first_internal;
Byte* first_external = out_buf.get();
Byte* last_external = first_external + out_buf_size;
Byte* next_external = first_external;
typename codecvt_type::state_type state(0);
typename codecvt_type::result r = codecvt.out(state,
first_internal, last_internal, next_internal,
first_external, last_external, next_external);
if (codecvt_type::ok == r)
{
external_str.assign(first_external, next_external);
}
else if (codecvt_type::noconv == r)
{
external_str.assign(reinterpret_cast<const Byte*>(first_internal),
reinterpret_cast<const Byte*>(last_internal));
}
else
{
boost::throw_exception(bad_conversion());
}
return external_str;
}
示例3: strip
template<typename char_t> std::basic_string<char_t> strip(const std::basic_string<char_t>& what, const std::basic_string<char_t> of_what)
{
std::basic_string<char_t> result;
for ( size_t i=0; i<what.length(); i++ )
{
if ( of_what.find(what[i]) == std::basic_string<char_t>::npos )
{
result.push_back(what[i]);
}
}
return result;
}
示例4: Allocator
explicit
dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s,
typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0,
typename std::basic_string<CharT, Traits, Alloc>::size_type n
= (std::basic_string<CharT, Traits, Alloc>::npos),
const Allocator& alloc = Allocator())
: detail::dynamic_bitset_base<Block, Allocator>
(std::min(n, s.size() - pos), alloc)
#endif
{
// Locate sub string
assert(pos <= s.length());
from_string(s, pos, std::min(n, s.size() - pos));
}
示例5: sizeof
inline
typename quan::where_<
quan::meta::bool_< (sizeof(CharTo) < sizeof(CharFrom))>,
std::basic_string<CharTo>
>::type
convert(std::basic_string<CharFrom> const & in)
{
typedef std::ctype<CharFrom> ct;
auto & facet = std::use_facet<ct>(std::locale());
std::basic_string<CharTo> result;
for ( auto i = 0U ; i < in.length();++i){
result += facet.narrow(in[i],'#');
}
return result;
}
示例6: replace
int replace(std::basic_string<Ch, Tr, Alloc>& target,
const std::basic_string<Ch, Tr, Alloc>& oldStr,
const std::basic_string<Ch, Tr, Alloc>& newStr)
{
int replaceCount = 0;
typedef std::basic_string<Ch, Tr, Alloc> str_type;
str_type::size_type searchPos = 0;
str_type::size_type findPos = 0;
str_type result;
for(;;)
{
findPos = StringUtil::find(target, oldStr, searchPos);
if(str_type::npos == findPos)
{
break;
}
result += target.substr(searchPos, (findPos - searchPos));
result += newStr;
searchPos = findPos + oldStr.length();
++replaceCount;
}
if(searchPos < target.length())
{
result += target.substr(searchPos);
}
target = result;
return replaceCount;
}
示例7: serializeString
inline void serializeString(SF::Archive & ar, std::basic_string<C,T,A> & s)
{
if (ar.isRead())
{
boost::uint32_t count = 0;
ar & count;
SF::IStream &is = *ar.getIstream();
s.resize(0);
std::size_t minSerializedLength = sizeof(C);
if (ar.verifyAgainstArchiveSize(count*minSerializedLength))
{
if (count > s.capacity())
{
s.reserve(count);
}
}
boost::uint32_t charsRemaining = count;
const boost::uint32_t BufferSize = 512;
C buffer[BufferSize];
while (charsRemaining)
{
boost::uint32_t charsToRead = RCF_MIN(BufferSize, charsRemaining);
boost::uint32_t bytesToRead = charsToRead*sizeof(C);
RCF_VERIFY(
is.read( (char *) buffer, bytesToRead) == bytesToRead,
RCF::Exception(RCF::_SfError_ReadFailure()))
(bytesToRead)(BufferSize)(count);
s.append(buffer, charsToRead);
charsRemaining -= charsToRead;
}
}
else if (ar.isWrite())
{
boost::uint32_t count = static_cast<boost::uint32_t >(s.length());
ar & count;
ar.getOstream()->writeRaw(
(char *) s.c_str(),
count*sizeof(C));
}
}
示例8: serialize
inline void serialize(SF::Archive &ar, std::basic_string<C,T,A> &t, const unsigned int)
{
if (ar.isRead())
{
C *pch = NULL;
UInt32 length = 0;
ar & SF::Archive::Flag( SF::Archive::NO_BEGIN_END ) & dynamicArray(pch, length);
t.assign(pch, length);
delete [] pch;
}
else if (ar.isWrite())
{
C *pch = const_cast<C *>(t.c_str());
UInt32 length = static_cast<UInt32>(t.length());
ar & SF::Archive::Flag( SF::Archive::NO_BEGIN_END ) & dynamicArray(pch, length);
}
}
示例9: Symbol
/** Convert a string to a valid symbol.
*
* This will make a best effort at turning `str` into a complete, valid
* Symbol, and will always return one.
*/
static inline Symbol symbolify(const std::basic_string<char>& in) {
if (in.empty()) {
return Symbol("_");
}
std::basic_string<char> out(in);
for (size_t i = 0; i < in.length(); ++i) {
if (!is_valid_char(out[i])) {
out[i] = '_';
}
}
if (is_valid_start_char(out[0])) {
return Symbol(out);
} else {
return Symbol(std::string("_") + out);
}
}
示例10: split
template<typename char_t, typename func> void split(const std::basic_string<char_t>& what, char_t on, func f)
{
size_t left = 0, right = 0;
auto insert_fn = [&what, &f](size_t left, size_t right) -> void
{
if ( left < right ) f(trim(what.substr(left, right-left)));
};
for ( ; right<what.length(); right++ )
{
if ( what[right] == on )
{
insert_fn(left, right);
left = right+1;
}
}
insert_fn(left, right);
}
示例11: StringTrimT
void StringTrimT(std::basic_string<CharType> &output)
{
if (output.empty())
return;
size_t bound1 = 0;
size_t bound2 = output.length();
const CharType *src = output.data();
for (; bound2 > 0; bound2--)
if (NOT_SPACE(src[bound2-1]))
break;
for (; bound1 < bound2; bound1++)
if (NOT_SPACE(src[bound1]))
break;
if (bound1 < bound2) {
memmove((void *)src,
src + bound1,
sizeof(CharType) * (bound2 - bound1));
}
output.resize(bound2 - bound1);
}
示例12: operator
uuid operator()(std::basic_string<ch, char_traits, alloc> const& name) const {
HashAlgo hash;
hash.process_bytes(namespace_uuid.begin(), namespace_uuid.size());
process_characters(hash, name.c_str(), name.length());
return hash_to_uuid(hash);
}
示例13: parse
void parse(const std::basic_string<wchar_t>& data)
{
for (int index = 0; index < data.length(); ++index)
{
wchar_t currentByte = data[index];
if (currentByte < 32)
currentCommandString_ << L"<" << static_cast<int>(currentByte) << L">";
else
currentCommandString_ << currentByte;
if (currentByte != 0)
{
switch (currentState_)
{
case ExpectingNewCommand:
if (currentByte == 1)
currentState_ = ExpectingCommand;
//just throw anything else away
break;
case ExpectingCommand:
if (currentByte == 2)
currentState_ = ExpectingParameter;
else
command_name_ += currentByte;
break;
case ExpectingParameter:
//allocate new parameter
if (parameters_.size() == 0 || currentByte == 2)
parameters_.push_back(std::wstring());
//add the character to end end of the last parameter
if (currentByte != 2)
{
//add the character to end end of the last parameter
if (currentByte == L'<')
parameters_.back() += L"<";
else if (currentByte == L'>')
parameters_.back() += L">";
else if (currentByte == L'\"')
parameters_.back() += L""";
else
parameters_.back() += currentByte;
}
break;
}
}
else
{
std::transform(
command_name_.begin(), command_name_.end(),
command_name_.begin(),
toupper);
try
{
if (!command_processor_.handle(command_name_, parameters_))
CASPAR_LOG(error) << "CLK: Unknown command: " << command_name_;
else
CASPAR_LOG(debug) << L"CLK: Executed valid command: "
<< currentCommandString_.str();
}
catch (...)
{
CASPAR_LOG_CURRENT_EXCEPTION();
CASPAR_LOG(error) << "CLK: Failed to interpret command: "
<< currentCommandString_.str();
}
reset();
}
}
}
示例14: startsWith
template<class Ch> inline bool startsWith(const std::basic_string<Ch>& text, const Ch* prefix, ulong_t startOffset = 0)
{return startsWith(text.data() + startOffset, text.length() - startOffset, prefix, -1);}
示例15: numericValue
template<class Ch> inline status_t numericValue(const std::basic_string<Ch>& text, long& result, uint_t base=10)
{return numericValue(text.data(), text.data() + text.length(), result, base);}