xref: /aoo41x/main/l10ntools/inc/inireader.hxx (revision 983d4c8a)
1*983d4c8aSAndrew Rist /**************************************************************
2*983d4c8aSAndrew Rist  *
3*983d4c8aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*983d4c8aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*983d4c8aSAndrew Rist  * distributed with this work for additional information
6*983d4c8aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*983d4c8aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*983d4c8aSAndrew Rist  * "License"); you may not use this file except in compliance
9*983d4c8aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*983d4c8aSAndrew Rist  *
11*983d4c8aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*983d4c8aSAndrew Rist  *
13*983d4c8aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*983d4c8aSAndrew Rist  * software distributed under the License is distributed on an
15*983d4c8aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*983d4c8aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*983d4c8aSAndrew Rist  * specific language governing permissions and limitations
18*983d4c8aSAndrew Rist  * under the License.
19*983d4c8aSAndrew Rist  *
20*983d4c8aSAndrew Rist  *************************************************************/
21*983d4c8aSAndrew Rist 
22cdf0e10cSrcweir #include <string>
23cdf0e10cSrcweir #include <hash_map>
24cdf0e10cSrcweir #include <unicode/regex.h>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir using namespace std;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir namespace transex3
29cdf0e10cSrcweir {
30cdf0e10cSrcweir 
31cdf0e10cSrcweir struct eqstr
32cdf0e10cSrcweir {
operator ()transex3::eqstr33cdf0e10cSrcweir     bool operator()( const string s1 , const string s2) const
34cdf0e10cSrcweir     {
35cdf0e10cSrcweir         return s1.compare( s2 ) == 0;
36cdf0e10cSrcweir     }
37cdf0e10cSrcweir };
38cdf0e10cSrcweir 
39cdf0e10cSrcweir typedef std::hash_map< string , string > stringmap;
40cdf0e10cSrcweir typedef std::hash_map< string, stringmap* > INImap;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class INIreader
43cdf0e10cSrcweir {
44cdf0e10cSrcweir     private:
45cdf0e10cSrcweir         UErrorCode section_status;
46cdf0e10cSrcweir         UErrorCode parameter_status;
47cdf0e10cSrcweir         RegexMatcher* section_match;
48cdf0e10cSrcweir         RegexMatcher* parameter_match;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     public:
INIreader()51cdf0e10cSrcweir         INIreader(): section_status   ( U_ZERO_ERROR ) ,
52cdf0e10cSrcweir                      parameter_status ( U_ZERO_ERROR )
53cdf0e10cSrcweir         {
54cdf0e10cSrcweir                      section_match   = new RegexMatcher   ( "^\\s*\\[([a-zA-Z0-9]*)\\].*" , 0 , section_status );
55cdf0e10cSrcweir                      parameter_match = new RegexMatcher   ( "^\\s*([a-zA-Z0-9]*)\\s*=\\s*([a-zA-Z0-9 ]*).*" , 0 , parameter_status ) ;
56cdf0e10cSrcweir         }
~INIreader()57cdf0e10cSrcweir         ~INIreader()
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             delete section_match;
60cdf0e10cSrcweir             delete parameter_match;
61cdf0e10cSrcweir         }
62cdf0e10cSrcweir         // open "filename", fill hash_map with sections / paramaters
63cdf0e10cSrcweir         bool read( INImap& myMap , string& filename );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     private:
66cdf0e10cSrcweir         bool is_section( string& line , string& section_str );
67cdf0e10cSrcweir         bool is_parameter( string& line , string& parameter_key , string& parameter_value );
68cdf0e10cSrcweir         inline void check_status( UErrorCode status );
69cdf0e10cSrcweir         inline void toStlString ( const UnicodeString& str, string& stl_str );
70cdf0e10cSrcweir         inline void trim( string& str );
71cdf0e10cSrcweir };
72cdf0e10cSrcweir 
73cdf0e10cSrcweir }
74