UTF-8 string manager, ryzom/ryzomcore#335

develop
kaetemi 4 years ago
parent 246ea2f603
commit 9d534882e8

@ -1385,14 +1385,14 @@ NLMISC_COMMAND(setItemName, "set name of items, sbrick, etc..","<sheet_id> <name
{ {
if (args.size() < 2) return false; if (args.size() < 2) return false;
CSheetId id(args[0]); CSheetId id(args[0]);
ucstring name; string name;
name.fromUtf8(args[1]); name = args[1];
ucstring desc; string desc;
ucstring desc2; string desc2;
if (args.size() > 2) if (args.size() > 2)
desc.fromUtf8(args[2]); desc = args[2];
if (args.size() > 3) if (args.size() > 3)
desc2.fromUtf8(args[3]); desc2 = args[3];
STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance();
if (pSMC) if (pSMC)
@ -1406,10 +1406,10 @@ NLMISC_COMMAND(setItemName, "set name of items, sbrick, etc..","<sheet_id> <name
NLMISC_COMMAND(setMissingDynstringText, "set text of missing dynamic string"," <name> <text>") NLMISC_COMMAND(setMissingDynstringText, "set text of missing dynamic string"," <name> <text>")
{ {
if (args.size() < 2) return false; if (args.size() < 2) return false;
ucstring name; string name;
name.fromUtf8(args[0]); name = args[0];
ucstring text; string text;
text.fromUtf8(args[1]); text = args[1];
STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance();
if (pSMC) if (pSMC)
@ -1459,7 +1459,7 @@ NLMISC_COMMAND(ah, "Launch an action handler", "<ActionHandler> <AHparam>")
static void setDynString(uint32 strID, const std::string &value) static void setDynString(uint32 strID, const std::string &value)
{ {
STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance();
pSMC->receiveString(strID, ucstring(value)); pSMC->receiveString(strID, value);
CBitMemStream bm; CBitMemStream bm;
if (bm.isReading()) bm.invert(); if (bm.isReading()) bm.invert();
bm.serial(strID); bm.serial(strID);

@ -2262,32 +2262,32 @@ void CEntityCL::load() // virtual
// onStringAvailable : // onStringAvailable :
// Callback when the name is arrived. // 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 // remove the shard name if possible
_EntityName= removeShardFromName(_EntityName); _EntityName= removeShardFromName(_EntityName);
// New title // New title
ucstring newtitle; string newtitle;
_HasReservedTitle = false; _HasReservedTitle = false;
// check if there is any replacement tag in the string // 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) if (p1 != ucstring::npos)
{ {
// we found a replacement point begin tag // 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) if (p2 != ucstring::npos)
{ {
// ok, we have the second replacement point! // ok, we have the second replacement point!
// extract the replacement id // 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 // retrieve the translated string
_TitleRaw = id.toString(); _TitleRaw = id;
// ucstring replacement = CI18N::get(strNewTitle); // string replacement = CI18N::get(strNewTitle);
bool womanTitle = false; bool womanTitle = false;
CCharacterCL * c = dynamic_cast<CCharacterCL*>(this); CCharacterCL * c = dynamic_cast<CCharacterCL*>(this);
if(c) if(c)
@ -2295,22 +2295,21 @@ void CEntityCL::onStringAvailable(uint /* stringId */, const ucstring &value)
womanTitle = ( c->getGender() == GSGENDER::female ); 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 // Sometimes translation contains another title
{ {
ucstring::size_type pos = replacement.find('$'); string::size_type pos = replacement.find('$');
if (pos != ucstring::npos) if (pos != ucstring::npos)
{ {
ucstring sn = replacement; _EntityName = _EntityName = STRING_MANAGER::CStringManagerClient::getLocalizedName(sn.substr(0, pos));
_EntityName = sn.substr(0, pos).toUtf8(); string::size_type pos2 = replacement.find('$', pos + 1);
ucstring::size_type pos2 = sn.find('$', pos + 1); _TitleRaw = replacement.substr(pos+1, pos2 - pos - 1);
_TitleRaw = sn.substr(pos+1, pos2 - pos - 1); replacement = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw.toUtf8(), womanTitle);
replacement = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(_TitleRaw, womanTitle);
} }
} }
_Tags = STRING_MANAGER::CStringManagerClient::getTitleInfos(_TitleRaw, womanTitle); _Tags = STRING_MANAGER::CStringManagerClient::getTitleInfos(_TitleRaw.toUtf8(), womanTitle);
if (!replacement.empty() || !ClientCfg.DebugStringManager) 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) _EntityName = STRING_MANAGER::CStringManagerClient::getLocalizedName(_EntityName.substr(0, p1)); // + _Name.substr(p2+1)
// Get extended name // Get extended name
_NameEx = replacement; _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 ) if ( titleEnum >= CHARACTER_TITLE::BeginGmTitle && titleEnum <= CHARACTER_TITLE::EndGmTitle )
{ {
_GMTitle = titleEnum - CHARACTER_TITLE::BeginGmTitle; _GMTitle = titleEnum - CHARACTER_TITLE::BeginGmTitle;
@ -2359,7 +2358,7 @@ void CEntityCL::onStringAvailable(uint /* stringId */, const ucstring &value)
if (pGC != NULL) pGC->setUCTitle(_EntityName); if (pGC != NULL) pGC->setUCTitle(_EntityName);
CSkillManager *pSM = CSkillManager::getInstance(); CSkillManager *pSM = CSkillManager::getInstance();
pSM->setPlayerTitle(_TitleRaw.toString()); pSM->setPlayerTitle(_TitleRaw.toUtf8());
} }
// Must rebuild the in scene interface 'cause name has changed // Must rebuild the in scene interface 'cause name has changed

@ -935,7 +935,7 @@ protected:
// Current entity title // Current entity title
ucstring _Title; ucstring _Title;
// Current entity tags // Current entity tags
std::vector<ucstring> _Tags; std::vector<std::string> _Tags;
// Current entity title string id // Current entity title string id
ucstring _TitleRaw; ucstring _TitleRaw;
// Current permanent content symbol for the entity // Current permanent content symbol for the entity
@ -1222,7 +1222,7 @@ public:
private: private:
// Override for string reception callback // Override for string reception callback
virtual void onStringAvailable(uint stringId, const ucstring &value); virtual void onStringAvailable(uint stringId, const std::string &value);
}; };

@ -536,10 +536,10 @@ void CForageSourceCL::updateVisualPropertyVisualFX(const NLMISC::TGameCycle &/*
void CForageSourceCL::updateVisualPropertyName(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop) void CForageSourceCL::updateVisualPropertyName(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop)
{ {
CSheetId rmSheetId( (const uint32&)prop ); CSheetId rmSheetId( (const uint32&)prop );
const ucchar *name = STRING_MANAGER::CStringManagerClient::getItemLocalizedName( rmSheetId ); const char *name = STRING_MANAGER::CStringManagerClient::getItemLocalizedName( rmSheetId );
if ( name ) if ( name )
{ {
_EntityName = ucstring(name).toUtf8(); _EntityName = name;
if ( _ProspectorSlot != 255 ) if ( _ProspectorSlot != 255 )
{ {
CEntityCL *prospector = EntitiesMngr.entities()[_ProspectorSlot]; CEntityCL *prospector = EntitiesMngr.entities()[_ProspectorSlot];

@ -693,7 +693,7 @@ class CHandlerOpenTitleHelp : public IActionHandler
// retrieve the translated string // retrieve the translated string
if (!strNewTitle.empty()) if (!strNewTitle.empty())
name = ucstring(STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(ucstring::makeFromUtf8(strNewTitle), woman)).toUtf8(); name = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(strNewTitle, woman);
else else
name.clear(); name.clear();
} }
@ -752,7 +752,7 @@ class CHandlerOpenTitleHelp : public IActionHandler
for (titleIDnb = 0; titleIDnb < CHARACTER_TITLE::NB_CHARACTER_TITLE; ++titleIDnb) for (titleIDnb = 0; titleIDnb < CHARACTER_TITLE::NB_CHARACTER_TITLE; ++titleIDnb)
{ {
bool women = UserEntity && UserEntity->getGender()==GSGENDER::female; 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; break;
} }

@ -916,7 +916,7 @@ NLMISC_COMMAND(slsn, "Temp : set the name of the last sender.", "<name>")
bool CStringPostProcessRemoveName::cbIDStringReceived(ucstring &inOut) bool CStringPostProcessRemoveName::cbIDStringReceived(ucstring &inOut)
{ {
// extract the replacement id // extract the replacement id
ucstring strNewTitle = CEntityCL::getTitleFromName(inOut.toUtf8()); string strNewTitle = CEntityCL::getTitleFromName(inOut.toUtf8());
// retrieve the translated string // retrieve the translated string
if (!strNewTitle.empty()) if (!strNewTitle.empty())

@ -1047,12 +1047,12 @@ REGISTER_ACTION_HANDLER( CHandlerSetCompassNorth, "set_compass_north");
class CCompassDialogsStringCallback : public IStringWaitCallback 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(); uint size = (uint)CCompassDialogsManager::getInstance()._Entries.size();
for ( uint i = 0; i < size; i++) for ( uint i = 0; i < size; i++)
{ {
ucstring name; std::string name;
if ( CStringManagerClient::instance()->getDynString(CCompassDialogsManager::getInstance()._Entries[i].Text, name) ) if ( CStringManagerClient::instance()->getDynString(CCompassDialogsManager::getInstance()._Entries[i].Text, name) )
{ {
if ( value == name ) if ( value == name )

@ -436,7 +436,7 @@ void CSBrickManager::compileBrickProperties()
// **** for all bricks, recompute localized text with formated version // **** for all bricks, recompute localized text with formated version
ucstring textTemp; string textTemp;
textTemp.reserve(1000); textTemp.reserve(1000);
for (std::vector<CSBrickSheet *>::size_type ib = 0; ib < _BrickVector.size(); ++ib) for (std::vector<CSBrickSheet *>::size_type ib = 0; ib < _BrickVector.size(); ++ib)
{ {
@ -445,7 +445,7 @@ void CSBrickManager::compileBrickProperties()
continue; continue;
// Get the Brick texts // Get the Brick texts
ucstring texts[3]; std::string texts[3];
texts[0]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedName(brickSheet->Id); texts[0]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedName(brickSheet->Id);
texts[1]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedDescription(brickSheet->Id); texts[1]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedDescription(brickSheet->Id);
texts[2]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedCompositionDescription(brickSheet->Id); texts[2]= STRING_MANAGER::CStringManagerClient::getSBrickLocalizedCompositionDescription(brickSheet->Id);
@ -453,7 +453,7 @@ void CSBrickManager::compileBrickProperties()
// For alls texts, parse format // For alls texts, parse format
for(uint i=0;i<3;i++) for(uint i=0;i<3;i++)
{ {
ucstring &text= texts[i]; string &text= texts[i];
textTemp.erase(); textTemp.erase();
// Parse the text // Parse the text

@ -2299,11 +2299,9 @@ void impulsePhraseSend(NLMISC::CBitMemStream &impulse)
void impulseStringResp(NLMISC::CBitMemStream &impulse) void impulseStringResp(NLMISC::CBitMemStream &impulse)
{ {
uint32 stringId; uint32 stringId;
string strUtf8; string str;
impulse.serial(stringId); impulse.serial(stringId);
impulse.serial(strUtf8); impulse.serial(str);
ucstring str;
str.fromUtf8(strUtf8);
if (PermanentlyBanned) return; if (PermanentlyBanned) return;
@ -3390,7 +3388,7 @@ private:
public: public:
// called when the string is available // 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 // don't care if already displayed
if(_AlreadyDisplayed) if(_AlreadyDisplayed)

@ -743,7 +743,7 @@ void CPlayerCL::updateVisualPropertyVpa(const NLMISC::TGameCycle &/* gameCycle *
} }
// update title when gender changed // 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) if (!replacement.empty() || !ClientCfg.DebugStringManager)
{ {
// Get extended name // Get extended name

@ -446,7 +446,7 @@ void CPlayerR2CL::updateVisualPropertyVpa(const NLMISC::TGameCycle &/* gameCycle
} }
// update title when gender changed // 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()) if (!replacement.empty())
{ {
// Get extended name // Get extended name

@ -39,17 +39,17 @@ namespace STRING_MANAGER
// *************************************************************************** // ***************************************************************************
map<string, CStringManagerClient::CItem> CStringManagerClient::_SpecItem_TempMap; map<string, CStringManagerClient::CItem> CStringManagerClient::_SpecItem_TempMap;
map<ucstring, ucstring> CStringManagerClient::_DynStrings; map<string, string> CStringManagerClient::_DynStrings;
vector<ucstring> CStringManagerClient::_TitleWords; vector<string> CStringManagerClient::_TitleWords;
bool CStringManagerClient::_SpecItem_MemoryCompressed = false; bool CStringManagerClient::_SpecItem_MemoryCompressed = false;
char *CStringManagerClient::_SpecItem_Labels = NULL; char *CStringManagerClient::_SpecItem_Labels = NULL;
ucchar *CStringManagerClient::_SpecItem_NameDesc = NULL; char *CStringManagerClient::_SpecItem_NameDesc = NULL;
vector<CStringManagerClient::CItemLight> CStringManagerClient::_SpecItems; vector<CStringManagerClient::CItemLight> CStringManagerClient::_SpecItems;
bool MustReleaseStaticArrays = true; bool MustReleaseStaticArrays = true;
CStringManagerClient *CStringManagerClient::_Instance= NULL; CStringManagerClient *CStringManagerClient::_Instance= NULL;
ucstring CStringManagerClient::_WaitString("???"); string CStringManagerClient::_WaitString("???");
CStringManagerClient::CStringManagerClient() CStringManagerClient::CStringManagerClient()
@ -57,7 +57,7 @@ namespace STRING_MANAGER
_CacheInited = false; _CacheInited = false;
_CacheLoaded = false; _CacheLoaded = false;
// insert the empty string. // 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 // reserve some place to avoid reallocation as possible
_CacheStringToSave.reserve(1024); _CacheStringToSave.reserve(1024);
} }
@ -122,6 +122,7 @@ namespace STRING_MANAGER
{ {
try try
{ {
const uint currentVersion = 1;
_CacheFilename = std::string("save/") + _ShardId.substr(0, _ShardId.find(":")) + ".string_cache"; _CacheFilename = std::string("save/") + _ShardId.substr(0, _ShardId.find(":")) + ".string_cache";
nlinfo("SM : Try to open the string cache : %s", _CacheFilename.c_str()); 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 // there is a cache file, check date reset it if needed
{ {
NLMISC::CIFile file(_CacheFilename); NLMISC::CIFile file(_CacheFilename);
file.setVersionException(false, false);
file.serialVersion(currentVersion);
file.serial(_Timestamp); file.serial(_Timestamp);
} }
@ -139,6 +142,7 @@ namespace STRING_MANAGER
nlinfo("SM: Clearing string cache : outofdate"); nlinfo("SM: Clearing string cache : outofdate");
// the cache is not sync, reset it // the cache is not sync, reset it
NLMISC::COFile file(_CacheFilename); NLMISC::COFile file(_CacheFilename);
file.serialVersion(currentVersion);
file.serial(timestamp); file.serial(timestamp);
} }
else else
@ -151,6 +155,7 @@ namespace STRING_MANAGER
nlinfo("SM: Creating string cache"); nlinfo("SM: Creating string cache");
// cache file don't exist, create it with the timestamp // cache file don't exist, create it with the timestamp
NLMISC::COFile file(_CacheFilename); NLMISC::COFile file(_CacheFilename);
file.serialVersion(currentVersion);
file.serial(timestamp); file.serial(timestamp);
} }
@ -160,17 +165,19 @@ namespace STRING_MANAGER
// NB : we keep the waiting strings and dyn strings // NB : we keep the waiting strings and dyn strings
// insert the empty string. // insert the empty string.
_ReceivedStrings.insert(make_pair((uint)EmptyStringId, ucstring())); _ReceivedStrings.insert(make_pair((uint)EmptyStringId, string()));
// load the cache file // load the cache file
NLMISC::CIFile file(_CacheFilename); NLMISC::CIFile file(_CacheFilename);
int version = file.serialVersion(currentVersion);
file.serial(_Timestamp); file.serial(_Timestamp);
nlassert(_Timestamp == timestamp); nlassert(_Timestamp == timestamp);
nlassert(version >= 1); // Initial version
while (!file.eof()) while (!file.eof())
{ {
uint32 id; uint32 id;
ucstring str; string str;
file.serial(id); file.serial(id);
file.serial(str); 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 ) H_AUTO( CStringManagerClient_waitString )
nlassert(premover && result); nlassert(premover && result);
ucstring value; string value;
if (getString(stringId, value)) if (getString(stringId, value))
*result = value; *result = value;
else else
@ -217,7 +224,7 @@ namespace STRING_MANAGER
H_AUTO( CStringManagerClient_waitString2 ) H_AUTO( CStringManagerClient_waitString2 )
nlassert(pcallback != 0); nlassert(pcallback != 0);
ucstring value; string value;
if (getString(stringId, value)) if (getString(stringId, value))
{ {
pcallback->onStringAvailable(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 ) H_AUTO( CStringManagerClient_waitDynString )
nlassert(premover && result); nlassert(premover && result);
ucstring value; string value;
if (getDynString(stringId, value)) if (getDynString(stringId, value))
*result = value; *result = value;
else else
@ -253,7 +260,7 @@ namespace STRING_MANAGER
H_AUTO( CStringManagerClient_waitDynString2 ) H_AUTO( CStringManagerClient_waitDynString2 )
nlassert(pcallback != 0); nlassert(pcallback != 0);
ucstring value; string value;
if (getDynString(stringId, value)) if (getDynString(stringId, value))
{ {
pcallback->onDynStringAvailable(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 ) H_AUTO( CStringManagerClient_getString )
@ -357,7 +364,7 @@ restartLoop4:
_WaitingStrings.insert(stringId); _WaitingStrings.insert(stringId);
// need to ask for this string. // need to ask for this string.
NLMISC::CBitMemStream bms; NLMISC::CBitMemStream bms;
const std::string msgType = "STRING_MANAGER:STRING_RQ"; const string msgType = "STRING_MANAGER:STRING_RQ";
if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) ) if( GenericMsgHeaderMngr.pushNameToStream(msgType,bms) )
{ {
bms.serial( stringId ); bms.serial( stringId );
@ -374,7 +381,7 @@ restartLoop4:
{ {
char tmp[1024]; char tmp[1024];
sprintf(tmp, "<WAIT STR %u>", stringId); sprintf(tmp, "<WAIT STR %u>", stringId);
result = ucstring(tmp); result = tmp;
} }
else else
result.erase(); // = _WaitString; result.erase(); // = _WaitString;
@ -385,14 +392,14 @@ restartLoop4:
{ {
char tmp[1024]; char tmp[1024];
sprintf(tmp, "<STR %u>", stringId); sprintf(tmp, "<STR %u>", stringId);
result = ucstring(tmp) + it->second; result = tmp + it->second;
} }
else else
{ {
result = it->second; result = it->second;
if (result.size() > 9 && result.substr(0, 9) == ucstring("<missing:")) if (result.size() > 9 && result.substr(0, 9) == "<missing:")
{ {
map<ucstring, ucstring>::iterator itds = _DynStrings.find(result.substr(9, result.size()-10)); map<string, string>::iterator itds = _DynStrings.find(result.substr(9, result.size()-10));
if (itds != _DynStrings.end()) if (itds != _DynStrings.end())
result = itds->second; result = itds->second;
} }
@ -402,7 +409,7 @@ restartLoop4:
return true; return true;
} }
void CStringManagerClient::receiveString(uint32 stringId, const ucstring &str) void CStringManagerClient::receiveString(uint32 stringId, const string &str)
{ {
H_AUTO( CStringManagerClient_receiveString ) H_AUTO( CStringManagerClient_receiveString )
@ -419,8 +426,8 @@ restartLoop4:
TStringsContainer::iterator it(_ReceivedStrings.find(stringId)); TStringsContainer::iterator it(_ReceivedStrings.find(stringId));
nlwarning("Receiving stringID %u (%s), already in received string (%s), replacing with new value.", nlwarning("Receiving stringID %u (%s), already in received string (%s), replacing with new value.",
stringId, stringId,
str.toString().c_str(), str.c_str(),
it->second.toString().c_str()); it->second.c_str());
if (it->second != str) if (it->second != str)
it->second = str; it->second = str;
@ -484,7 +491,7 @@ restartLoop:
last = _WaitingDynStrings.end(); last = _WaitingDynStrings.end();
for (; first != last; ++first) for (; first != last; ++first)
{ {
ucstring value; string value;
uint number = first->first; uint number = first->first;
/// Warning: if getDynString() return true, 'first' is erased => don't use it after in this loop /// Warning: if getDynString() return true, 'first' is erased => don't use it after in this loop
if (getDynString(number, value)) if (getDynString(number, value))
@ -616,7 +623,7 @@ restartLoop:
return false; return false;
} }
// ok, we have the base string, we can serial the parameters // 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) for (; first != last; ++first)
{ {
if (*first == '%') if (*first == '%')
@ -699,10 +706,10 @@ restartLoop:
if (dynInfo.Status == TDynStringInfo::serialized) if (dynInfo.Status == TDynStringInfo::serialized)
{ {
// try to retreive all string parameter to build the string. // try to retreive all string parameter to build the string.
ucstring temp; string temp;
temp.reserve(dynInfo.String.size() * 2); temp.reserve(dynInfo.String.size() * 2);
ucstring::iterator src(dynInfo.String.begin()); string::iterator src(dynInfo.String.begin());
ucstring::iterator move = src; string::iterator move = src;
std::vector<TParamValue>::iterator first(dynInfo.Params.begin()), last(dynInfo.Params.end()); std::vector<TParamValue>::iterator first(dynInfo.Params.begin()), last(dynInfo.Params.end());
for (; first != last; ++first) for (; first != last; ++first)
@ -712,7 +719,7 @@ restartLoop:
{ {
case string_id: case string_id:
{ {
ucstring str; string str;
if (!getString(param.StringId, str)) if (!getString(param.StringId, str))
return false; return false;
@ -741,10 +748,10 @@ restartLoop:
} }
// If the string contains a title, then remove it // 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) if ( ! str.empty() && pos != ucstring::npos)
{ {
str = CEntityCL::removeTitleFromName(str.toUtf8()); str = CEntityCL::removeTitleFromName(str);
} }
// append this string // append this string
@ -759,13 +766,13 @@ restartLoop:
char value[1024]; char value[1024];
sprintf(value, "%d", param.Integer); sprintf(value, "%d", param.Integer);
temp.append(move, src+param.ReplacementPoint); temp.append(move, src+param.ReplacementPoint);
temp+=ucstring(value); temp += value;
move = dynInfo.String.begin()+param.ReplacementPoint+2; move = dynInfo.String.begin()+param.ReplacementPoint+2;
} }
break; break;
case time: case time:
{ {
ucstring value; string value;
uint32 time = (uint32)param.Time; uint32 time = (uint32)param.Time;
if( time >= (10*60*60) ) if( time >= (10*60*60) )
{ {
@ -796,7 +803,7 @@ restartLoop:
char value[1024]; char value[1024];
sprintf(value, "%u", (uint32)param.Money); sprintf(value, "%u", (uint32)param.Money);
temp.append(move, src+param.ReplacementPoint); temp.append(move, src+param.ReplacementPoint);
temp+=ucstring(value); temp += value;
move = dynInfo.String.begin()+param.ReplacementPoint+2; move = dynInfo.String.begin()+param.ReplacementPoint+2;
} }
// TODO // TODO
@ -805,7 +812,7 @@ restartLoop:
break; break;
case dyn_string_id: case dyn_string_id:
{ {
ucstring dynStr; string dynStr;
if (!getDynString(param.DynStringId, dynStr)) if (!getDynString(param.DynStringId, dynStr))
return false; return false;
temp.append(move, src+param.ReplacementPoint); temp.append(move, src+param.ReplacementPoint);
@ -823,8 +830,8 @@ restartLoop:
// apply any 'delete' character in the string and replace double '%' // apply any 'delete' character in the string and replace double '%'
{ {
uint i =0; ptrdiff_t i =0;
while (i < temp.size()) while (i < (ptrdiff_t)temp.size())
{ {
if (temp[i] == 8) 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 ) H_AUTO( CStringManagerClient_getDynString )
@ -882,7 +889,7 @@ restartLoop:
{ {
char tmp[1024]; char tmp[1024];
sprintf(tmp, "<DYNSTR %u>", dynStringId); sprintf(tmp, "<DYNSTR %u>", dynStringId);
result = ucstring(tmp) + it->second.String; result = tmp + it->second.String;
} }
else else
result = it->second.String; result = it->second.String;
@ -908,7 +915,7 @@ restartLoop:
nlwarning("DynStringID %u is unknown !", dynStringId); nlwarning("DynStringID %u is unknown !", dynStringId);
char tmp[1024]; char tmp[1024];
sprintf(tmp, "<UNKNOWN DYNSTR %u>", dynStringId); sprintf(tmp, "<UNKNOWN DYNSTR %u>", dynStringId);
result = ucstring(tmp); result = tmp;
} }
else else
result.erase(); //_WaitString; result.erase(); //_WaitString;
@ -920,7 +927,7 @@ restartLoop:
{ {
char tmp[1024]; char tmp[1024];
sprintf(tmp, "<DYNSTR %u>", dynStringId); sprintf(tmp, "<DYNSTR %u>", dynStringId);
result = ucstring(tmp) + it->second.String; result = tmp + it->second.String;
} }
else else
result = it->second.String; result = it->second.String;
@ -933,7 +940,7 @@ restartLoop:
{ {
char tmp[1024]; char tmp[1024];
sprintf(tmp, "<WAIT DYNSTR %u>", dynStringId); sprintf(tmp, "<WAIT DYNSTR %u>", dynStringId);
result = ucstring(tmp); result = tmp;
} }
else else
result.erase(); // = _WaitString; result.erase(); // = _WaitString;
@ -943,7 +950,7 @@ restartLoop:
} }
// Tool fct to lookup a reference file // Tool fct to lookup a reference file
static string lookupReferenceFile(const std::string &fileName) static string lookupReferenceFile(const string &fileName)
{ {
string referenceFile; string referenceFile;
// special location for the "wk" language // special location for the "wk" language
@ -964,14 +971,14 @@ restartLoop:
return referenceFile; return referenceFile;
} }
void CLoadProxy::loadStringFile(const std::string &filename, ucstring &text) void CLoadProxy::loadStringFile(const string &filename, ucstring &text)
{ {
vector<TStringInfo> reference; vector<TStringInfo> reference;
vector<TStringInfo> addition; vector<TStringInfo> addition;
vector<TStringInfo> diff; vector<TStringInfo> diff;
// get the correct path name of the ref file // get the correct path name of the ref file
std::string referenceFile= lookupReferenceFile(filename); string referenceFile= lookupReferenceFile(filename);
// load the reference file // load the reference file
if (!referenceFile.empty()) if (!referenceFile.empty())
@ -1041,7 +1048,7 @@ public:
TWorksheet diff; TWorksheet diff;
// get the correct path name of the ref file // get the correct path name of the ref file
std::string referenceFile= lookupReferenceFile(filename); string referenceFile= lookupReferenceFile(filename);
// load the reference file // load the reference file
if (!referenceFile.empty()) if (!referenceFile.empty())
@ -1134,7 +1141,7 @@ public:
const string StringClientPackedFileName= "./save/string_client.pack"; const string StringClientPackedFileName= "./save/string_client.pack";
// Must Increment this number if change are made to the code (else change not taken into account) // Must Increment this number if change are made to the code (else change not taken into account)
const uint StringClientPackedVersion= 0; const uint StringClientPackedVersion= 0;
bool CStringManagerClient::checkWordFileDates(vector<CFileCheck> &fileChecks, const std::vector<std::string> &fileNames, const std::string &languageCode) bool CStringManagerClient::checkWordFileDates(vector<CFileCheck> &fileChecks, const std::vector<string> &fileNames, const string &languageCode)
{ {
fileChecks.resize(fileNames.size()); fileChecks.resize(fileNames.size());
@ -1142,7 +1149,7 @@ bool CStringManagerClient::checkWordFileDates(vector<CFileCheck> &fileChecks, co
for(uint i=0;i<fileChecks.size();i++) for(uint i=0;i<fileChecks.size();i++)
{ {
// get the correct path name of the ref file // get the correct path name of the ref file
std::string referenceFile= lookupReferenceFile(fileNames[i]); string referenceFile= lookupReferenceFile(fileNames[i]);
fileChecks[i].ReferenceDate= referenceFile.empty()?0:CFile::getFileModificationDate(referenceFile); fileChecks[i].ReferenceDate= referenceFile.empty()?0:CFile::getFileModificationDate(referenceFile);
// get then one of the working File (NB: 0 is a valid reponse for Final Client: no working file) // get then one of the working File (NB: 0 is a valid reponse for Final Client: no working file)
@ -1169,7 +1176,7 @@ bool CStringManagerClient::checkWordFileDates(vector<CFileCheck> &fileChecks, co
// *************************************************************************** // ***************************************************************************
void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode) void CStringManagerClient::initI18NSpecialWords(const string &languageCode)
{ {
ucstring womenNameColIdent= string("women_name"); ucstring womenNameColIdent= string("women_name");
ucstring descColIdent= string("description"); ucstring descColIdent= string("description");
@ -1213,8 +1220,8 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode)
uint32 profile0= (uint32)ryzomGetLocalTime(); uint32 profile0= (uint32)ryzomGetLocalTime();
ucstring ucs; ucstring ucs;
std::string fileName = fileNames[i]; string fileName = fileNames[i];
std::string keyExtenstion = specialWords[i*3+2]; string keyExtenstion = specialWords[i*3+2];
// read the ucstring and make diffs with data in ./translation/work. // read the ucstring and make diffs with data in ./translation/work.
CReadWorkSheetFile rwsf; CReadWorkSheetFile rwsf;
@ -1250,17 +1257,17 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode)
for(uint j=1;j<ws.size();j++) for(uint j=1;j<ws.size();j++)
{ {
// Get the key and name string. // Get the key and name string.
const ucstring &key= ws.getData(j, keyColIndex); const string &key= ws.getData(j, keyColIndex).toUtf8();
const ucstring &name= ws.getData(j, nameColIndex); const string &name= ws.getData(j, nameColIndex).toUtf8();
// Append to the I18N. // Append to the I18N.
// avoid case problems // avoid case problems
string keyStr= NLMISC::toLower(key.toString()); string keyStr = NLMISC::toLower(key);
// append the special key extension. // append the special key extension.
keyStr+= keyExtenstion; keyStr+= keyExtenstion;
// insert in map. // insert in map.
std::map<std::string, CItem>::iterator it; std::map<string, CItem>::iterator it;
it= _SpecItem_TempMap.find( keyStr ); it= _SpecItem_TempMap.find( keyStr );
if ( it!=_SpecItem_TempMap.end() ) if ( it!=_SpecItem_TempMap.end() )
{ {
@ -1276,7 +1283,7 @@ void CStringManagerClient::initI18NSpecialWords(const std::string &languageCode)
if(womenNameColIndex!=std::numeric_limits<uint>::max()) if(womenNameColIndex!=std::numeric_limits<uint>::max())
{ {
const ucstring &womenName= ws.getData(j, womenNameColIndex); 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 // replace all \n in the women name with true \n
while(strFindReplace(_SpecItem_TempMap[keyStr].WomenName, "\\n", "\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<uint>::max()) if(descColIndex!=std::numeric_limits<uint>::max())
{ {
const ucstring &desc= ws.getData(j, descColIndex); 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 // replace all \n in the desc with true \n
while(strFindReplace(_SpecItem_TempMap[keyStr].Desc, "\\n", "\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<uint>::max()) if(descColIndex2!=std::numeric_limits<uint>::max())
{ {
const ucstring &desc= ws.getData(j, descColIndex2); 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 // replace all \n in the desc with true \n
while(strFindReplace(_SpecItem_TempMap[keyStr].Desc2, "\\n", "\n")); while(strFindReplace(_SpecItem_TempMap[keyStr].Desc2, "\\n", "\n"));
} }
@ -1358,7 +1365,7 @@ void CStringManagerClient::specialWordsMemoryCompress()
// Make big strings // Make big strings
_SpecItems.resize(nNbEntries); _SpecItems.resize(nNbEntries);
_SpecItem_Labels = new char[nLabelSize]; _SpecItem_Labels = new char[nLabelSize];
_SpecItem_NameDesc = new ucchar[nNameDescSize]; _SpecItem_NameDesc = new char[nNameDescSize];
nNbEntries = 0; nNbEntries = 0;
nLabelSize = 0; nLabelSize = 0;
@ -1366,35 +1373,30 @@ void CStringManagerClient::specialWordsMemoryCompress()
it = _SpecItem_TempMap.begin(); it = _SpecItem_TempMap.begin();
while (it != _SpecItem_TempMap.end()) while (it != _SpecItem_TempMap.end())
{ {
if (NLMISC::startsWith(it->first.c_str(), "bf"))
if (strnicmp(it->first.c_str(), "bf", 2) == 0)
{ {
uint nDbg = 0; uint nDbg = 0;
nDbg++; nDbg++;
} }
_SpecItems[nNbEntries].Label = _SpecItem_Labels+nLabelSize; _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; nLabelSize += (uint32)it->first.size() + 1;
_SpecItems[nNbEntries].Name = _SpecItem_NameDesc+nNameDescSize; _SpecItems[nNbEntries].Name = _SpecItem_NameDesc+nNameDescSize;
memcpy(_SpecItems[nNbEntries].Name, it->second.Name.c_str(), 2*(it->second.Name.size()+1)); strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.Name.c_str());
_SpecItems[nNbEntries].Name[it->second.Name.size()] = 0;
nNameDescSize += (uint32)it->second.Name.size() + 1; nNameDescSize += (uint32)it->second.Name.size() + 1;
_SpecItems[nNbEntries].WomenName = _SpecItem_NameDesc+nNameDescSize; _SpecItems[nNbEntries].WomenName = _SpecItem_NameDesc+nNameDescSize;
memcpy(_SpecItems[nNbEntries].WomenName, it->second.WomenName.c_str(), 2*(it->second.WomenName.size()+1)); strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.WomenName.c_str());
_SpecItems[nNbEntries].WomenName[it->second.WomenName.size()] = 0;
nNameDescSize += (uint32)it->second.WomenName.size() + 1; nNameDescSize += (uint32)it->second.WomenName.size() + 1;
_SpecItems[nNbEntries].Desc = _SpecItem_NameDesc+nNameDescSize; _SpecItems[nNbEntries].Desc = _SpecItem_NameDesc+nNameDescSize;
memcpy(_SpecItems[nNbEntries].Desc, it->second.Desc.c_str(), 2*(it->second.Desc.size()+1)); strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.Desc.c_str());
_SpecItems[nNbEntries].Desc[it->second.Desc.size()] = 0;
nNameDescSize += (uint32)it->second.Desc.size() + 1; nNameDescSize += (uint32)it->second.Desc.size() + 1;
_SpecItems[nNbEntries].Desc2 = _SpecItem_NameDesc+nNameDescSize; _SpecItems[nNbEntries].Desc2 = _SpecItem_NameDesc+nNameDescSize;
memcpy(_SpecItems[nNbEntries].Desc2, it->second.Desc2.c_str(), 2*(it->second.Desc2.size()+1)); strcpy(_SpecItem_NameDesc+nNameDescSize, it->second.Desc2.c_str());
_SpecItems[nNbEntries].Desc2[it->second.Desc2.size()] = 0;
nNameDescSize += (uint32)it->second.Desc2.size() + 1; nNameDescSize += (uint32)it->second.Desc2.size() + 1;
nNbEntries++; 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()) if (label.empty())
{ {
static ucstring emptyString; static string emptyString;
return emptyString.c_str(); return emptyString.c_str();
} }
if (label[0] == '#') if (label[0] == '#')
{ {
static ucstring rawString;
return getLocalizedName(label.substr(1, label.size()-1)); return getLocalizedName(label.substr(1, label.size()-1));
} }
// avoid case problems // avoid case problems
static std::string lwrLabel; static string lwrLabel;
lwrLabel = toLower(label); lwrLabel = toLower(label);
if (_SpecItem_MemoryCompressed) if (_SpecItem_MemoryCompressed)
@ -1456,28 +1457,26 @@ const ucchar * CStringManagerClient::getSpecialWord(const std::string &label, bo
} }
} }
static ucstring badString; static string badString;
badString = "<NotExist:" + lwrLabel + ">";
badString = ucstring(std::string("<NotExist:")+lwrLabel+">");
return badString.c_str(); 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()) if (label.empty())
return emptyString.c_str(); return emptyString.c_str();
// avoid case problems // avoid case problems
static std::string lwrLabel; static string lwrLabel;
lwrLabel = toLower(label); lwrLabel = toLower(label);
if (_SpecItem_MemoryCompressed) if (_SpecItem_MemoryCompressed)
{ {
CItemLight tmp; CItemLight tmp;
tmp.Label = (char*)lwrLabel.c_str(); tmp.Label = lwrLabel.c_str();
vector<CItemLight>::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp()); vector<CItemLight>::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp());
if (it != _SpecItems.end()) 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()) if (label.empty())
return emptyString.c_str(); return emptyString.c_str();
// avoid case problems // avoid case problems
static std::string lwrLabel; static string lwrLabel;
lwrLabel = toLower(label); lwrLabel = toLower(label);
if (_SpecItem_MemoryCompressed) if (_SpecItem_MemoryCompressed)
{ {
CItemLight tmp; CItemLight tmp;
tmp.Label = (char*)lwrLabel.c_str(); tmp.Label = lwrLabel.c_str();
vector<CItemLight>::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp()); vector<CItemLight>::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp());
if (it != _SpecItems.end()) 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); return getSpecialWord(placeNameID);
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getFactionLocalizedName(const string &factionNameID) const char *CStringManagerClient::getFactionLocalizedName(const string &factionNameID)
{ {
return getSpecialWord(factionNameID); return getSpecialWord(factionNameID);
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSkillLocalizedName(SKILLS::ESkills e) const char *CStringManagerClient::getSkillLocalizedName(SKILLS::ESkills e)
{ {
return getSpecialWord(SKILLS::toString(e)); return getSpecialWord(SKILLS::toString(e));
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getItemLocalizedName(CSheetId id) const char *CStringManagerClient::getItemLocalizedName(CSheetId id)
{ {
return getSpecialWord(id.toString()); return getSpecialWord(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getCreatureLocalizedName(NLMISC::CSheetId id) const char *CStringManagerClient::getCreatureLocalizedName(NLMISC::CSheetId id)
{ {
return getSpecialWord(id.toString()); return getSpecialWord(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSBrickLocalizedName(NLMISC::CSheetId id) const char *CStringManagerClient::getSBrickLocalizedName(NLMISC::CSheetId id)
{ {
return getSpecialWord(id.toString()); return getSpecialWord(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSPhraseLocalizedName(NLMISC::CSheetId id) const char *CStringManagerClient::getSPhraseLocalizedName(NLMISC::CSheetId id)
{ {
return getSpecialWord(id.toString()); 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)); 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)); return getSpecialDesc(SKILLS::toString(e));
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getItemLocalizedDescription(CSheetId id) const char *CStringManagerClient::getItemLocalizedDescription(CSheetId id)
{ {
return getSpecialDesc(id.toString()); return getSpecialDesc(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSBrickLocalizedDescription(NLMISC::CSheetId id) const char *CStringManagerClient::getSBrickLocalizedDescription(NLMISC::CSheetId id)
{ {
return getSpecialDesc(id.toString()); return getSpecialDesc(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSBrickLocalizedCompositionDescription(NLMISC::CSheetId id) const char *CStringManagerClient::getSBrickLocalizedCompositionDescription(NLMISC::CSheetId id)
{ {
return getSpecialDesc2(id.toString()); return getSpecialDesc2(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSPhraseLocalizedDescription(NLMISC::CSheetId id) const char *CStringManagerClient::getSPhraseLocalizedDescription(NLMISC::CSheetId id)
{ {
return getSpecialDesc(id.toString()); return getSpecialDesc(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getTitleLocalizedName(const ucstring &titleId, bool women) const char *CStringManagerClient::getTitleLocalizedName(const string &titleId, bool women)
{ {
vector<ucstring> listInfos = getTitleInfos(titleId, women); vector<string> listInfos = getTitleInfos(titleId, women);
if (!listInfos.empty()) if (!listInfos.empty())
{ {
_TitleWords.push_back(listInfos[0]); _TitleWords.push_back(listInfos[0]);
@ -1661,18 +1661,18 @@ const ucchar *CStringManagerClient::getLocalizedName(const ucstring &uctext)
} }
// *************************************************************************** // ***************************************************************************
vector<ucstring> CStringManagerClient::getTitleInfos(const ucstring &titleId, bool women) vector<string> CStringManagerClient::getTitleInfos(const string &titleId, bool women)
{ {
//ucstring infosUC; //ucstring infosUC;
//infosUC.fromUtf8(titleId); //infosUC.fromUtf8(titleId);
vector<ucstring> listInfos; vector<string> listInfos;
splitUCString(titleId, ucstring("#"), listInfos); splitString(titleId, string("#"), listInfos);
if (!listInfos.empty()) if (!listInfos.empty())
{ {
if (titleId[0] != '#') if (titleId[0] != '#')
{ {
listInfos[0] = getSpecialWord(listInfos[0].toUtf8(), women); listInfos[0] = getSpecialWord(listInfos[0], women);
} }
} }
@ -1680,74 +1680,76 @@ vector<ucstring> 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)); return getSpecialDesc(EGSPD::CClassificationType::toString(type));
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getOutpostLocalizedName(NLMISC::CSheetId id) const char *CStringManagerClient::getOutpostLocalizedName(NLMISC::CSheetId id)
{ {
return getSpecialWord(id.toString()); return getSpecialWord(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getOutpostLocalizedDescription(NLMISC::CSheetId id) const char *CStringManagerClient::getOutpostLocalizedDescription(NLMISC::CSheetId id)
{ {
return getSpecialDesc(id.toString()); return getSpecialDesc(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getOutpostBuildingLocalizedName(NLMISC::CSheetId id) const char *CStringManagerClient::getOutpostBuildingLocalizedName(NLMISC::CSheetId id)
{ {
return getSpecialWord(id.toString()); return getSpecialWord(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id) const char *CStringManagerClient::getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id)
{ {
return getSpecialDesc(id.toString()); return getSpecialDesc(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSquadLocalizedName(NLMISC::CSheetId id) const char *CStringManagerClient::getSquadLocalizedName(NLMISC::CSheetId id)
{ {
return getSpecialWord(id.toString()); return getSpecialWord(id.toString());
} }
// *************************************************************************** // ***************************************************************************
const ucchar *CStringManagerClient::getSquadLocalizedDescription(NLMISC::CSheetId id) const char *CStringManagerClient::getSquadLocalizedDescription(NLMISC::CSheetId id)
{ {
return getSpecialDesc(id.toString()); 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; _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()) if (label.empty())
{ {
return; return;
} }
// avoid case problems // avoid case problems
static std::string lwrLabel; static string lwrLabel;
lwrLabel = toLower(label); lwrLabel = toLower(label);
nlassert(!_SpecItem_MemoryCompressed); // Not allowed, strings are released!
if (_SpecItem_MemoryCompressed) if (_SpecItem_MemoryCompressed)
{ {
ucchar *strName = (ucchar *)name.c_str(); #if 0
ucchar *strDesc = (ucchar *)desc.c_str(); const char *strName = name.c_str();
ucchar *strDesc2 = (ucchar *)desc2.c_str(); const char *strDesc = desc.c_str();
const char *strDesc2 = desc2.c_str();
CItemLight tmp; CItemLight tmp;
tmp.Label = (char*)lwrLabel.c_str(); tmp.Label = lwrLabel.c_str();
vector<CItemLight>::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp()); vector<CItemLight>::iterator it = lower_bound(_SpecItems.begin(), _SpecItems.end(), tmp, CItemLightComp());
if (it != _SpecItems.end()) if (it != _SpecItems.end())
@ -1773,6 +1775,7 @@ void CStringManagerClient::replaceSBrickName(NLMISC::CSheetId id, const ucstring
tmp.Desc2 = strDesc2; tmp.Desc2 = strDesc2;
_SpecItems.push_back(tmp); _SpecItems.push_back(tmp);
} }
#endif
} }
else else
{ {

@ -63,15 +63,16 @@ public:
// Force the cache to be saved // Force the cache to be saved
void flushStringCache(); 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, std::string &result);
bool getString(uint32 stringId, ucstring &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, ucstring *result); void waitString(uint32 stringId, const IStringWaiterRemover *premover, std::string *result);
void waitString(uint32 stringId, IStringWaitCallback *pcallback); void waitString(uint32 stringId, IStringWaitCallback *pcallback);
bool getDynString(uint32 dynStringId, ucstring &result); bool getDynString(uint32 dynStringId, std::string &result);
void waitDynString(uint32 stringId, const IStringWaiterRemover *premover, ucstring *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 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 receiveDynString(NLMISC::CBitMemStream &bms);
void releaseDynString(uint32 stringId); void releaseDynString(uint32 stringId);
@ -80,55 +81,55 @@ public:
static void initI18NSpecialWords(const std::string &languageCode); static void initI18NSpecialWords(const std::string &languageCode);
static void specialWordsMemoryCompress(); static void specialWordsMemoryCompress();
// Yoyo: Replace the Brick Name with Filled stats (CSBrickManager work). No-Op if not found // 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 replaceSBrickName(NLMISC::CSheetId id, const std::string &name, const std::string &desc, const std::string &desc2);
static void replaceDynString(const ucstring &name, const ucstring &text); static void replaceDynString(const std::string &name, const std::string &text);
// Get the Localized Name of the Places. // 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) // 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. // 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. // 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. // 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. // 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. // 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. // 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. // 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. // 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. // 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. // 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 // Get the Localized Title name
static const ucchar *getTitleLocalizedName(const ucstring &titleId, bool women); static const char *getTitleLocalizedName(const std::string &titleId, bool women);
static const ucchar *getLocalizedName(const ucstring &text); static const char *getLocalizedName(const std::string &text);
static std::vector<ucstring> getTitleInfos(const ucstring &titleId, bool women); static std::vector<std::string> getTitleInfos(const std::string &titleId, bool women);
// Get the Localized name of a classification type // 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 // Outpost name
static const ucchar *getOutpostLocalizedName(NLMISC::CSheetId id); static const char *getOutpostLocalizedName(NLMISC::CSheetId id);
// Outpost description // Outpost description
static const ucchar *getOutpostLocalizedDescription(NLMISC::CSheetId id); static const char *getOutpostLocalizedDescription(NLMISC::CSheetId id);
// Outpost building name // Outpost building name
static const ucchar *getOutpostBuildingLocalizedName(NLMISC::CSheetId id); static const char *getOutpostBuildingLocalizedName(NLMISC::CSheetId id);
// Outpost building description // Outpost building description
static const ucchar *getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id); static const char *getOutpostBuildingLocalizedDescription(NLMISC::CSheetId id);
// Squad name // Squad name
static const ucchar *getSquadLocalizedName(NLMISC::CSheetId id); static const char *getSquadLocalizedName(NLMISC::CSheetId id);
// Squad description // Squad description
static const ucchar *getSquadLocalizedDescription(NLMISC::CSheetId id); static const char *getSquadLocalizedDescription(NLMISC::CSheetId id);
private: private:
// constructor. // constructor.
@ -154,7 +155,7 @@ private:
struct TParamValue struct TParamValue
{ {
TParamType Type; TParamType Type;
ucstring::size_type ReplacementPoint; std::string::size_type ReplacementPoint;
union union
{ {
uint32 StringId; uint32 StringId;
@ -177,7 +178,7 @@ private:
NLMISC::CBitMemStream Message; NLMISC::CBitMemStream Message;
uint32 StringId; uint32 StringId;
std::vector<TParamValue> Params; std::vector<TParamValue> Params;
ucstring String; std::string String;
}; };
enum enum
@ -189,7 +190,7 @@ private:
struct TStringWaiter struct TStringWaiter
{ {
/// Pointer to the ucstring to fill /// Pointer to the ucstring to fill
ucstring *Result; std::string *Result;
/// Pointer to the remover that contains this string reference /// Pointer to the remover that contains this string reference
const IStringWaiterRemover *Remover; const IStringWaiterRemover *Remover;
}; };
@ -198,7 +199,7 @@ private:
/// Container for simple strings /// Container for simple strings
typedef CHashMap<uint, ucstring> TStringsContainer; typedef CHashMap<uint, std::string> TStringsContainer;
/// Container for dyn strings /// Container for dyn strings
typedef CHashMap<uint, TDynStringInfo> TDynStringsContainer; typedef CHashMap<uint, TDynStringInfo> TDynStringsContainer;
/// Container of string reference waiting for value. /// Container of string reference waiting for value.
@ -224,7 +225,7 @@ private:
TStringCallbacksContainer _DynStringsCallbacks; TStringCallbacksContainer _DynStringsCallbacks;
// Return value for waiting string.. // Return value for waiting string..
static ucstring _WaitString; static std::string _WaitString;
// Singleton pattern implementation // Singleton pattern implementation
static CStringManagerClient *_Instance; static CStringManagerClient *_Instance;
@ -247,7 +248,7 @@ private:
struct CCacheString struct CCacheString
{ {
uint32 StringId; uint32 StringId;
ucstring String; std::string String;
}; };
std::vector<CCacheString> _CacheStringToSave; std::vector<CCacheString> _CacheStringToSave;
//@} //@}
@ -257,41 +258,60 @@ private:
{ {
public: public:
// The Name of the item // The Name of the item
ucstring Name; std::string Name;
// The Women Name of the item // The Women Name of the item
ucstring WomenName; std::string WomenName;
// Description of the item // Description of the item
ucstring Desc; std::string Desc;
// Optional Second description (For SBrick composition for example) // Optional Second description (For SBrick composition for example)
ucstring Desc2; std::string Desc2;
void serial(NLMISC::IStream &f) void serial(NLMISC::IStream &f)
{ {
sint ver= f.serialVersion(1); sint ver = f.serialVersion(2);
if (ver >= 2)
{
f.serial(Name); f.serial(Name);
if (ver >= 1)
f.serial(WomenName); f.serial(WomenName);
f.serial(Desc); f.serial(Desc);
f.serial(Desc2); 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 bool _SpecItem_MemoryCompressed;
static std::map<std::string, CItem> _SpecItem_TempMap; static std::map<std::string, CItem> _SpecItem_TempMap;
static std::vector<ucstring> _TitleWords; static std::vector<std::string> _TitleWords;
static std::map<ucstring, ucstring> _DynStrings; static std::map<std::string, std::string> _DynStrings;
static char *_SpecItem_Labels; static char *_SpecItem_Labels;
static ucchar *_SpecItem_NameDesc; static char *_SpecItem_NameDesc;
struct CItemLight struct CItemLight
{ {
char *Label; const char *Label;
ucchar *Name; const char *Name;
ucchar *WomenName; const char *WomenName;
ucchar *Desc; const char *Desc;
ucchar *Desc2; const char *Desc2;
}; };
struct CItemLightComp struct CItemLightComp
{ {
@ -303,9 +323,9 @@ private:
static std::vector<CItemLight> _SpecItems; static std::vector<CItemLight> _SpecItems;
static const ucchar *getSpecialWord(const std::string &label, bool women = false); static const char *getSpecialWord(const std::string &label, bool women = false);
static const ucchar *getSpecialDesc(const std::string &label); static const char *getSpecialDesc(const std::string &label);
static const ucchar *getSpecialDesc2(const std::string &label); static const char *getSpecialDesc2(const std::string &label);
// Check Files for the Packed string. // Check Files for the Packed string.
class CFileCheck class CFileCheck
@ -381,9 +401,9 @@ class IStringWaitCallback
{ {
public: public:
/// Overide this method to receive callback for string. /// 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. /// 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() virtual ~IStringWaitCallback()
{ {

Loading…
Cancel
Save