#include <proton/string.hpp>
using namespace std;
using namespace proton;
void str_eg()
{
cout << ">>> str examples :" << endl;
a="abc "+a;
cout << "split:" << s << endl;
cout << "join again:"<< b << endl;
cout << "upper:"<<A<< endl;
cout <<
"lower:"<<A.
lower()<< endl;
cout <<
"There is " << A.
count(
'A') <<
" 'A' in A." << endl;
cout << "strip of '" << c << "' is " ;
cout << c.
strip() << endl;
cout <<
str(
"%% to show a number: %d\n") % 15;
cout <<
str(
"%% to show a float: %f\n") % 15.1;
cout <<
"%% to show a str: %s\n" %
str(
"abc");
cout <<
"%% to show a tuple: (%d,%d)\n" %
_t(1,2);
int k=10;
cout <<
"%% to show a forwarded tuple: (%s,%f,%X)" %
_f(c,1.1,k) << endl;
try{
cout <<
str(
"%d %d %o %% %x %X\n") % 1;
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
cout <<
"%d %d %o %% %x %X\n" %
_f(1,2,3);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
cout <<
"%d %d" %
_f(1,2,3);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
cout <<
"%d %d" %
_f(
"abc",2);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
cout <<
"%t %d" %
_f(
"abc",2);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
}
void wstr_eg()
{
wcout << L">>> wstr examples :" << endl;
a=L"abc "+a;
wcout << L"split:" << s << endl;
wcout << L"join again:"<< b << endl;
wcout << L"upper:"<<A<< endl;
wcout << L
"lower:"<<A.
lower()<< endl;
wcout << L
"There is " << A.
count(L
'A') << L
" 'A' in A." << endl;
wcout << L"strip of '" << c << L"' is " ;
wcout << c.
strip() << endl;
cout <<
str(
"%% to show a number: %d\n") % 15;
cout <<
str(
"%% to show a float: %f\n") % 15.1;
cout <<
"%% to show a str: %s\n" %
str(
"abc");
cout <<
"%% to show a tuple: (%d,%d)\n" %
_t(1,2);
int k=10;
wcout << L
"%% to show a forwarded tuple: (%s,%f,%X)" %
_f(c,1.1,k) << endl;
try{
wcout <<
wstr(L
"%d %d %o %% %x %X\n") % 1;
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
wcout << L
"%d %d %o %% %x %X\n" %
_f(1,2,3);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
wcout << L
"%d %d" %
_f(1,2,3);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
wcout << L
"%d %d" %
_f(L
"abc",2);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
try{
wcout << L
"%t %d" %
_f(L
"abc",2);
}
catch(const std::invalid_argument& e)
{
cout << e.what() << endl;
}
}
int main()
{
str_eg();
wstr_eg();
return 0;
}