1
0
forked from 0ad/0ad

Slightly better dictionary handling

This was SVN commit r1041.
This commit is contained in:
Ykkrosh 2004-08-24 11:28:18 +00:00
parent 49b5c5c2b8
commit c6d292dc87
5 changed files with 28 additions and 16 deletions

View File

@ -185,12 +185,14 @@ bool CLocale::LoadFunctions(const char* data, size_t len, const char* filename)
}
bool CLocale::LoadDictionary(const char* data, const wchar_t* name)
bool CLocale::LoadDictionary(const char* data)
{
ReadWString8(DictName);
u8 PropertyCount = *(u8*)data;
data += 1;
DictData& dict = Dictionaries[name];
DictData& dict = Dictionaries[DictName];
// Read the names of the properties

View File

@ -23,20 +23,21 @@ All other methods are used internally by other I18n components.
#include <map>
#include <algorithm>
// GCC requires an explicit hash function for wide strings
#ifdef __GNUC__
namespace __gnu_cxx
{
template<> struct hash<I18n::Str>
{
size_t operator()(const I18n::Str& s) const
{
const wchar_t* __s = s.c_str();
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(__h);
}
};
template<> struct hash<I18n::Str>
{
size_t operator()(const I18n::Str& s) const
{
const wchar_t* __s = s.c_str();
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(__h);
}
};
}
#endif // __GNUC__
@ -57,7 +58,7 @@ namespace I18n
bool LoadFunctions(const char* filedata, size_t len, const char* filename);
bool LoadStrings(const char* filedata);
bool LoadDictionary(const char* filedata, const wchar_t* name);
bool LoadDictionary(const char* filedata);
const StrImW CallFunction(const char* name, const std::vector<BufferVariable*>& vars, const std::vector<ScriptValue*>& params);

View File

@ -13,6 +13,10 @@ namespace I18n
template<typename T> Name(T d) : value(d) {}
StrImW value;
};
// Also allow I18n::Raw("english message"), which does the same
// non-translation but makes more sense when writing e.g. error messages
typedef Name Raw;
}

View File

@ -31,7 +31,7 @@ namespace I18n
virtual bool LoadStrings(const char* filedata) = 0;
// Needs .wrd files generated through tables.pl
virtual bool LoadDictionary(const char* filedata, const wchar_t* name) = 0;
virtual bool LoadDictionary(const char* filedata) = 0;
virtual ~CLocale_interface() {}
};

View File

@ -149,6 +149,10 @@ static JSClass JSI_class_scriptglobal = {
ScriptObject::ScriptObject(CLocale* locale, JSContext* cx)
: Context(cx)
{
// Don't do much if there's currently no scripting support
if (cx == NULL)
return;
// This should, in theory, never fail
Object = JS_NewObject(Context, &JSI_class_scriptglobal, NULL, NULL);
@ -172,7 +176,8 @@ ScriptObject::ScriptObject(CLocale* locale, JSContext* cx)
ScriptObject::~ScriptObject()
{
JS_RemoveRoot(Context, &Object);
if (Context)
JS_RemoveRoot(Context, &Object);
}
bool ScriptObject::ExecuteCode(const jschar* data, size_t len, const char* filename)