本文整理汇总了C++中std::basic_string类的典型用法代码示例。如果您正苦于以下问题:C++ basic_string类的具体用法?C++ basic_string怎么用?C++ basic_string使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了basic_string类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
}
示例2: test_ok
void test_ok(std::string file,std::locale const &l,std::basic_string<Char> cmp=std::basic_string<Char>())
{
if(cmp.empty())
cmp=to<Char>(file);
std::ofstream test("testi.txt");
test << file;
test.close();
typedef std::basic_fstream<Char> stream_type;
stream_type f1("testi.txt",stream_type::in);
f1.imbue(l);
TEST(read_file<Char>(f1) == cmp);
f1.close();
stream_type f2("testo.txt",stream_type::out);
f2.imbue(l);
f2 << cmp;
f2.close();
std::ifstream testo("testo.txt");
TEST(read_file<char>(testo) == file);
}
示例3: test_pos
void test_pos(std::string source,std::basic_string<Char> target,std::string encoding)
{
using namespace boost::locale::conv;
boost::locale::generator g;
std::locale l= encoding == "ISO8859-8" ? g("he_IL."+encoding) : g("en_US."+encoding);
TEST(to_utf<Char>(source,encoding)==target);
TEST(to_utf<Char>(source.c_str(),encoding)==target);
TEST(to_utf<Char>(source.c_str(),source.c_str()+source.size(),encoding)==target);
TEST(to_utf<Char>(source,l)==target);
TEST(to_utf<Char>(source.c_str(),l)==target);
TEST(to_utf<Char>(source.c_str(),source.c_str()+source.size(),l)==target);
TEST(from_utf<Char>(target,encoding)==source);
TEST(from_utf<Char>(target.c_str(),encoding)==source);
TEST(from_utf<Char>(target.c_str(),target.c_str()+target.size(),encoding)==source);
TEST(from_utf<Char>(target,l)==source);
TEST(from_utf<Char>(target.c_str(),l)==source);
TEST(from_utf<Char>(target.c_str(),target.c_str()+target.size(),l)==source);
}
示例4: name
void name(const std::basic_string<Char>& name, const basic_parsing_context<Char>& context)
{
do_name(name.c_str(), name.length(), context);
}
示例5: unescape_wide_string
void unescape_wide_string(
const std::string &src,
std::basic_string<unsigned int> &dest)
{
dest.reserve(src.size()); // about that long, but may be shorter
for(unsigned i=0; i<src.size(); i++)
{
unsigned int ch=(unsigned char)src[i];
if(ch=='\\') // escape?
{
i++;
assert(i<src.size()); // backslash can't be last character
ch=(unsigned char)src[i];
switch(ch)
{
case '\\': dest.push_back(ch); break;
case 'n': dest.push_back('\n'); break; /* NL (0x0a) */
case 't': dest.push_back('\t'); break; /* HT (0x09) */
case 'v': dest.push_back('\v'); break; /* VT (0x0b) */
case 'b': dest.push_back('\b'); break; /* BS (0x08) */
case 'r': dest.push_back('\r'); break; /* CR (0x0d) */
case 'f': dest.push_back('\f'); break; /* FF (0x0c) */
case 'a': dest.push_back('\a'); break; /* BEL (0x07) */
case '"': dest.push_back('"'); break;
case '\'': dest.push_back('\''); break;
case 'u': // universal character
case 'U': // universal character
i++;
{
std::string hex;
unsigned count=(ch=='u')?4:8;
hex.reserve(count);
for(; count!=0 && i<src.size(); i++, count--)
hex+=src[i];
// go back
i--;
unsigned int result;
sscanf(hex.c_str(), "%x", &result);
ch=result;
}
dest.push_back(ch);
break;
case 'x': // hex
i++;
{
std::string hex;
while(i<src.size() && isxdigit(src[i]))
{
hex+=src[i];
i++;
}
// go back
i--;
unsigned int result;
sscanf(hex.c_str(), "%x", &result);
ch=result;
}
dest.push_back(ch);
break;
default:
if(isdigit(ch)) // octal
{
std::string octal;
while(i<src.size() && isdigit(src[i]))
{
octal+=src[i];
i++;
}
// go back
i--;
unsigned int result;
sscanf(octal.c_str(), "%o", &result);
ch=result;
dest.push_back(ch);
}
else
{
// Unknown escape sequence.
// Both GCC and CL turn \% into %.
dest.push_back(ch);
}
//.........这里部分代码省略.........
示例6: make_set_state
set_state_functor<Char>
make_set_state(std::basic_string<Char, Traits, Alloc> const& new_state)
{
return set_state_functor<Char>(new_state.c_str());
}
示例7: str_from_delimited_time_duration
inline
time_duration
str_from_delimited_time_duration(const std::basic_string<char_type>& s)
{
unsigned short min=0, sec =0;
int hour =0;
bool is_neg = (s.at(0) == '-');
boost::int64_t fs=0;
int pos = 0;
typedef typename std::basic_string<char_type>::traits_type traits_type;
typedef boost::char_separator<char_type, traits_type> char_separator_type;
typedef boost::tokenizer<char_separator_type,
typename std::basic_string<char_type>::const_iterator,
std::basic_string<char_type> > tokenizer;
typedef typename boost::tokenizer<char_separator_type,
typename std::basic_string<char_type>::const_iterator,
typename std::basic_string<char_type> >::iterator tokenizer_iterator;
char_type sep_chars[5] = {'-',':',',','.'};
char_separator_type sep(sep_chars);
tokenizer tok(s,sep);
for(tokenizer_iterator beg=tok.begin(); beg!=tok.end();++beg){
switch(pos) {
case 0: {
hour = boost::lexical_cast<int>(*beg);
break;
}
case 1: {
min = boost::lexical_cast<unsigned short>(*beg);
break;
}
case 2: {
sec = boost::lexical_cast<unsigned short>(*beg);
break;
};
case 3: {
int digits = static_cast<int>(beg->length());
//Works around a bug in MSVC 6 library that does not support
//operator>> thus meaning lexical_cast will fail to compile.
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
// msvc wouldn't compile 'time_duration::num_fractional_digits()'
// (required template argument list) as a workaround a temp
// time_duration object was used
time_duration td(hour,min,sec,fs);
int precision = td.num_fractional_digits();
// _atoi64 is an MS specific function
if(digits >= precision) {
// drop excess digits
fs = _atoi64(beg->substr(0, precision).c_str());
}
else {
fs = _atoi64(beg->c_str());
}
#else
int precision = time_duration::num_fractional_digits();
if(digits >= precision) {
// drop excess digits
fs = boost::lexical_cast<boost::int64_t>(beg->substr(0, precision));
}
else {
fs = boost::lexical_cast<boost::int64_t>(*beg);
}
#endif
if(digits < precision){
// trailing zeros get dropped from the string,
// "1:01:01.1" would yield .000001 instead of .100000
// the power() compensates for the missing decimal places
fs *= power(10, precision - digits);
}
break;
}
default: break;
}//switch
pos++;
}
if(is_neg) {
return -time_duration(hour, min, sec, fs);
}
else {
return time_duration(hour, min, sec, fs);
}
}
示例8:
inline bool operator > (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) > 0; }
示例9: ends_with
template<typename char_t> bool ends_with(const std::basic_string<char_t>& what, const std::basic_string<char_t>& with)
{
return !what.empty() && (what.find(with) == what.length()-with.length());
}
示例10: test_from_neg
void test_from_neg(std::basic_string<Char> source,std::string target,std::string encoding)
{
using namespace boost::locale::conv;
boost::locale::generator g;
std::locale l=g("en_US."+encoding);
TEST(from_utf<Char>(source,encoding)==target);
TEST(from_utf<Char>(source.c_str(),encoding)==target);
TEST(from_utf<Char>(source.c_str(),source.c_str()+source.size(),encoding)==target);
TEST(from_utf<Char>(source,l)==target);
TEST(from_utf<Char>(source.c_str(),l)==target);
TEST(from_utf<Char>(source.c_str(),source.c_str()+source.size(),l)==target);
TESTF(from_utf<Char>(source,encoding,stop));
TESTF(from_utf<Char>(source.c_str(),encoding,stop));
TESTF(from_utf<Char>(source.c_str(),source.c_str()+source.size(),encoding,stop));
TESTF(from_utf<Char>(source,l,stop));
TESTF(from_utf<Char>(source.c_str(),l,stop));
TESTF(from_utf<Char>(source.c_str(),source.c_str()+source.size(),l,stop));
}
示例11: code_convert
inline void code_convert(std::basic_string< CharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale())
{
str2.append(str1.c_str(), str1.size());
}
示例12: 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();
}
}
}
示例13: 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);
}
示例14: operator
size_t operator()(const std::basic_string<char, Traits, Allocator>& __s) const
{
return __stl_hash_string(__s.c_str());
}
示例15: report
/* ----------------------------------------------------------------- */
int report(HWND owner, const std::basic_string<TCHAR>& message) {
return DialogBoxParam(GetModuleHandle(NULL), _T("IDD_REPORT"), owner, report_wndproc, (LPARAM)message.c_str());
}