void CI18N::_readTextFile(const string &filename, ucstring &result, bool forceUtf8, bool fileLookup, bool preprocess, TLineFormat lineFmt, bool warnIfIncludesNotFound, TReadContext &readContext) { string fullName; if (fileLookup) fullName = CPath::lookup(filename, false,warnIfIncludesNotFound); else fullName = filename; if (fullName.empty()) return; // If ::lookup is used, the file can be in a bnp and CFile::fileExists fails. bool isInBnp = fullName.find('@') != string::npos; if (!isInBnp && !CFile::fileExists(fullName)) { nlwarning("CI18N::readTextFile : file '%s' does not exist, returning empty string", fullName.c_str()); return; } NLMISC::CIFile file(fullName); // Fast read all the text in binary mode. string text; text.resize(file.getFileSize()); if (file.getFileSize() > 0) file.serialBuffer((uint8*)(&text[0]), (uint)text.size()); // Transform the string in ucstring according to format header if (!text.empty()) readTextBuffer((uint8*)&text[0], (uint)text.size(), result, forceUtf8); if (preprocess) { // a string to old the result of the preprocess ucstring final; // make rooms to reduce allocation cost final.reserve(raiseToNextPowerOf2((uint)result.size())); // parse the file, looking for preprocessor command. ucstring::const_iterator it(result.begin()), end(result.end()); // input line counter uint32 currentLine = 1; // set the current file and line info final += toString("#fileline \"%s\" %u\n", filename.c_str(), currentLine);
void CI18N::removeCComment(ucstring &commentedString) { ucstring temp; temp.reserve(commentedString.size()); ucstring::const_iterator first(commentedString.begin()), last(commentedString.end()); for (;first != last; ++first) { temp.push_back(*first); if (*first == '[') { // no comment inside string literal while (++first != last) { temp.push_back(*first); if (*first == ']') break; } } else if (*first == '/') { // start of comment ? ++first; if (first != last && *first == '/') { temp.resize(temp.size()-1); // one line comment, skip until end of line while (first != last && *first != '\n') ++first; } else if (first != last && *first == '*') { temp.resize(temp.size()-1); // start of multi line comment, skip until we found '*/' while (first != last && !(*first == '*' && (first+1) != last && *(first+1) == '/')) ++first; // skip the closing '/' if (first != last) ++first; } else { temp.push_back(*first); } } } commentedString.swap(temp); }
// **************************************************************************** ucstring CViewTextFormated::formatString(const ucstring &inputString, const ucstring ¶mString) { ucstring formatedResult; // Apply the format for(ucstring::const_iterator it = inputString.begin(); it != inputString.end();) { if (*it == '$') { ++it; if (it == inputString.end()) break; switch(*it) { case 't': // add text ID formatedResult += paramString; break; case 'P': case 'p': // add player name if (ClientCfg.Local) { formatedResult += ucstring("player"); } else { if(UserEntity) { ucstring name = UserEntity->getEntityName(); if (*it == 'P') setCase(name, CaseUpper); formatedResult += name; } } break; // case 's': case 'b': // add bot name { ucstring botName; bool womanTitle = false; if (ClientCfg.Local) { botName = ucstring("NPC"); } else { CLFECOMMON::TCLEntityId trader = CLFECOMMON::INVALID_SLOT; if(UserEntity) trader = UserEntity->trader(); if (trader != CLFECOMMON::INVALID_SLOT) { CEntityCL *entity = EntitiesMngr.entity(trader); if (entity != NULL) { uint32 nDBid = entity->getNameId(); if (nDBid != 0) { CStringManagerClient *pSMC = CStringManagerClient::instance(); pSMC->getString(nDBid, botName); } else { botName = entity->getDisplayName(); } CCharacterCL *pChar = dynamic_cast<CCharacterCL*>(entity); if (pChar != NULL) womanTitle = pChar->getGender() == GSGENDER::female; } } } // get the title translated ucstring sTitleTranslated = botName; CStringPostProcessRemoveName spprn; spprn.Woman = womanTitle; spprn.cbIDStringReceived(sTitleTranslated); botName = CEntityCL::removeTitleAndShardFromName(botName); // short name (with no title such as 'guard', 'merchant' ...) if (*it == 's') { // But if there is no name, display only the title if (botName.empty()) botName = sTitleTranslated; } else { // Else we want the title ! if (!botName.empty()) botName += " "; botName += sTitleTranslated; } formatedResult += botName; } break; default: formatedResult += (ucchar) '$'; break; } ++it; } else { formatedResult += (ucchar) *it; ++it; } } return formatedResult; }