1*cdf0e10cSrcweir #include <string> 2*cdf0e10cSrcweir #include <hash_map> 3*cdf0e10cSrcweir #include <unicode/regex.h> 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir using namespace std; 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir namespace transex3 8*cdf0e10cSrcweir { 9*cdf0e10cSrcweir 10*cdf0e10cSrcweir struct eqstr 11*cdf0e10cSrcweir { 12*cdf0e10cSrcweir bool operator()( const string s1 , const string s2) const 13*cdf0e10cSrcweir { 14*cdf0e10cSrcweir return s1.compare( s2 ) == 0; 15*cdf0e10cSrcweir } 16*cdf0e10cSrcweir }; 17*cdf0e10cSrcweir 18*cdf0e10cSrcweir typedef std::hash_map< string , string > stringmap; 19*cdf0e10cSrcweir typedef std::hash_map< string, stringmap* > INImap; 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir class INIreader 22*cdf0e10cSrcweir { 23*cdf0e10cSrcweir private: 24*cdf0e10cSrcweir UErrorCode section_status; 25*cdf0e10cSrcweir UErrorCode parameter_status; 26*cdf0e10cSrcweir RegexMatcher* section_match; 27*cdf0e10cSrcweir RegexMatcher* parameter_match; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir public: 30*cdf0e10cSrcweir INIreader(): section_status ( U_ZERO_ERROR ) , 31*cdf0e10cSrcweir parameter_status ( U_ZERO_ERROR ) 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir section_match = new RegexMatcher ( "^\\s*\\[([a-zA-Z0-9]*)\\].*" , 0 , section_status ); 34*cdf0e10cSrcweir parameter_match = new RegexMatcher ( "^\\s*([a-zA-Z0-9]*)\\s*=\\s*([a-zA-Z0-9 ]*).*" , 0 , parameter_status ) ; 35*cdf0e10cSrcweir } 36*cdf0e10cSrcweir ~INIreader() 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir delete section_match; 39*cdf0e10cSrcweir delete parameter_match; 40*cdf0e10cSrcweir } 41*cdf0e10cSrcweir // open "filename", fill hash_map with sections / paramaters 42*cdf0e10cSrcweir bool read( INImap& myMap , string& filename ); 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir private: 45*cdf0e10cSrcweir bool is_section( string& line , string& section_str ); 46*cdf0e10cSrcweir bool is_parameter( string& line , string& parameter_key , string& parameter_value ); 47*cdf0e10cSrcweir inline void check_status( UErrorCode status ); 48*cdf0e10cSrcweir inline void toStlString ( const UnicodeString& str, string& stl_str ); 49*cdf0e10cSrcweir inline void trim( string& str ); 50*cdf0e10cSrcweir }; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir } 53