#include "string_table_simple.h" #include "tinyxml/tinyxml.h" using namespace irr; using namespace core; bool StringTable::Load(const char* filename_) { if ( !filename_ || !strlen(filename_) ) return false; TiXmlDocument xmlDoc(filename_); if ( !xmlDoc.LoadFile() ) { return false; } TiXmlNode * stringsNode = xmlDoc.FirstChild("strings"); if (!stringsNode) return false; TiXmlNode* node = stringsNode->IterateChildren("string", NULL); while ( node ) { TiXmlElement* element = node->ToElement(); const char * text = element->GetText(); const char *id = element->Attribute("id"); if ( id && strlen(id) && text ) { std::string strId(id); std::string strText(text); std::wstring wstrId(strId.begin(), strId.end()); std::wstring wstrText(strText.begin(), strText.end()); Add(wstrId.c_str(), wstrText.c_str()); } node = stringsNode->IterateChildren("string", node); } return true; } //bool StringTable::Save(const c8* filename_) //{ //} void StringTable::Add(const stringw &identifier_, const stringw &string_) { int idx = mStringTable.binary_search( StringTableEntry(identifier_) ); if ( idx < 0 ) mStringTable.push_back( StringTableEntry(identifier_, string_) ); else mStringTable[idx].mString = string_; } stringw StringTable::Get(const stringw &identifier_) { int idx = mStringTable.binary_search( StringTableEntry(identifier_) ); if ( idx < 0 ) return identifier_; return mStringTable[idx].mString; } stringw StringTable::Get(const char *identifier_) { std::string str(identifier_); std::wstring wstr(str.begin(), str.end()); return Get(stringw(wstr.c_str())); }