1 /*! 2 * \file tfel-doc/src/Global.cxx 3 * \brief 4 * \author Thomas Helfer 5 * \brief 03 mai 2011 6 * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights 7 * reserved. 8 * This project is publicly released under either the GNU GPL Licence 9 * or the CECILL-A licence. A copy of thoses licences are delivered 10 * with the sources of TFEL. CEA or EDF may also distribute this 11 * project under specific licensing conditions. 12 */ 13 14 #include<iostream> 15 16 #include"TFEL/Utilities/Global.hxx" 17 #include"TFEL/Utilities/TerminalColors.hxx" 18 19 namespace tfel{ 20 21 namespace utilities{ 22 23 std::map<std::string,std::map<std::string,std::string> >& getTypeMap()24 getTypeMap() 25 { 26 using namespace std; 27 static map<string,map<string,string> > t; 28 return t; 29 } 30 31 std::map<std::string,std::string>& getTypeMap(const std::string & l)32 getTypeMap(const std::string& l) 33 { 34 using namespace std; 35 static map<string,map<string,string> > t; 36 return t[l]; 37 } 38 39 std::map<std::string,std::map<std::string,std::string> >& getCategoriesMap()40 getCategoriesMap() 41 { 42 using namespace std; 43 static map<string,map<string,string> > c; 44 return c; 45 } 46 47 std::map<std::string,std::string>& getCategoriesMap(const std::string & l)48 getCategoriesMap(const std::string& l) 49 { 50 using namespace std; 51 return getCategoriesMap()[l]; 52 } 53 54 std::map<std::string,std::map<std::string,std::string> >& getKeysMap()55 getKeysMap() 56 { 57 using namespace std; 58 static map<string,map<string,string> > k; 59 return k; 60 } 61 62 std::map<std::string,std::string>& getKeysMap(const std::string & l)63 getKeysMap(const std::string& l) 64 { 65 using namespace std; 66 return getKeysMap()[l]; 67 } 68 69 std::map<std::string,std::map<std::string,std::string> >& getTranslationsMap()70 getTranslationsMap() 71 { 72 using namespace std; 73 static map<string,map<string,string> > k; 74 return k; 75 } 76 77 std::map<std::string,std::string>& getTranslationsMap(const std::string & l)78 getTranslationsMap(const std::string& l) 79 { 80 using namespace std; 81 return getTranslationsMap()[l]; 82 } 83 84 std::string getTranslation(const std::string & s,const std::string & l)85 getTranslation(const std::string& s, 86 const std::string& l) 87 { 88 using namespace std; 89 using namespace tfel::utilities; 90 const auto& translations = getTranslationsMap(l); 91 map<string,string>::const_iterator pk; 92 if(l=="english"){ 93 return s; 94 } 95 pk = translations.find(s); 96 if(pk!=translations.end()){ 97 return pk->second; 98 } 99 cerr << TerminalColors::Red; 100 cerr << "getTranslation : no translation found for '" << s 101 << "' in language '"+l+"', using default" << endl; 102 cerr << TerminalColors::Reset; 103 return s; 104 } 105 106 std::string getCategory(const std::string & s,const std::string & l)107 getCategory(const std::string& s, 108 const std::string& l) 109 { 110 using namespace std; 111 using namespace tfel::utilities; 112 const auto& categories = getCategoriesMap(l); 113 map<string,string>::const_iterator pk; 114 pk = categories.find(s); 115 if(pk!=categories.end()){ 116 return pk->second; 117 } 118 cerr << TerminalColors::Red; 119 cerr << "getCategory : no category found for '" << s 120 << "' in language '"+l+"', using default" << endl; 121 cerr << TerminalColors::Reset; 122 return s; 123 } 124 125 std::string getKeyValue(const std::string & s,const std::string & l)126 getKeyValue(const std::string& s, 127 const std::string& l) 128 { 129 using namespace std; 130 using namespace tfel::utilities; 131 const auto& keys = getKeysMap(l); 132 map<string,string>::const_iterator pk; 133 if(s.empty()){ 134 return s; 135 } 136 if(s[0]=='!'){ 137 return s.substr(1); 138 } 139 pk = keys.find(s); 140 if(pk!=keys.end()){ 141 return pk->second; 142 } 143 cerr << TerminalColors::Red; 144 cerr << "getKeyValue : no translation found for key '" << s 145 << "' in language '"+l+"', using default" << endl; 146 cerr << TerminalColors::Reset; 147 return s; 148 } 149 150 std::string capitalize(const std::string & s)151 capitalize(const std::string& s) 152 { 153 std::string r{s}; 154 if(r[0]=='�'){ 155 r[0]='�'; 156 } else if(r[0]=='�'){ 157 r[0]='�'; 158 } else if(r[0]=='�'){ 159 r[0]='�'; 160 } else if(r[0]=='�'){ 161 r[0]='�'; 162 } else if(r[0]=='�'){ 163 r[0]='�'; 164 } else { 165 r[0] = static_cast<char>(toupper(r[0])); 166 } 167 return r; 168 } // end of capitalize 169 170 } // end of namespace utilities 171 172 } // end of namespace tfel 173