added GetLangR, which doesn't construct a CLang object when not found;

GetDef now uses GetLangR, so when users set their language to an invalid value, no such language is created.
This commit is contained in:
Pavol Marko 2004-08-21 21:08:30 +00:00
parent 2f3950b548
commit b63ae4eed8
2 changed files with 18 additions and 3 deletions

View File

@ -332,7 +332,7 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
const char * CLangMngr::CLang::GetDef(const char *key) const char * CLangMngr::CLang::GetDef(const char *key)
{ {
static char nfind[1024] = "ML_NOTFOUND"; static char nfind[1024] = "ML_NOTFOUND(KEY)";
int ikey = m_LMan->GetKeyEntry(key); int ikey = m_LMan->GetKeyEntry(key);
if (ikey == -1) if (ikey == -1)
{ {
@ -941,12 +941,25 @@ CLangMngr::CLang * CLangMngr::GetLang(const char *name)
return p; return p;
} }
// Find a CLang by name, if not found, return NULL
CLangMngr::CLang * CLangMngr::GetLangR(const char *name)
{
LangVecIter iter;
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
{
if ( strcmp((*iter)->GetName(), name)==0 )
return (*iter);
}
return NULL;
}
const char *CLangMngr::GetDef(const char *langName, const char *key) const char *CLangMngr::GetDef(const char *langName, const char *key)
{ {
CLang *lang = GetLang(langName); CLang *lang = GetLangR(langName);
if (lang) if (lang)
return lang->GetDef(key); return lang->GetDef(key);
return ""; return "ML_NOTFOUND(LANG)";
} }
bool CLangMngr::Save(const char *filename) bool CLangMngr::Save(const char *filename)

View File

@ -154,6 +154,8 @@ class CLangMngr
// Get a lang object (construct if needed) // Get a lang object (construct if needed)
CLang * GetLang(const char *name); CLang * GetLang(const char *name);
CLang * GetLangR(const char *name);
// Current global client-id for functions like client_print with first parameter 0 // Current global client-id for functions like client_print with first parameter 0
int m_CurGlobId; int m_CurGlobId;
public: public: