test/ss_example.cpp

00001 
00002 /*expected  output
00003     (456789) [123]  2006-10-01    ABCDEF   
00004 (456789) [123]  2006-10-01    ABCDEF
00005 (456789) [123]  2006-10-01    ABCDEF1.23456  
00006 (456789) [123]  2006-10-01  2006-Jul-01  ABCDEF1.23456  
00007 __[456789]__ [123]  2006-10-01  2006-Jul-01  ABCDEF1.23456  
00008 0  [456789]__
00009 1  [123]
00010 2  2006-10-01
00011 3  2006-Jul-01
00012 4  ABCDEF1.23456
00013 hello world 
00014 */
00015 #include "super_string/super_string.hpp"
00016 #include "boost/date_time/gregorian/gregorian.hpp"
00017 #include <iostream>
00018  
00019 using std::string;
00020 using std::cout;
00021 using std::wcout;
00022 using std::endl;
00023 using namespace boost::gregorian;
00024 
00025 
00026 int
00027 main()
00028 {
00029 
00030   super_string s("    (456789) [123]  2006-10-01    abcdef   ");
00031   s.to_upper();
00032   cout << s << endl;
00033   
00034   s.trim();  //lop off the whitespace on both sides
00035   cout << s << endl;
00036   
00037   double dbl = 1.23456;
00038   s.append(dbl);  //append any streamable type 
00039   s+= "  ";
00040   cout << s << endl;
00041   
00042   date d(2006, Jul, 1);
00043   s.insert_at(28, d);  //insert any streamable type
00044   cout << s << endl;
00045   
00046   //find the yyyy-mm-dd date format
00047   if (s.contains_regex("\\d{4}-\\d{2}-\\d{2}")) {
00048     //replace parens around digits with square brackets [the digits]
00049     s.replace_all_regex("\\(([0-9]+)\\)", "__[$1]__");
00050     cout << s << endl;
00051     
00052     
00053     //split the string on white space to process parts
00054     super_string::string_vector out_vec;
00055     unsigned int count = s.split_regex("\\s+", out_vec);
00056     if (count) {
00057       for(int i=0; i < out_vec.size(); ++i) {
00058         out_vec[i].replace_first("__","");  //get rid of first __ in string
00059         cout << i << "  " << out_vec[i] << endl;
00060       }
00061     }
00062   }
00063   
00064   //wide strings too...
00065   wsuper_string ws(L"   hello world ");
00066   ws.trim_left();
00067   wcout << ws << endl;
00068   
00069   return 0;
00070 
00071 }

Generated on Sun Jul 9 15:43:03 2006 for SuperString by  doxygen 1.4.6