From 9d534882e862bc89f127b1d3c6a9ced098b88214 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 31 Oct 2020 08:11:32 +0800 Subject: [PATCH] UTF-8 string manager, ryzom/ryzomcore#335 --- ryzom/client/src/commands.cpp | 22 +- ryzom/client/src/entity_cl.cpp | 37 ++- ryzom/client/src/entity_cl.h | 4 +- ryzom/client/src/forage_source_cl.cpp | 4 +- .../src/interface_v3/action_handler_help.cpp | 4 +- .../src/interface_v3/action_handler_misc.cpp | 2 +- .../client/src/interface_v3/group_compas.cpp | 4 +- .../src/interface_v3/sbrick_manager.cpp | 6 +- ryzom/client/src/net_manager.cpp | 8 +- ryzom/client/src/player_cl.cpp | 2 +- ryzom/client/src/player_r2_cl.cpp | 2 +- ryzom/client/src/string_manager_client.cpp | 241 +++++++++--------- ryzom/client/src/string_manager_client.h | 138 +++++----- 13 files changed, 247 insertions(+), 227 deletions(-) diff --git a/ryzom/client/src/commands.cpp b/ryzom/client/src/commands.cpp index 986da78e6..d3a6a2df6 100644 --- a/ryzom/client/src/commands.cpp +++ b/ryzom/client/src/commands.cpp @@ -1385,14 +1385,14 @@ NLMISC_COMMAND(setItemName, "set name of items, sbrick, etc.."," 2) - desc.fromUtf8(args[2]); + desc = args[2]; if (args.size() > 3) - desc2.fromUtf8(args[3]); + desc2 = args[3]; STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); if (pSMC) @@ -1406,10 +1406,10 @@ NLMISC_COMMAND(setItemName, "set name of items, sbrick, etc.."," ") { if (args.size() < 2) return false; - ucstring name; - name.fromUtf8(args[0]); - ucstring text; - text.fromUtf8(args[1]); + string name; + name = args[0]; + string text; + text = args[1]; STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); if (pSMC) @@ -1459,7 +1459,7 @@ NLMISC_COMMAND(ah, "Launch an action handler", " ") static void setDynString(uint32 strID, const std::string &value) { STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); - pSMC->receiveString(strID, ucstring(value)); + pSMC->receiveString(strID, value); CBitMemStream bm; if (bm.isReading()) bm.invert(); bm.serial(strID); diff --git a/ryzom/client/src/entity_cl.cpp b/ryzom/client/src/entity_cl.cpp index 9e57b3acb..b28d3fda6 100644 --- a/ryzom/client/src/entity_cl.cpp +++ b/ryzom/client/src/entity_cl.cpp @@ -2262,32 +2262,32 @@ void CEntityCL::load() // virtual // onStringAvailable : // Callback when the name is arrived. //----------------------------------------------- -void CEntityCL::onStringAvailable(uint /* stringId */, const ucstring &value) +void CEntityCL::onStringAvailable(uint /* stringId */, const std::string &value) { - _EntityName = value.toUtf8(); + _EntityName = value; // remove the shard name if possible _EntityName= removeShardFromName(_EntityName); // New title - ucstring newtitle; + string newtitle; _HasReservedTitle = false; // check if there is any replacement tag in the string - ucstring::size_type p1 = _EntityName.find('$'); + string::size_type p1 = _EntityName.find('$'); if (p1 != ucstring::npos) { // we found a replacement point begin tag - ucstring::size_type p2 = _EntityName.find('$', p1+1); + string::size_type p2 = _EntityName.find('$', p1+1); if (p2 != ucstring::npos) { // ok, we have the second replacement point! // extract the replacement id - ucstring id = _EntityName.substr(p1+1, p2-p1-1); + string id = _EntityName.substr(p1+1, p2-p1-1); // retrieve the translated string - _TitleRaw = id.toString(); -// ucstring replacement = CI18N::get(strNewTitle); + _TitleRaw = id; +// string replacement = CI18N::get(strNewTitle); bool womanTitle = false; CCharacterCL * c = dynamic_cast(this); if(c) @@ -2295,22 +2295,21 @@ void CEntityCL::onStringAvailable(uint /* stringId */, const ucstring &value) womanTitle = ( c->getGender() == GSGENDER::female ); } - ucstring replacement(STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw, womanTitle)); + string replacement = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw.toUtf8(), womanTitle); // Sometimes translation contains another title { - ucstring::size_type pos = replacement.find('$'); + string::size_type pos = replacement.find('$'); if (pos != ucstring::npos) { - ucstring sn = replacement; - _EntityName = sn.substr(0, pos).toUtf8(); - ucstring::size_type pos2 = sn.find('$', pos + 1); - _TitleRaw = sn.substr(pos+1, pos2 - pos - 1); - replacement = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw, womanTitle); + _EntityName = _EntityName = STRING_MANAGER::CStringManagerClient::getLocalizedName(sn.substr(0, pos)); + string::size_type pos2 = replacement.find('$', pos + 1); + _TitleRaw = replacement.substr(pos+1, pos2 - pos - 1); + replacement = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw.toUtf8(), womanTitle); } } - _Tags = STRING_MANAGER::CStringManagerClient::getTitleInfos(_TitleRaw, womanTitle); + _Tags = STRING_MANAGER::CStringManagerClient::getTitleInfos(_TitleRaw.toUtf8(), womanTitle); if (!replacement.empty() || !ClientCfg.DebugStringManager) { @@ -2319,9 +2318,9 @@ void CEntityCL::onStringAvailable(uint /* stringId */, const ucstring &value) _EntityName = STRING_MANAGER::CStringManagerClient::getLocalizedName(_EntityName.substr(0, p1)); // + _Name.substr(p2+1) // Get extended name _NameEx = replacement; - newtitle = _NameEx; + newtitle = _NameEx.toUtf8(); } - CHARACTER_TITLE::ECharacterTitle titleEnum = CHARACTER_TITLE::toCharacterTitle( _TitleRaw.toString() ); + CHARACTER_TITLE::ECharacterTitle titleEnum = CHARACTER_TITLE::toCharacterTitle( _TitleRaw.toUtf8() ); if ( titleEnum >= CHARACTER_TITLE::BeginGmTitle && titleEnum <= CHARACTER_TITLE::EndGmTitle ) { _GMTitle = titleEnum - CHARACTER_TITLE::BeginGmTitle; @@ -2359,7 +2358,7 @@ void CEntityCL::onStringAvailable(uint /* stringId */, const ucstring &value) if (pGC != NULL) pGC->setUCTitle(_EntityName); CSkillManager *pSM = CSkillManager::getInstance(); - pSM->setPlayerTitle(_TitleRaw.toString()); + pSM->setPlayerTitle(_TitleRaw.toUtf8()); } // Must rebuild the in scene interface 'cause name has changed diff --git a/ryzom/client/src/entity_cl.h b/ryzom/client/src/entity_cl.h index 5b53c3027..3ac01ed25 100644 --- a/ryzom/client/src/entity_cl.h +++ b/ryzom/client/src/entity_cl.h @@ -935,7 +935,7 @@ protected: // Current entity title ucstring _Title; // Current entity tags - std::vector _Tags; + std::vector _Tags; // Current entity title string id ucstring _TitleRaw; // Current permanent content symbol for the entity @@ -1222,7 +1222,7 @@ public: private: // Override for string reception callback - virtual void onStringAvailable(uint stringId, const ucstring &value); + virtual void onStringAvailable(uint stringId, const std::string &value); }; diff --git a/ryzom/client/src/forage_source_cl.cpp b/ryzom/client/src/forage_source_cl.cpp index 7f538a2f0..e813912df 100644 --- a/ryzom/client/src/forage_source_cl.cpp +++ b/ryzom/client/src/forage_source_cl.cpp @@ -536,10 +536,10 @@ void CForageSourceCL::updateVisualPropertyVisualFX(const NLMISC::TGameCycle &/* void CForageSourceCL::updateVisualPropertyName(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop) { CSheetId rmSheetId( (const uint32&)prop ); - const ucchar *name = STRING_MANAGER::CStringManagerClient::getItemLocalizedName( rmSheetId ); + const char *name = STRING_MANAGER::CStringManagerClient::getItemLocalizedName( rmSheetId ); if ( name ) { - _EntityName = ucstring(name).toUtf8(); + _EntityName = name; if ( _ProspectorSlot != 255 ) { CEntityCL *prospector = EntitiesMngr.entities()[_ProspectorSlot]; diff --git a/ryzom/client/src/interface_v3/action_handler_help.cpp b/ryzom/client/src/interface_v3/action_handler_help.cpp index 2ccbf963a..c00328ef0 100644 --- a/ryzom/client/src/interface_v3/action_handler_help.cpp +++ b/ryzom/client/src/interface_v3/action_handler_help.cpp @@ -693,7 +693,7 @@ class CHandlerOpenTitleHelp : public IActionHandler // retrieve the translated string if (!strNewTitle.empty()) - name = ucstring(STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(ucstring::makeFromUtf8(strNewTitle), woman)).toUtf8(); + name = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(strNewTitle, woman); else name.clear(); } @@ -752,7 +752,7 @@ class CHandlerOpenTitleHelp : public IActionHandler for (titleIDnb = 0; titleIDnb < CHARACTER_TITLE::NB_CHARACTER_TITLE; ++titleIDnb) { bool women = UserEntity && UserEntity->getGender()==GSGENDER::female; - if (CStringManagerClient::getTitleLocalizedName(CHARACTER_TITLE::toString((CHARACTER_TITLE::ECharacterTitle)titleIDnb),women) == title) + if (CStringManagerClient::getTitleLocalizedName(CHARACTER_TITLE::toString((CHARACTER_TITLE::ECharacterTitle)titleIDnb),women) == title.toUtf8()) break; } diff --git a/ryzom/client/src/interface_v3/action_handler_misc.cpp b/ryzom/client/src/interface_v3/action_handler_misc.cpp index 63d491deb..8190ab799 100644 --- a/ryzom/client/src/interface_v3/action_handler_misc.cpp +++ b/ryzom/client/src/interface_v3/action_handler_misc.cpp @@ -916,7 +916,7 @@ NLMISC_COMMAND(slsn, "Temp : set the name of the last sender.", "") bool CStringPostProcessRemoveName::cbIDStringReceived(ucstring &inOut) { // extract the replacement id - ucstring strNewTitle = CEntityCL::getTitleFromName(inOut.toUtf8()); + string strNewTitle = CEntityCL::getTitleFromName(inOut.toUtf8()); // retrieve the translated string if (!strNewTitle.empty()) diff --git a/ryzom/client/src/interface_v3/group_compas.cpp b/ryzom/client/src/interface_v3/group_compas.cpp index d5b8d7e9c..fc0f2a5a5 100644 --- a/ryzom/client/src/interface_v3/group_compas.cpp +++ b/ryzom/client/src/interface_v3/group_compas.cpp @@ -1047,12 +1047,12 @@ REGISTER_ACTION_HANDLER( CHandlerSetCompassNorth, "set_compass_north"); class CCompassDialogsStringCallback : public IStringWaitCallback { - virtual void onDynStringAvailable(uint /* stringId */, const ucstring &value) + virtual void onDynStringAvailable(uint /* stringId */, const std::string &value) { uint size = (uint)CCompassDialogsManager::getInstance()._Entries.size(); for ( uint i = 0; i < size; i++) { - ucstring name; + std::string name; if ( CStringManagerClient::instance()->getDynString(CCompassDialogsManager::getInstance()._Entries[i].Text, name) ) { if ( value == name ) diff --git a/ryzom/client/src/interface_v3/sbrick_manager.cpp b/ryzom/client/src/interface_v3/sbrick_manager.cpp index d12ed783c..a2cecf2d4 100644 --- a/ryzom/client/src/interface_v3/sbrick_manager.cpp +++ b/ryzom/client/src/interface_v3/sbrick_manager.cpp @@ -436,7 +436,7 @@ void CSBrickManager::compileBrickProperties() // **** for all bricks, recompute localized text with formated version - ucstring textTemp; + string textTemp; textTemp.reserve(1000); for (std::vector::size_type ib = 0; ib < _BrickVector.size(); ++ib) { @@ -445,7 +445,7 @@ void CSBrickManager::compileBrickProperties() continue; // Get the Brick texts - ucstring texts[3]; + std::string texts[3]; texts[0]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedName(brickSheet->Id); texts[1]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedDescription(brickSheet->Id); texts[2]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedCompositionDescription(brickSheet->Id); @@ -453,7 +453,7 @@ void CSBrickManager::compileBrickProperties() // For alls texts, parse format for(uint i=0;i<3;i++) { - ucstring &text= texts[i]; + string &text= texts[i]; textTemp.erase(); // Parse the text diff --git a/ryzom/client/src/net_manager.cpp b/ryzom/client/src/net_manager.cpp index e2d55e250..9f05fe860 100644 --- a/ryzom/client/src/net_manager.cpp +++ b/ryzom/client/src/net_manager.cpp @@ -2299,11 +2299,9 @@ void impulsePhraseSend(NLMISC::CBitMemStream &impulse) void impulseStringResp(NLMISC::CBitMemStream &impulse) { uint32 stringId; - string strUtf8; + string str; impulse.serial(stringId); - impulse.serial(strUtf8); - ucstring str; - str.fromUtf8(strUtf8); + impulse.serial(str); if (PermanentlyBanned) return; @@ -3390,7 +3388,7 @@ private: public: // called when the string is available - virtual void onDynStringAvailable(uint stringId, const ucstring &value) + virtual void onDynStringAvailable(uint stringId, const std::string &value) { // don't care if already displayed if(_AlreadyDisplayed) diff --git a/ryzom/client/src/player_cl.cpp b/ryzom/client/src/player_cl.cpp index 9aef1032b..437149f16 100644 --- a/ryzom/client/src/player_cl.cpp +++ b/ryzom/client/src/player_cl.cpp @@ -743,7 +743,7 @@ void CPlayerCL::updateVisualPropertyVpa(const NLMISC::TGameCycle &/* gameCycle * } // update title when gender changed - const ucstring replacement(STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw, _Gender == GSGENDER::female)); + const string replacement = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw.toUtf8(), _Gender == GSGENDER::female); if (!replacement.empty() || !ClientCfg.DebugStringManager) { // Get extended name diff --git a/ryzom/client/src/player_r2_cl.cpp b/ryzom/client/src/player_r2_cl.cpp index 138e7d8fa..8f7621755 100644 --- a/ryzom/client/src/player_r2_cl.cpp +++ b/ryzom/client/src/player_r2_cl.cpp @@ -446,7 +446,7 @@ void CPlayerR2CL::updateVisualPropertyVpa(const NLMISC::TGameCycle &/* gameCycle } // update title when gender changed - const ucstring replacement(STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw,_Gender == GSGENDER::female)); + const string replacement(STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw.toUtf8(),_Gender == GSGENDER::female)); if (!replacement.empty()) { // Get extended name diff --git a/ryzom/client/src/string_manager_client.cpp b/ryzom/client/src/string_manager_client.cpp index ec493e3d3..7381f5cb9 100644 --- a/ryzom/client/src/string_manager_client.cpp +++ b/ryzom/client/src/string_manager_client.cpp @@ -39,17 +39,17 @@ namespace STRING_MANAGER // *************************************************************************** map CStringManagerClient::_SpecItem_TempMap; - map CStringManagerClient::_DynStrings; - vector CStringManagerClient::_TitleWords; + map CStringManagerClient::_DynStrings; + vector CStringManagerClient::_TitleWords; bool CStringManagerClient::_SpecItem_MemoryCompressed = false; char *CStringManagerClient::_SpecItem_Labels = NULL; - ucchar *CStringManagerClient::_SpecItem_NameDesc = NULL; + char *CStringManagerClient::_SpecItem_NameDesc = NULL; vector CStringManagerClient::_SpecItems; bool MustReleaseStaticArrays = true; CStringManagerClient *CStringManagerClient::_Instance= NULL; - ucstring CStringManagerClient::_WaitString("???"); + string CStringManagerClient::_WaitString("???"); CStringManagerClient::CStringManagerClient() @@ -57,7 +57,7 @@ namespace STRING_MANAGER _CacheInited = false; _CacheLoaded = false; // insert the empty string. - _ReceivedStrings.insert(make_pair((uint)EmptyStringId, ucstring())); + _ReceivedStrings.insert(make_pair((uint)EmptyStringId, string())); // reserve some place to avoid reallocation as possible _CacheStringToSave.reserve(1024); } @@ -122,6 +122,7 @@ namespace STRING_MANAGER { try { + const uint currentVersion = 1; _CacheFilename = std::string("save/") + _ShardId.substr(0, _ShardId.find(":")) + ".string_cache"; nlinfo("SM : Try to open the string cache : %s", _CacheFilename.c_str()); @@ -131,6 +132,8 @@ namespace STRING_MANAGER // there is a cache file, check date reset it if needed { NLMISC::CIFile file(_CacheFilename); + file.setVersionException(false, false); + file.serialVersion(currentVersion); file.serial(_Timestamp); } @@ -139,6 +142,7 @@ namespace STRING_MANAGER nlinfo("SM: Clearing string cache : outofdate"); // the cache is not sync, reset it NLMISC::COFile file(_CacheFilename); + file.serialVersion(currentVersion); file.serial(timestamp); } else @@ -151,6 +155,7 @@ namespace STRING_MANAGER nlinfo("SM: Creating string cache"); // cache file don't exist, create it with the timestamp NLMISC::COFile file(_CacheFilename); + file.serialVersion(currentVersion); file.serial(timestamp); } @@ -160,17 +165,19 @@ namespace STRING_MANAGER // NB : we keep the waiting strings and dyn strings // insert the empty string. - _ReceivedStrings.insert(make_pair((uint)EmptyStringId, ucstring())); + _ReceivedStrings.insert(make_pair((uint)EmptyStringId, string())); // load the cache file NLMISC::CIFile file(_CacheFilename); + int version = file.serialVersion(currentVersion); file.serial(_Timestamp); nlassert(_Timestamp == timestamp); + nlassert(version >= 1); // Initial version while (!file.eof()) { uint32 id; - ucstring str; + string str; file.serial(id); file.serial(str); @@ -194,12 +201,12 @@ namespace STRING_MANAGER - void CStringManagerClient::waitString(uint32 stringId, const IStringWaiterRemover *premover, ucstring *result) + void CStringManagerClient::waitString(uint32 stringId, const IStringWaiterRemover *premover, string *result) { H_AUTO( CStringManagerClient_waitString ) nlassert(premover && result); - ucstring value; + string value; if (getString(stringId, value)) *result = value; else @@ -217,7 +224,7 @@ namespace STRING_MANAGER H_AUTO( CStringManagerClient_waitString2 ) nlassert(pcallback != 0); - ucstring value; + string value; if (getString(stringId, value)) { pcallback->onStringAvailable(stringId, value); @@ -230,12 +237,12 @@ namespace STRING_MANAGER } - void CStringManagerClient::waitDynString(uint32 stringId, const IStringWaiterRemover *premover, ucstring *result) + void CStringManagerClient::waitDynString(uint32 stringId, const IStringWaiterRemover *premover, string *result) { H_AUTO( CStringManagerClient_waitDynString ) nlassert(premover && result); - ucstring value; + string value; if (getDynString(stringId, value)) *result = value; else @@ -253,7 +260,7 @@ namespace STRING_MANAGER H_AUTO( CStringManagerClient_waitDynString2 ) nlassert(pcallback != 0); - ucstring value; + string value; if (getDynString(stringId, value)) { pcallback->onDynStringAvailable(stringId, value); @@ -330,7 +337,7 @@ restartLoop4: - bool CStringManagerClient::getString(uint32 stringId, ucstring &result) + bool CStringManagerClient::getString(uint32 stringId, string &result) { H_AUTO( CStringManagerClient_getString ) @@ -357,7 +364,7 @@ restartLoop4: _WaitingStrings.insert(stringId); // need to ask for this string. NLMISC::CBitMemStream bms; - const std::string msgType = "STRING_MANAGER:STRING_RQ"; + const string msgType = "STRING_MANAGER:STRING_RQ"; if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) { bms.serial( stringId ); @@ -374,7 +381,7 @@ restartLoop4: { char tmp[1024]; sprintf(tmp, "", stringId); - result = ucstring(tmp); + result = tmp; } else result.erase(); // = _WaitString; @@ -385,14 +392,14 @@ restartLoop4: { char tmp[1024]; sprintf(tmp, "", stringId); - result = ucstring(tmp) + it->second; + result = tmp + it->second; } else { result = it->second; - if (result.size() > 9 && result.substr(0, 9) == ucstring(" 9 && result.substr(0, 9) == "::iterator itds = _DynStrings.find(result.substr(9, result.size()-10)); + map::iterator itds = _DynStrings.find(result.substr(9, result.size()-10)); if (itds != _DynStrings.end()) result = itds->second; } @@ -402,7 +409,7 @@ restartLoop4: return true; } - void CStringManagerClient::receiveString(uint32 stringId, const ucstring &str) + void CStringManagerClient::receiveString(uint32 stringId, const string &str) { H_AUTO( CStringManagerClient_receiveString ) @@ -419,8 +426,8 @@ restartLoop4: TStringsContainer::iterator it(_ReceivedStrings.find(stringId)); nlwarning("Receiving stringID %u (%s), already in received string (%s), replacing with new value.", stringId, - str.toString().c_str(), - it->second.toString().c_str()); + str.c_str(), + it->second.c_str()); if (it->second != str) it->second = str; @@ -484,7 +491,7 @@ restartLoop: last = _WaitingDynStrings.end(); for (; first != last; ++first) { - ucstring value; + string value; uint number = first->first; /// Warning: if getDynString() return true, 'first' is erased => don't use it after in this loop if (getDynString(number, value)) @@ -616,7 +623,7 @@ restartLoop: return false; } // ok, we have the base string, we can serial the parameters - ucstring::iterator first(dynInfo.String.begin()), last(dynInfo.String.end()); + string::iterator first(dynInfo.String.begin()), last(dynInfo.String.end()); for (; first != last; ++first) { if (*first == '%') @@ -699,10 +706,10 @@ restartLoop: if (dynInfo.Status == TDynStringInfo::serialized) { // try to retreive all string parameter to build the string. - ucstring temp; + string temp; temp.reserve(dynInfo.String.size() * 2); - ucstring::iterator src(dynInfo.String.begin()); - ucstring::iterator move = src; + string::iterator src(dynInfo.String.begin()); + string::iterator move = src; std::vector::iterator first(dynInfo.Params.begin()), last(dynInfo.Params.end()); for (; first != last; ++first) @@ -712,7 +719,7 @@ restartLoop: { case string_id: { - ucstring str; + string str; if (!getString(param.StringId, str)) return false; @@ -741,10 +748,10 @@ restartLoop: } // If the string contains a title, then remove it - ucstring::size_type pos = str.find('$'); + string::size_type pos = str.find('$'); if ( ! str.empty() && pos != ucstring::npos) { - str = CEntityCL::removeTitleFromName(str.toUtf8()); + str = CEntityCL::removeTitleFromName(str); } // append this string @@ -759,13 +766,13 @@ restartLoop: char value[1024]; sprintf(value, "%d", param.Integer); temp.append(move, src+param.ReplacementPoint); - temp+=ucstring(value); + temp += value; move = dynInfo.String.begin()+param.ReplacementPoint+2; } break; case time: { - ucstring value; + string value; uint32 time = (uint32)param.Time; if( time >= (10*60*60) ) { @@ -796,7 +803,7 @@ restartLoop: char value[1024]; sprintf(value, "%u", (uint32)param.Money); temp.append(move, src+param.ReplacementPoint); - temp+=ucstring(value); + temp += value; move = dynInfo.String.begin()+param.ReplacementPoint+2; } // TODO @@ -805,7 +812,7 @@ restartLoop: break; case dyn_string_id: { - ucstring dynStr; + string dynStr; if (!getDynString(param.DynStringId, dynStr)) return false; temp.append(move, src+param.ReplacementPoint); @@ -823,8 +830,8 @@ restartLoop: // apply any 'delete' character in the string and replace double '%' { - uint i =0; - while (i < temp.size()) + ptrdiff_t i =0; + while (i < (ptrdiff_t)temp.size()) { if (temp[i] == 8) { @@ -853,7 +860,7 @@ restartLoop: } - bool CStringManagerClient::getDynString(uint32 dynStringId, ucstring &result) + bool CStringManagerClient::getDynString(uint32 dynStringId, std::string &result) { H_AUTO( CStringManagerClient_getDynString ) @@ -882,7 +889,7 @@ restartLoop: { char tmp[1024]; sprintf(tmp, "", dynStringId); - result = ucstring(tmp) + it->second.String; + result = tmp + it->second.String; } else result = it->second.String; @@ -908,7 +915,7 @@ restartLoop: nlwarning("DynStringID %u is unknown !", dynStringId); char tmp[1024]; sprintf(tmp, "", dynStringId); - result = ucstring(tmp); + result = tmp; } else result.erase(); //_WaitString; @@ -920,7 +927,7 @@ restartLoop: { char tmp[1024]; sprintf(tmp, "", dynStringId); - result = ucstring(tmp) + it->second.String; + result = tmp + it->second.String; } else result = it->second.String; @@ -933,7 +940,7 @@ restartLoop: { char tmp[1024]; sprintf(tmp, "", dynStringId); - result = ucstring(tmp); + result = tmp; } else result.erase(); // = _WaitString; @@ -943,7 +950,7 @@ restartLoop: } // Tool fct to lookup a reference file - static string lookupReferenceFile(const std::string &fileName) + static string lookupReferenceFile(const string &fileName) { string referenceFile; // special location for the "wk" language @@ -964,14 +971,14 @@ restartLoop: return referenceFile; } - void CLoadProxy::loadStringFile(const std::string &filename, ucstring &text) + void CLoadProxy::loadStringFile(const string &filename, ucstring &text) { vector reference; vector addition; vector diff; // get the correct path name of the ref file - std::string referenceFile= lookupReferenceFile(filename); + string referenceFile= lookupReferenceFile(filename); // load the reference file if (!referenceFile.empty()) @@ -1041,7 +1048,7 @@ public: TWorksheet diff; // get the correct path name of the ref file - std::string referenceFile= lookupReferenceFile(filename); + string referenceFile= lookupReferenceFile(filename); // load the reference file if (!referenceFile.empty()) @@ -1134,7 +1141,7 @@ public: const string StringClientPackedFileName= "./save/string_client.pack"; // Must Increment this number if change are made to the code (else change not taken into account) const uint StringClientPackedVersion= 0; -bool CStringManagerClient::checkWordFileDates(vector &fileChecks, const std::vector &fileNames, const std::string &languageCode) +bool CStringManagerClient::checkWordFileDates(vector &fileChecks, const std::vector &fileNames, const string &languageCode) { fileChecks.resize(fileNames.size()); @@ -1142,7 +1149,7 @@ bool CStringManagerClient::checkWordFileDates(vector &fileChecks, co for(uint i=0;i &fileChecks, co // *************************************************************************** -void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) +void CStringManagerClient::initI18NSpecialWords(const string &languageCode) { ucstring womenNameColIdent= string("women_name"); ucstring descColIdent= string("description"); @@ -1213,8 +1220,8 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) uint32 profile0= (uint32)ryzomGetLocalTime(); ucstring ucs; - std::string fileName = fileNames[i]; - std::string keyExtenstion = specialWords[i*3+2]; + string fileName = fileNames[i]; + string keyExtenstion = specialWords[i*3+2]; // read the ucstring and make diffs with data in ./translation/work. CReadWorkSheetFile rwsf; @@ -1250,17 +1257,17 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) for(uint j=1;j::iterator it; + std::map::iterator it; it= _SpecItem_TempMap.find( keyStr ); if ( it!=_SpecItem_TempMap.end() ) { @@ -1276,7 +1283,7 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) if(womenNameColIndex!=std::numeric_limits::max()) { const ucstring &womenName= ws.getData(j, womenNameColIndex); - _SpecItem_TempMap[keyStr].WomenName= womenName; + _SpecItem_TempMap[keyStr].WomenName= womenName.toUtf8(); // replace all \n in the women name with true \n while(strFindReplace(_SpecItem_TempMap[keyStr].WomenName, "\\n", "\n")); } @@ -1285,7 +1292,7 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) if(descColIndex!=std::numeric_limits::max()) { const ucstring &desc= ws.getData(j, descColIndex); - _SpecItem_TempMap[keyStr].Desc= desc; + _SpecItem_TempMap[keyStr].Desc= desc.toUtf8(); // replace all \n in the desc with true \n while(strFindReplace(_SpecItem_TempMap[keyStr].Desc, "\\n", "\n")); } @@ -1294,7 +1301,7 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) if(descColIndex2!=std::numeric_limits::max()) { const ucstring &desc= ws.getData(j, descColIndex2); - _SpecItem_TempMap[keyStr].Desc2= desc; + _SpecItem_TempMap[keyStr].Desc2= desc.toUtf8(); // replace all \n in the desc with true \n while(strFindReplace(_SpecItem_TempMap[keyStr].Desc2, "\\n", "\n")); } @@ -1358,7 +1365,7 @@ void CStringManagerClient::specialWordsMemoryCompress() // Make big strings _SpecItems.resize(nNbEntries); _SpecItem_Labels = new char[nLabelSize]; - _SpecItem_NameDesc = new ucchar[nNameDescSize]; + _SpecItem_NameDesc = new char[nNameDescSize]; nNbEntries = 0; nLabelSize = 0; @@ -1366,35 +1373,30 @@ void CStringManagerClient::specialWordsMemoryCompress() it = _SpecItem_TempMap.begin(); while (it != _SpecItem_TempMap.end()) { - - if (strnicmp(it->first.c_str(), "bf", 2) == 0) + if (NLMISC::startsWith(it->first.c_str(), "bf")) { uint nDbg = 0; nDbg++; } _SpecItems[nNbEntries].Label = _SpecItem_Labels+nLabelSize; - strcpy(_SpecItems[nNbEntries].Label, it->first.c_str()); + strcpy(_SpecItem_Labels+nLabelSize, it->first.c_str()); nLabelSize += (uint32)it->first.size() + 1; _SpecItems[nNbEntries].Name = _SpecItem_NameDesc+nNameDescSize; - memcpy(_SpecItems[nNbEntries].Name, it->second.Name.c_str(), 2*(it->second.Name.size()+1)); - _SpecItems[nNbEntries].Name[it->second.Name.size()] = 0; + strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.Name.c_str()); nNameDescSize += (uint32)it->second.Name.size() + 1; _SpecItems[nNbEntries].WomenName = _SpecItem_NameDesc+nNameDescSize; - memcpy(_SpecItems[nNbEntries].WomenName, it->second.WomenName.c_str(), 2*(it->second.WomenName.size()+1)); - _SpecItems[nNbEntries].WomenName[it->second.WomenName.size()] = 0; + strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.WomenName.c_str()); nNameDescSize += (uint32)it->second.WomenName.size() + 1; _SpecItems[nNbEntries].Desc = _SpecItem_NameDesc+nNameDescSize; - memcpy(_SpecItems[nNbEntries].Desc, it->second.Desc.c_str(), 2*(it->second.Desc.size()+1)); - _SpecItems[nNbEntries].Desc[it->second.Desc.size()] = 0; + strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.Desc.c_str()); nNameDescSize += (uint32)it->second.Desc.size() + 1; _SpecItems[nNbEntries].Desc2 = _SpecItem_NameDesc+nNameDescSize; - memcpy(_SpecItems[nNbEntries].Desc2, it->second.Desc2.c_str(), 2*(it->second.Desc2.size()+1)); - _SpecItems[nNbEntries].Desc2[it->second.Desc2.size()] = 0; + strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.Desc2.c_str()); nNameDescSize += (uint32)it->second.Desc2.size() + 1; nNbEntries++; @@ -1406,22 +1408,21 @@ void CStringManagerClient::specialWordsMemoryCompress() } // *************************************************************************** -const ucchar * CStringManagerClient::getSpecialWord(const std::string &label, bool women) +const char *CStringManagerClient::getSpecialWord(const string &label, bool women) { if (label.empty()) { - static ucstring emptyString; + static string emptyString; return emptyString.c_str(); } if (label[0] == '#') { - static ucstring rawString; return getLocalizedName(label.substr(1, label.size()-1)); } // avoid case problems - static std::string lwrLabel; + static string lwrLabel; lwrLabel = toLower(label); if (_SpecItem_MemoryCompressed) @@ -1456,28 +1457,26 @@ const ucchar * CStringManagerClient::getSpecialWord(const std::string &label, bo } } - static ucstring badString; - - badString = ucstring(std::string(""); - + static string badString; + badString = ""; return badString.c_str(); } // *************************************************************************** -const ucchar * CStringManagerClient::getSpecialDesc(const std::string &label) +const char *CStringManagerClient::getSpecialDesc(const string &label) { - static ucstring emptyString; + static string emptyString; if (label.empty()) return emptyString.c_str(); // avoid case problems - static std::string lwrLabel; + static string lwrLabel; lwrLabel = toLower(label); if (_SpecItem_MemoryCompressed) { CItemLight tmp; - tmp.Label = (char*)lwrLabel.c_str(); + tmp.Label = lwrLabel.c_str(); vector::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp()); if (it != _SpecItems.end()) @@ -1497,20 +1496,20 @@ const ucchar * CStringManagerClient::getSpecialDesc(const std::string &label) } // *************************************************************************** -const ucchar * CStringManagerClient::getSpecialDesc2(const std::string &label) +const char *CStringManagerClient::getSpecialDesc2(const string &label) { - static ucstring emptyString; + static string emptyString; if (label.empty()) return emptyString.c_str(); // avoid case problems - static std::string lwrLabel; + static string lwrLabel; lwrLabel = toLower(label); if (_SpecItem_MemoryCompressed) { CItemLight tmp; - tmp.Label = (char*)lwrLabel.c_str(); + tmp.Label = lwrLabel.c_str(); vector::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp()); if (it != _SpecItems.end()) @@ -1539,87 +1538,88 @@ const ucchar * CStringManagerClient::getSpecialDesc2(const std::string &label) */ // *************************************************************************** -const ucchar *CStringManagerClient::getPlaceLocalizedName(const string &placeNameID) +const char *CStringManagerClient::getPlaceLocalizedName(const string &placeNameID) { return getSpecialWord(placeNameID); } // *************************************************************************** -const ucchar *CStringManagerClient::getFactionLocalizedName(const string &factionNameID) +const char *CStringManagerClient::getFactionLocalizedName(const string &factionNameID) { return getSpecialWord(factionNameID); } // *************************************************************************** -const ucchar *CStringManagerClient::getSkillLocalizedName(SKILLS::ESkills e) +const char *CStringManagerClient::getSkillLocalizedName(SKILLS::ESkills e) { return getSpecialWord(SKILLS::toString(e)); } // *************************************************************************** -const ucchar *CStringManagerClient::getItemLocalizedName(CSheetId id) +const char *CStringManagerClient::getItemLocalizedName(CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getCreatureLocalizedName(NLMISC::CSheetId id) +const char *CStringManagerClient::getCreatureLocalizedName(NLMISC::CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSBrickLocalizedName(NLMISC::CSheetId id) +const char *CStringManagerClient::getSBrickLocalizedName(NLMISC::CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSPhraseLocalizedName(NLMISC::CSheetId id) +const char *CStringManagerClient::getSPhraseLocalizedName(NLMISC::CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -/*const ucchar *CStringManagerClient::getBrickLocalizedDescription(BRICK_FAMILIES::TBrickFamily e) +/*const char *CStringManagerClient::getBrickLocalizedDescription(BRICK_FAMILIES::TBrickFamily e) { return getSpecialDesc(BRICK_FAMILIES::toString(e)); } */ // *************************************************************************** -const ucchar *CStringManagerClient::getSkillLocalizedDescription(SKILLS::ESkills e) +const char *CStringManagerClient::getSkillLocalizedDescription(SKILLS::ESkills e) { return getSpecialDesc(SKILLS::toString(e)); } // *************************************************************************** -const ucchar *CStringManagerClient::getItemLocalizedDescription(CSheetId id) +const char *CStringManagerClient::getItemLocalizedDescription(CSheetId id) { return getSpecialDesc(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSBrickLocalizedDescription(NLMISC::CSheetId id) +const char *CStringManagerClient::getSBrickLocalizedDescription(NLMISC::CSheetId id) { return getSpecialDesc(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSBrickLocalizedCompositionDescription(NLMISC::CSheetId id) +const char *CStringManagerClient::getSBrickLocalizedCompositionDescription(NLMISC::CSheetId id) { return getSpecialDesc2(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSPhraseLocalizedDescription(NLMISC::CSheetId id) +const char *CStringManagerClient::getSPhraseLocalizedDescription(NLMISC::CSheetId id) { return getSpecialDesc(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getTitleLocalizedName(const ucstring &titleId, bool women) +const char *CStringManagerClient::getTitleLocalizedName(const string &titleId, bool women) { - vector listInfos = getTitleInfos(titleId, women); + vector listInfos = getTitleInfos(titleId, women); + if (!listInfos.empty()) { _TitleWords.push_back(listInfos[0]); @@ -1661,18 +1661,18 @@ const ucchar *CStringManagerClient::getLocalizedName(const ucstring &uctext) } // *************************************************************************** -vector CStringManagerClient::getTitleInfos(const ucstring &titleId, bool women) +vector CStringManagerClient::getTitleInfos(const string &titleId, bool women) { //ucstring infosUC; //infosUC.fromUtf8(titleId); - vector listInfos; - splitUCString(titleId, ucstring("#"), listInfos); + vector listInfos; + splitString(titleId, string("#"), listInfos); if (!listInfos.empty()) { if (titleId[0] != '#') { - listInfos[0] = getSpecialWord(listInfos[0].toUtf8(), women); + listInfos[0] = getSpecialWord(listInfos[0], women); } } @@ -1680,74 +1680,76 @@ vector CStringManagerClient::getTitleInfos(const ucstring &titleId, bo } // *************************************************************************** -const ucchar *CStringManagerClient::getClassificationTypeLocalizedName(EGSPD::CClassificationType::TClassificationType type) +const char *CStringManagerClient::getClassificationTypeLocalizedName(EGSPD::CClassificationType::TClassificationType type) { return getSpecialDesc(EGSPD::CClassificationType::toString(type)); } // *************************************************************************** -const ucchar *CStringManagerClient::getOutpostLocalizedName(NLMISC::CSheetId id) +const char *CStringManagerClient::getOutpostLocalizedName(NLMISC::CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getOutpostLocalizedDescription(NLMISC::CSheetId id) +const char *CStringManagerClient::getOutpostLocalizedDescription(NLMISC::CSheetId id) { return getSpecialDesc(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getOutpostBuildingLocalizedName(NLMISC::CSheetId id) +const char *CStringManagerClient::getOutpostBuildingLocalizedName(NLMISC::CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id) +const char *CStringManagerClient::getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id) { return getSpecialDesc(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSquadLocalizedName(NLMISC::CSheetId id) +const char *CStringManagerClient::getSquadLocalizedName(NLMISC::CSheetId id) { return getSpecialWord(id.toString()); } // *************************************************************************** -const ucchar *CStringManagerClient::getSquadLocalizedDescription(NLMISC::CSheetId id) +const char *CStringManagerClient::getSquadLocalizedDescription(NLMISC::CSheetId id) { return getSpecialDesc(id.toString()); } // *************************************************************************** -void CStringManagerClient::replaceDynString(const ucstring &name, const ucstring &text) +void CStringManagerClient::replaceDynString(const std::string &name, const std::string &text) { _DynStrings[name] = text; } // *************************************************************************** -void CStringManagerClient::replaceSBrickName(NLMISC::CSheetId id, const ucstring &name, const ucstring &desc, const ucstring &desc2) +void CStringManagerClient::replaceSBrickName(NLMISC::CSheetId id, const std::string &name, const std::string &desc, const std::string &desc2) { - std::string label= id.toString(); + string label= id.toString(); if (label.empty()) { return; } // avoid case problems - static std::string lwrLabel; + static string lwrLabel; lwrLabel = toLower(label); + nlassert(!_SpecItem_MemoryCompressed); // Not allowed, strings are released! if (_SpecItem_MemoryCompressed) { - ucchar *strName = (ucchar *)name.c_str(); - ucchar *strDesc = (ucchar *)desc.c_str(); - ucchar *strDesc2 = (ucchar *)desc2.c_str(); +#if 0 + const char *strName = name.c_str(); + const char *strDesc = desc.c_str(); + const char *strDesc2 = desc2.c_str(); CItemLight tmp; - tmp.Label = (char*)lwrLabel.c_str(); + tmp.Label = lwrLabel.c_str(); vector::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp()); if (it != _SpecItems.end()) @@ -1773,6 +1775,7 @@ void CStringManagerClient::replaceSBrickName(NLMISC::CSheetId id, const ucstring tmp.Desc2 = strDesc2; _SpecItems.push_back(tmp); } +#endif } else { diff --git a/ryzom/client/src/string_manager_client.h b/ryzom/client/src/string_manager_client.h index 971d808b3..5179318f4 100644 --- a/ryzom/client/src/string_manager_client.h +++ b/ryzom/client/src/string_manager_client.h @@ -63,15 +63,16 @@ public: // Force the cache to be saved void flushStringCache(); - bool getString(uint32 stringId, std::string &result) { ucstring temp; bool res = getString(stringId, temp); result = temp.toUtf8(); return res; } // FIXME: UTF-8 - bool getString(uint32 stringId, ucstring &result); - void waitString(uint32 stringId, const IStringWaiterRemover *premover, ucstring *result); + bool getString(uint32 stringId, std::string &result); + bool getString(uint32 stringId, ucstring &result) { std::string temp; bool res = getString(stringId, temp); result.fromUtf8(temp); return res; } // FIXME: UTF-8 + void waitString(uint32 stringId, const IStringWaiterRemover *premover, std::string *result); void waitString(uint32 stringId, IStringWaitCallback *pcallback); - bool getDynString(uint32 dynStringId, ucstring &result); - void waitDynString(uint32 stringId, const IStringWaiterRemover *premover, ucstring *result); + bool getDynString(uint32 dynStringId, std::string &result); + bool getDynString(uint32 dynStringId, ucstring &result) { std::string temp; bool res = getString(dynStringId, temp); result.fromUtf8(temp); return res; } // FIXME: UTF-8 + void waitDynString(uint32 stringId, const IStringWaiterRemover *premover, std::string *result); void waitDynString(uint32 stringId, IStringWaitCallback *pcallback); - void receiveString(uint32 stringId, const ucstring &str); + void receiveString(uint32 stringId, const std::string &str); void receiveDynString(NLMISC::CBitMemStream &bms); void releaseDynString(uint32 stringId); @@ -80,55 +81,55 @@ public: static void initI18NSpecialWords(const std::string &languageCode); static void specialWordsMemoryCompress(); // Yoyo: Replace the Brick Name with Filled stats (CSBrickManager work). No-Op if not found - static void replaceSBrickName(NLMISC::CSheetId id, const ucstring &name, const ucstring &desc, const ucstring &desc2); - static void replaceDynString(const ucstring &name, const ucstring &text); + static void replaceSBrickName(NLMISC::CSheetId id, const std::string &name, const std::string &desc, const std::string &desc2); + static void replaceDynString(const std::string &name, const std::string &text); // Get the Localized Name of the Places. - static const ucchar *getPlaceLocalizedName(const std::string &placeNameID); + static const char *getPlaceLocalizedName(const std::string &placeNameID); // Get the Localized Name of the faction (for the fame) - static const ucchar *getFactionLocalizedName(const std::string &factionNameID); + static const char *getFactionLocalizedName(const std::string &factionNameID); // Get the Localized Name of the Skill. - static const ucchar *getSkillLocalizedName(SKILLS::ESkills e); + static const char *getSkillLocalizedName(SKILLS::ESkills e); // Get the Localized Name of the Item. - static const ucchar *getItemLocalizedName(NLMISC::CSheetId id); + static const char *getItemLocalizedName(NLMISC::CSheetId id); // Get the Localized Name of the Creature. - static const ucchar *getCreatureLocalizedName(NLMISC::CSheetId id); + static const char *getCreatureLocalizedName(NLMISC::CSheetId id); // Get the Localized Name of the SBrick. - static const ucchar *getSBrickLocalizedName(NLMISC::CSheetId id); + static const char *getSBrickLocalizedName(NLMISC::CSheetId id); // Get the Localized Name of the SPhrase. - static const ucchar *getSPhraseLocalizedName(NLMISC::CSheetId id); + static const char *getSPhraseLocalizedName(NLMISC::CSheetId id); // Get the Localized Description of the Skill. - static const ucchar *getSkillLocalizedDescription(SKILLS::ESkills e); + static const char *getSkillLocalizedDescription(SKILLS::ESkills e); // Get the Localized Descriptionof the Item. - static const ucchar *getItemLocalizedDescription(NLMISC::CSheetId id); + static const char *getItemLocalizedDescription(NLMISC::CSheetId id); // Get the Localized Description of the SBrick. - static const ucchar *getSBrickLocalizedDescription(NLMISC::CSheetId id); + static const char *getSBrickLocalizedDescription(NLMISC::CSheetId id); // Get the Localized Composition Description of the SBrick. - static const ucchar *getSBrickLocalizedCompositionDescription(NLMISC::CSheetId id); + static const char *getSBrickLocalizedCompositionDescription(NLMISC::CSheetId id); // Get the Localized Description of the SPhrase. - static const ucchar *getSPhraseLocalizedDescription(NLMISC::CSheetId id); + static const char *getSPhraseLocalizedDescription(NLMISC::CSheetId id); // Get the Localized Title name - static const ucchar *getTitleLocalizedName(const ucstring &titleId, bool women); - static const ucchar *getLocalizedName(const ucstring &text); - static std::vector getTitleInfos(const ucstring &titleId, bool women); + static const char *getTitleLocalizedName(const std::string &titleId, bool women); + static const char *getLocalizedName(const std::string &text); + static std::vector getTitleInfos(const std::string &titleId, bool women); // Get the Localized name of a classification type - static const ucchar *getClassificationTypeLocalizedName(EGSPD::CClassificationType::TClassificationType type); + static const char *getClassificationTypeLocalizedName(EGSPD::CClassificationType::TClassificationType type); // Outpost name - static const ucchar *getOutpostLocalizedName(NLMISC::CSheetId id); + static const char *getOutpostLocalizedName(NLMISC::CSheetId id); // Outpost description - static const ucchar *getOutpostLocalizedDescription(NLMISC::CSheetId id); + static const char *getOutpostLocalizedDescription(NLMISC::CSheetId id); // Outpost building name - static const ucchar *getOutpostBuildingLocalizedName(NLMISC::CSheetId id); + static const char *getOutpostBuildingLocalizedName(NLMISC::CSheetId id); // Outpost building description - static const ucchar *getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id); + static const char *getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id); // Squad name - static const ucchar *getSquadLocalizedName(NLMISC::CSheetId id); + static const char *getSquadLocalizedName(NLMISC::CSheetId id); // Squad description - static const ucchar *getSquadLocalizedDescription(NLMISC::CSheetId id); + static const char *getSquadLocalizedDescription(NLMISC::CSheetId id); private: // constructor. @@ -153,8 +154,8 @@ private: struct TParamValue { - TParamType Type; - ucstring::size_type ReplacementPoint; + TParamType Type; + std::string::size_type ReplacementPoint; union { uint32 StringId; @@ -177,7 +178,7 @@ private: NLMISC::CBitMemStream Message; uint32 StringId; std::vector Params; - ucstring String; + std::string String; }; enum @@ -189,7 +190,7 @@ private: struct TStringWaiter { /// Pointer to the ucstring to fill - ucstring *Result; + std::string *Result; /// Pointer to the remover that contains this string reference const IStringWaiterRemover *Remover; }; @@ -198,7 +199,7 @@ private: /// Container for simple strings - typedef CHashMap TStringsContainer; + typedef CHashMap TStringsContainer; /// Container for dyn strings typedef CHashMap TDynStringsContainer; /// Container of string reference waiting for value. @@ -224,7 +225,7 @@ private: TStringCallbacksContainer _DynStringsCallbacks; // Return value for waiting string.. - static ucstring _WaitString; + static std::string _WaitString; // Singleton pattern implementation static CStringManagerClient *_Instance; @@ -247,7 +248,7 @@ private: struct CCacheString { uint32 StringId; - ucstring String; + std::string String; }; std::vector _CacheStringToSave; //@} @@ -257,41 +258,60 @@ private: { public: // The Name of the item - ucstring Name; + std::string Name; // The Women Name of the item - ucstring WomenName; + std::string WomenName; // Description of the item - ucstring Desc; + std::string Desc; // Optional Second description (For SBrick composition for example) - ucstring Desc2; + std::string Desc2; void serial(NLMISC::IStream &f) { - sint ver= f.serialVersion(1); - f.serial(Name); - if (ver >= 1) + sint ver = f.serialVersion(2); + if (ver >= 2) + { + f.serial(Name); f.serial(WomenName); - f.serial(Desc); - f.serial(Desc2); + f.serial(Desc); + f.serial(Desc2); + } + else + { + nlassert(f.isReading()); + ucstring name; + ucstring womenName; + ucstring desc; + ucstring desc2; + f.serial(name); + if (ver >= 1) + f.serial(womenName); + f.serial(desc); + f.serial(desc2); + Name = name.toUtf8(); + WomenName = womenName.toUtf8(); + Desc = desc.toUtf8(); + Desc2 = desc2.toUtf8(); + } } }; static bool _SpecItem_MemoryCompressed; static std::map _SpecItem_TempMap; - static std::vector _TitleWords; - static std::map _DynStrings; + static std::vector _TitleWords; + static std::map _DynStrings; static char *_SpecItem_Labels; - static ucchar *_SpecItem_NameDesc; + static char *_SpecItem_NameDesc; struct CItemLight { - char *Label; - ucchar *Name; - ucchar *WomenName; - ucchar *Desc; - ucchar *Desc2; + const char *Label; + const char *Name; + const char *WomenName; + const char *Desc; + const char *Desc2; }; struct CItemLightComp { @@ -303,9 +323,9 @@ private: static std::vector _SpecItems; - static const ucchar *getSpecialWord(const std::string &label, bool women = false); - static const ucchar *getSpecialDesc(const std::string &label); - static const ucchar *getSpecialDesc2(const std::string &label); + static const char *getSpecialWord(const std::string &label, bool women = false); + static const char *getSpecialDesc(const std::string &label); + static const char *getSpecialDesc2(const std::string &label); // Check Files for the Packed string. class CFileCheck @@ -381,9 +401,9 @@ class IStringWaitCallback { public: /// Overide this method to receive callback for string. - virtual void onStringAvailable(uint /* stringId */, const ucstring &/* value */) {} + virtual void onStringAvailable(uint /* stringId */, const std::string &/* value */) {} /// Overide this method to receive callback for dynamic string. - virtual void onDynStringAvailable(uint /* stringId */, const ucstring &/* value */) {} + virtual void onDynStringAvailable(uint /* stringId */, const std::string &/* value */) {} virtual ~IStringWaitCallback() {