test/css_example.cpp

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

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