🎨 Reformatted code

This commit is contained in:
Edgar 2021-01-15 11:03:58 +01:00
parent 57b0d3a184
commit c3e01fc5c8
2 changed files with 21 additions and 16 deletions

View File

@ -41,18 +41,18 @@
#include <cstring> // this is for memset when compiling with gcc. #include <cstring> // this is for memset when compiling with gcc.
#include <deque> #include <deque>
#include <fstream> #include <fstream>
#include <map>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <map>
//------------------------------------------------------------- //-------------------------------------------------------------
// Path-Seperators are different on other OS. // Path-Seperators are different on other OS.
//------------------------------------------------------------- //-------------------------------------------------------------
#ifndef moPATHSEP #ifndef MO_PATHSEP
#ifdef WIN32 #ifdef WIN32
#define moPATHSEP std::string("\\") #define MO_PATHSEP std::string("\\")
#else #else
#define moPATHSEP std::string("/") #define MO_PATHSEP std::string("/")
#endif #endif
#endif #endif
@ -483,22 +483,27 @@ class moFileReader
return moFileReader::EC_FILEINVALID; return moFileReader::EC_FILEINVALID;
} }
std::string original_str = original; std::string original_str = original;
std::string translation_str = translation; std::string translation_str = translation;
auto x = original_str.find(ContextSeparator); auto ctxSeparator = original_str.find(ContextSeparator);
// Store it in the map. // Store it in the map.
if(x == std::string::npos){ if (ctxSeparator == std::string::npos)
{
m_lookup[original_str] = translation_str; m_lookup[original_str] = translation_str;
numStrings++; 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, ctxSeparator)]
[original_str.substr(ctxSeparator + 1, original_str.length())] = translation_str;
numStrings++; 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!";
return moFileReader::EC_ERROR; return moFileReader::EC_ERROR;
} }
@ -536,7 +541,7 @@ class moFileReader
if (m_lookup_context.empty()) return id; if (m_lookup_context.empty()) return id;
auto iterator = m_lookup_context.find(context); auto iterator = m_lookup_context.find(context);
if(iterator == m_lookup_context.end()) return id; if (iterator == m_lookup_context.end()) return id;
auto iterator2 = iterator->second.find(id); auto iterator2 = iterator->second.find(id);
return iterator2 == iterator->second.end() ? id : iterator2->second; return iterator2 == iterator->second.end() ? id : iterator2->second;
@ -575,14 +580,14 @@ class moFileReader
static eErrorCode ExportAsHTML(const std::string &infile, const std::string &filename = "", const std::string &css = g_css) static eErrorCode ExportAsHTML(const std::string &infile, const std::string &filename = "", const std::string &css = g_css)
{ {
// Read the file // Read the file
moFileReader reader; moFileReader reader;
moFileReader::eErrorCode r = reader.ReadFile(infile.c_str()); moFileReader::eErrorCode r = reader.ReadFile(infile.c_str());
if (r != moFileReader::EC_SUCCESS) { return r; } if (r != moFileReader::EC_SUCCESS) { return r; }
if (reader.m_lookup.empty()) { return moFileReader::EC_TABLEEMPTY; } if (reader.m_lookup.empty()) { return moFileReader::EC_TABLEEMPTY; }
// Beautify Output // Beautify Output
std::string fname; std::string fname;
unsigned int pos = infile.find_last_of(moPATHSEP); unsigned int pos = infile.find_last_of(MO_PATHSEP);
if (pos != std::string::npos) { fname = infile.substr(pos + 1, infile.length()); } if (pos != std::string::npos) { fname = infile.substr(pos + 1, infile.length()); }
else else
{ {
@ -685,7 +690,7 @@ class moFileReader
private: private:
// Holds the lookup-table // Holds the lookup-table
moLookupList m_lookup; moLookupList m_lookup;
moContextLookupList m_lookup_context; moContextLookupList m_lookup_context;
int numStrings = 0; int numStrings = 0;

View File

@ -97,7 +97,7 @@ void PrintLicense()
std::string GetAppName(const char *raw) std::string GetAppName(const char *raw)
{ {
std::string r(raw); std::string r(raw);
int first = r.find_last_of(moPATHSEP) + 1; int first = r.find_last_of(MO_PATHSEP) + 1;
r = r.substr(first, r.length() - first); r = r.substr(first, r.length() - first);
return r; return r;
} }