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