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