| 167 | } |
| 168 | |
| 169 | bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, IConsole *pConsole) |
| 170 | { |
| 171 | // empty string means unload |
| 172 | if(pFilename[0] == 0) |
| 173 | { |
| 174 | m_vStrings.clear(); |
| 175 | m_StringsHeap.Reset(); |
| 176 | return true; |
| 177 | } |
| 178 | |
| 179 | CLineReader LineReader; |
| 180 | if(!LineReader.OpenFile(pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL))) |
| 181 | return false; |
| 182 | |
| 183 | log_info("localization", "loaded '%s'", pFilename); |
| 184 | m_vStrings.clear(); |
| 185 | m_StringsHeap.Reset(); |
| 186 | |
| 187 | char aContext[512]; |
| 188 | char aOrigin[512]; |
| 189 | int Line = 0; |
| 190 | while(const char *pLine = LineReader.Get()) |
| 191 | { |
| 192 | Line++; |
| 193 | if(!str_length(pLine)) |
| 194 | continue; |
| 195 | |
| 196 | if(pLine[0] == '#') // skip comments |
| 197 | continue; |
| 198 | |
| 199 | if(pLine[0] == '[') // context |
| 200 | { |
| 201 | size_t Len = str_length(pLine); |
| 202 | if(Len < 1 || pLine[Len - 1] != ']') |
| 203 | { |
| 204 | log_error("localization", "malformed context '%s' on line %d", pLine, Line); |
| 205 | continue; |
| 206 | } |
| 207 | str_truncate(aContext, sizeof(aContext), pLine + 1, Len - 2); |
| 208 | pLine = LineReader.Get(); |
| 209 | if(!pLine) |
| 210 | { |
| 211 | log_error("localization", "unexpected end of file after context line '%s' on line %d", aContext, Line); |
| 212 | break; |
| 213 | } |
| 214 | Line++; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | aContext[0] = '\0'; |
| 219 | } |
| 220 | |
| 221 | str_copy(aOrigin, pLine); |
| 222 | const char *pReplacement = LineReader.Get(); |
| 223 | if(!pReplacement) |
| 224 | { |
| 225 | log_error("localization", "unexpected end of file after original '%s' on line %d", aOrigin, Line); |
| 226 | break; |
nothing calls this directly
no test coverage detected