2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#ifndef __LANGDICT_H__
|
|
|
|
#define __LANGDICT_H__
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
class idLangKeyValue
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
|
|
|
idLangKeyValue() : key( NULL ), value( NULL ) { }
|
2012-11-28 15:47:07 +00:00
|
|
|
idLangKeyValue( char* k, char* v ) : key( k ), value( v ) { }
|
|
|
|
char* key;
|
|
|
|
char* value;
|
2012-11-26 18:58:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class idStrId;
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================
|
2012-11-28 15:47:07 +00:00
|
|
|
idLangDict is a simple Dictionary used specifically for the
|
2012-11-26 18:58:24 +00:00
|
|
|
LocalizedStringTables.
|
|
|
|
================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
class idLangDict
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* KEY_PREFIX;
|
2012-11-26 18:58:24 +00:00
|
|
|
static const int KEY_PREFIX_LEN;
|
|
|
|
static const int MAX_REDIRECTION_DEPTH = 2;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLangDict();
|
|
|
|
~idLangDict();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
void Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
bool Load( const byte* buffer, const int bufferLen, const char* name );
|
|
|
|
bool Save( const char* fileName );
|
|
|
|
|
|
|
|
const char* GetString( const char* str ) const; // returns str if string not found
|
|
|
|
const char* FindString( const char* str ) const; // returns NULL if string not found
|
|
|
|
|
|
|
|
const char* AddString( const char* str ); // returns a randomly generated key
|
|
|
|
bool DeleteString( const char* key ); // returns false if the key doesn't exist
|
|
|
|
bool RenameStringKey( const char* oldKey, const char* newKey );
|
|
|
|
|
|
|
|
bool SetString( const char* key, const char* val ); // Returns false if the key doesn't exist
|
|
|
|
void AddKeyVal( const char* key, const char* val ); // Like SetString, but adds it if it doesn't already exist
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int GetNumKeyVals() const;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idLangKeyValue* GetKeyVal( int i ) const;
|
2012-11-26 18:58:24 +00:00
|
|
|
bool DeleteString( const int idx );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const char* GetLocalizedString( const idStrId& strId ) const;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// returns true if the string starts with the KEY_PREFIX string
|
2012-11-28 15:47:07 +00:00
|
|
|
static bool IsStringId( const char* str );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
2012-11-28 15:47:07 +00:00
|
|
|
idDynamicBlockAlloc< char, 100* 1024, 16 > blockAlloc;
|
2012-11-26 18:58:24 +00:00
|
|
|
idList< idLangKeyValue > keyVals;
|
|
|
|
idHashIndex keyIndex;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
2012-11-28 15:47:07 +00:00
|
|
|
int FindStringIndex( const char* str ) const;
|
|
|
|
const char* FindString_r( const char* str, int& depth ) const;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
friend class idStrId;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================
|
2012-11-28 15:47:07 +00:00
|
|
|
idLocalization
|
2012-11-26 18:58:24 +00:00
|
|
|
================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
class idLocalization
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* GetString( const char* inString ); // returns inString if string not found
|
|
|
|
static const char* FindString( const char* inString ); // Returns NULL if string not found
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
static void ClearDictionary();
|
2012-11-28 15:47:07 +00:00
|
|
|
static bool LoadDictionary( const byte* buffer, const int bufferLen, const char* name );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// This is only here for tools, normal code should only ever call GetString
|
2012-11-28 15:47:07 +00:00
|
|
|
static idLangDict& GetDictionary()
|
|
|
|
{
|
|
|
|
return languageDict;
|
|
|
|
}
|
|
|
|
|
|
|
|
static utf8Encoding_t VerifyUTF8( const uint8* buffer, const int bufferLen, const char* name );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
|
|
|
static idLangDict languageDict;
|
|
|
|
friend class idStrId;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================
|
|
|
|
idStrId represents a localized String as a String ID.
|
|
|
|
================================================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
class idStrId
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
|
|
|
idStrId() : index( -1 ) { }
|
2012-11-28 15:47:07 +00:00
|
|
|
idStrId( const idStrId& other ) : index( other.index ) { }
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
explicit idStrId( int i ) : index( i ) { }
|
2012-11-28 15:47:07 +00:00
|
|
|
explicit idStrId( const char* key )
|
|
|
|
{
|
|
|
|
Set( key );
|
|
|
|
}
|
|
|
|
explicit idStrId( const idStr& key )
|
|
|
|
{
|
|
|
|
Set( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator=( const char* key )
|
|
|
|
{
|
|
|
|
Set( key );
|
|
|
|
}
|
|
|
|
void operator=( const idStr& key )
|
|
|
|
{
|
|
|
|
Set( key );
|
|
|
|
}
|
|
|
|
void operator=( const idStrId& other )
|
|
|
|
{
|
|
|
|
index = other.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const idStrId& other ) const
|
|
|
|
{
|
|
|
|
return index == other.index;
|
|
|
|
}
|
|
|
|
bool operator!=( const idStrId& other ) const
|
|
|
|
{
|
|
|
|
return index != other.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set( const char* key );
|
|
|
|
|
|
|
|
void Empty()
|
|
|
|
{
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return index < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* GetKey() const;
|
|
|
|
const char* GetLocalizedString() const;
|
|
|
|
|
|
|
|
int GetIndex() const
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
void SetIndex( int i )
|
|
|
|
{
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
|
|
|
int index; // Index into the language dictionary
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !__LANGDICT_H__
|