🐛 Fixed GetNumStrings not counting strings with context

This commit is contained in:
Edgar 2021-01-15 10:30:56 +01:00
parent 1c4b434079
commit b25a249eaa

View File

@ -43,7 +43,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <unordered_map> #include <map>
//------------------------------------------------------------- //-------------------------------------------------------------
// Path-Seperators are different on other OS. // Path-Seperators are different on other OS.
@ -289,10 +289,10 @@ class moFileReader
{ {
protected: protected:
/// \brief Type for the map which holds the translation-pairs later. /// \brief Type for the map which holds the translation-pairs later.
typedef std::unordered_map<std::string, std::string> moLookupList; typedef std::map<std::string, std::string> moLookupList;
/// \brief Type for the 2D map which holds the translation-pairs later. /// \brief Type for the 2D map which holds the translation-pairs later.
typedef std::unordered_map<std::string, moLookupList> moContextLookupList; typedef std::map<std::string, moLookupList> moContextLookupList;
public: public:
/// \brief The Magic Number describes the endianess of bytes on the system. /// \brief The Magic Number describes the endianess of bytes on the system.
@ -490,11 +490,13 @@ class moFileReader
// Store it in the map. // Store it in the map.
if(x == std::string::npos){ if(x == std::string::npos){
m_lookup[original_str] = translation_str; m_lookup[original_str] = translation_str;
numStrings++;
} }
else{ else{
// try-catch for handling out_of_range exceptions // try-catch for handling out_of_range exceptions
try { try {
m_lookup_context[original_str.substr(0, x)][original_str.substr(x + 1, original_str.length())] = translation_str; m_lookup_context[original_str.substr(0, x)][original_str.substr(x + 1, original_str.length())] = translation_str;
numStrings++;
} }
catch (...) { catch (...) {
m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!"; m_error = "Stream bad during reading. The .mo-file seems to be invalid or has bad descriptions!";
@ -550,6 +552,8 @@ class moFileReader
void ClearTable() void ClearTable()
{ {
m_lookup.clear(); m_lookup.clear();
m_lookup_context.clear();
numStrings = 0;
} }
/** \brief Returns the Number of Entries in our Lookup-Table. /** \brief Returns the Number of Entries in our Lookup-Table.
@ -558,7 +562,7 @@ class moFileReader
*/ */
unsigned int GetNumStrings() const unsigned int GetNumStrings() const
{ {
return m_lookup.size(); return numStrings;
} }
/** \brief Exports the whole content of the .mo-File as .html /** \brief Exports the whole content of the .mo-File as .html
@ -684,6 +688,8 @@ class moFileReader
moLookupList m_lookup; moLookupList m_lookup;
moContextLookupList m_lookup_context; moContextLookupList m_lookup_context;
int numStrings = 0;
// Replaces < with ( to satisfy html-rules. // Replaces < with ( to satisfy html-rules.
static void MakeHtmlConform(std::string &_inout) static void MakeHtmlConform(std::string &_inout)
{ {