diff --git a/src/Core/GameProject/AssetNameGeneration.cpp b/src/Core/GameProject/AssetNameGeneration.cpp index c244a866..f9e26464 100644 --- a/src/Core/GameProject/AssetNameGeneration.cpp +++ b/src/Core/GameProject/AssetNameGeneration.cpp @@ -589,12 +589,14 @@ void GenerateAssetNames(CGameProject *pProj) for (TResourceIterator It(pStore); It; ++It) { - if (It->IsNamed()) continue; - CStringTable *pString = (CStringTable*) It->Load(); + if (It->IsNamed()) + continue; + + auto *pString = static_cast(It->Load()); TString String; - for (uint32 iStr = 0; iStr < pString->NumStrings() && String.IsEmpty(); iStr++) - String = CStringTable::StripFormatting( pString->GetString(ELanguage::English, iStr) ).Trimmed(); + for (size_t iStr = 0; iStr < pString->NumStrings() && String.IsEmpty(); iStr++) + String = CStringTable::StripFormatting(pString->GetString(ELanguage::English, iStr)).Trimmed(); if (!String.IsEmpty()) { diff --git a/src/Core/Resource/Cooker/CStringCooker.cpp b/src/Core/Resource/Cooker/CStringCooker.cpp index 9f2c6d27..5dff107e 100644 --- a/src/Core/Resource/Cooker/CStringCooker.cpp +++ b/src/Core/Resource/Cooker/CStringCooker.cpp @@ -4,131 +4,131 @@ void CStringCooker::WritePrimeDemoSTRG(IOutputStream& STRG) { - uint StartOffset = STRG.Tell(); - uint NumStrings = mpStringTable->NumStrings(); + const uint32 StartOffset = STRG.Tell(); + const size_t NumStrings = mpStringTable->NumStrings(); // Start writing the file... STRG.WriteLong(0); // Dummy file size - uint TableStart = STRG.Tell(); + const uint32 TableStart = STRG.Tell(); STRG.WriteLong(NumStrings); // Dummy string offsets - for (uint StringIdx = 0; StringIdx < NumStrings; StringIdx++) + for (size_t StringIdx = 0; StringIdx < NumStrings; StringIdx++) STRG.WriteLong(0); // Write strings - std::vector StringOffsets(NumStrings); + std::vector StringOffsets(NumStrings); - for (uint StringIdx = 0; StringIdx < NumStrings; StringIdx++) + for (size_t StringIdx = 0; StringIdx < NumStrings; StringIdx++) { StringOffsets[StringIdx] = STRG.Tell() - TableStart; - STRG.Write16String( mpStringTable->GetString(ELanguage::English, StringIdx).ToUTF16() ); + STRG.Write16String(mpStringTable->GetString(ELanguage::English, StringIdx).ToUTF16()); } // Fill in offsets - uint FileSize = STRG.Tell() - StartOffset; + const uint32 FileSize = STRG.Tell() - StartOffset; STRG.GoTo(StartOffset); STRG.WriteLong(FileSize); STRG.Skip(4); - for (uint StringIdx = 0; StringIdx < NumStrings; StringIdx++) - STRG.WriteLong( StringOffsets[StringIdx] ); + for (size_t StringIdx = 0; StringIdx < NumStrings; StringIdx++) + STRG.WriteLong(StringOffsets[StringIdx]); } void CStringCooker::WritePrimeSTRG(IOutputStream& STRG) { // Magic/Version - STRG.WriteLong( 0x87654321 ); - STRG.WriteLong( mpStringTable->Game() >= EGame::EchoesDemo ? 1 : 0 ); - STRG.WriteLong( mpStringTable->NumLanguages() ); - STRG.WriteLong( mpStringTable->NumStrings() ); + STRG.WriteLong(0x87654321); + STRG.WriteLong(mpStringTable->Game() >= EGame::EchoesDemo ? 1 : 0); + STRG.WriteLong(static_cast(mpStringTable->NumLanguages())); + STRG.WriteLong(static_cast(mpStringTable->NumStrings())); // Language info - uint LanguagesStart = STRG.Tell(); + const uint LanguagesStart = STRG.Tell(); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t i = 0; i < mpStringTable->NumLanguages(); i++) { - const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[LanguageIdx]; - STRG.WriteLong( (uint) kLanguage.Language ); - STRG.WriteLong( 0 ); // Dummy offset + const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[i]; + STRG.WriteLong(static_cast(kLanguage.Language)); + STRG.WriteLong(0); // Dummy offset - if ( mpStringTable->Game() >= EGame::EchoesDemo ) + if (mpStringTable->Game() >= EGame::EchoesDemo) { - STRG.WriteLong( 0 ); // Dummy size + STRG.WriteLong(0); // Dummy size } } // Name Table - if ( mpStringTable->Game() >= EGame::EchoesDemo ) + if (mpStringTable->Game() >= EGame::EchoesDemo) { WriteNameTable(STRG); } // Strings - uint StringDataStart = STRG.Tell(); - std::vector LanguageOffsets( mpStringTable->NumLanguages() ); - std::vector LanguageSizes( mpStringTable->NumLanguages() ); + const uint32 StringDataStart = STRG.Tell(); + std::vector LanguageOffsets(mpStringTable->NumLanguages()); + std::vector LanguageSizes(mpStringTable->NumLanguages()); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[LanguageIdx]; - uint LanguageStart = STRG.Tell(); + const uint32 LanguageStart = STRG.Tell(); LanguageOffsets[LanguageIdx] = LanguageStart - StringDataStart; - if ( mpStringTable->Game() == EGame::Prime ) + if (mpStringTable->Game() == EGame::Prime) { - STRG.WriteLong( 0 ); // Dummy size + STRG.WriteLong(0); // Dummy size } // Fill dummy string offsets - uint StringOffsetBase = STRG.Tell(); + const uint32 StringOffsetBase = STRG.Tell(); - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) { - STRG.WriteLong( 0 ); + STRG.WriteLong(0); } // Write strings - std::vector StringOffsets( mpStringTable->NumStrings() ); + std::vector StringOffsets(mpStringTable->NumStrings()); - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + for (size_t i = 0; i < mpStringTable->NumStrings(); i++) { - StringOffsets[StringIdx] = STRG.Tell() - StringOffsetBase; - STRG.Write16String( kLanguage.Strings[StringIdx].String.ToUTF16() ); + StringOffsets[i] = STRG.Tell() - StringOffsetBase; + STRG.Write16String(kLanguage.Strings[i].String.ToUTF16()); } // Go back and fill in size/offsets - uint LanguageEnd = STRG.Tell(); + const uint32 LanguageEnd = STRG.Tell(); LanguageSizes[LanguageIdx] = LanguageEnd - StringOffsetBase; STRG.GoTo(LanguageStart); - if ( mpStringTable->Game() == EGame::Prime ) + if (mpStringTable->Game() == EGame::Prime) { - STRG.WriteLong( LanguageSizes[LanguageIdx] ); + STRG.WriteLong(LanguageSizes[LanguageIdx]); } - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + for (size_t i = 0; i < mpStringTable->NumStrings(); i++) { - STRG.WriteLong( StringOffsets[StringIdx] ); + STRG.WriteLong(StringOffsets[i]); } STRG.GoTo(LanguageEnd); } - uint STRGEnd = STRG.Tell(); + const uint32 STRGEnd = STRG.Tell(); // Fill in missing language data STRG.GoTo(LanguagesStart); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t i = 0; i < mpStringTable->NumLanguages(); i++) { STRG.Skip(4); // Skip language ID - STRG.WriteLong( LanguageOffsets[LanguageIdx] ); + STRG.WriteLong(LanguageOffsets[i]); - if ( mpStringTable->Game() >= EGame::EchoesDemo ) + if (mpStringTable->Game() >= EGame::EchoesDemo) { - STRG.WriteLong( LanguageSizes[LanguageIdx] ); + STRG.WriteLong(LanguageSizes[i]); } } @@ -138,10 +138,10 @@ void CStringCooker::WritePrimeSTRG(IOutputStream& STRG) void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG) { // Magic/Version - STRG.WriteLong( 0x87654321 ); - STRG.WriteLong( 3 ); - STRG.WriteLong( mpStringTable->NumLanguages() ); - STRG.WriteLong( mpStringTable->NumStrings() ); + STRG.WriteLong(0x87654321); + STRG.WriteLong(3); + STRG.WriteLong(mpStringTable->NumLanguages()); + STRG.WriteLong(mpStringTable->NumStrings()); // Name Table WriteNameTable(STRG); @@ -153,50 +153,50 @@ void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG) { ELanguage Language; std::vector StringOffsets; - uint TotalSize; + uint32 TotalSize; }; std::vector CookedLanguageData( mpStringTable->NumLanguages() ); - int EnglishIdx = -1; + size_t EnglishIdx = UINT32_MAX; - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { const CStringTable::SLanguageData& kLanguageData = mpStringTable->mLanguages[LanguageIdx]; SCookedLanguageData& CookedData = CookedLanguageData[LanguageIdx]; CookedData.Language = kLanguageData.Language; - CookedData.StringOffsets.resize( mpStringTable->NumStrings() ); + CookedData.StringOffsets.resize(mpStringTable->NumStrings()); CookedData.TotalSize = 0; if (CookedData.Language == ELanguage::English) { - EnglishIdx = (int) LanguageIdx; + EnglishIdx = LanguageIdx; } } // Language IDs - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { - STRG.WriteLong( (uint) CookedLanguageData[LanguageIdx].Language ); + STRG.WriteLong(static_cast(CookedLanguageData[LanguageIdx].Language)); } // Language Info - uint LanguageInfoStart = STRG.Tell(); + const uint32 LanguageInfoStart = STRG.Tell(); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { // Fill language size/offsets with dummy data... - STRG.WriteLong( 0 ); + STRG.WriteLong(0); - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) - STRG.WriteLong( 0 ); + for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + STRG.WriteLong(0); } // Strings - uint StringsStart = STRG.Tell(); + const uint32 StringsStart = STRG.Tell(); - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) { - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { const CStringTable::SLanguageData& kLanguageData = mpStringTable->mLanguages[LanguageIdx]; const CStringTable::SStringData& kStringData = kLanguageData.Strings[StringIdx]; @@ -208,8 +208,8 @@ void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG) { CookedData.StringOffsets[StringIdx] = STRG.Tell() - StringsStart; CookedData.TotalSize += kStringData.String.Size() + 1; // +1 for terminating zero - STRG.WriteLong( kStringData.String.Size() + 1 ); - STRG.WriteString( kStringData.String ); + STRG.WriteLong(kStringData.String.Size() + 1); + STRG.WriteString(kStringData.String); } else { @@ -219,18 +219,18 @@ void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG) } } - uint STRGEnd = STRG.Tell(); + const uint32 STRGEnd = STRG.Tell(); // Fill in missing language data STRG.GoTo(LanguageInfoStart); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { const SCookedLanguageData& kCookedData = CookedLanguageData[LanguageIdx]; - STRG.WriteLong( kCookedData.TotalSize ); + STRG.WriteLong(kCookedData.TotalSize); - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) - STRG.WriteLong( kCookedData.StringOffsets[StringIdx] ); + for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + STRG.WriteLong(kCookedData.StringOffsets[StringIdx]); } STRG.GoTo(STRGEnd); @@ -241,13 +241,13 @@ void CStringCooker::WriteNameTable(IOutputStream& STRG) // Build a list of name entries to put in the map struct SNameEntry { - uint Offset; - uint Index; + uint32 Offset; + uint32 Index; TString Name; }; std::vector NameEntries; - for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) + for (uint32 StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++) { SNameEntry Entry; Entry.Offset = 0; @@ -256,46 +256,46 @@ void CStringCooker::WriteNameTable(IOutputStream& STRG) if (!Entry.Name.IsEmpty()) { - NameEntries.push_back(Entry); + NameEntries.push_back(std::move(Entry)); } } - std::stable_sort( NameEntries.begin(), NameEntries.end(), [](const SNameEntry& kLHS, const SNameEntry& kRHS) -> bool { + std::stable_sort(NameEntries.begin(), NameEntries.end(), [](const SNameEntry& kLHS, const SNameEntry& kRHS) { return kLHS.Name < kRHS.Name; }); // Write out name entries - uint NameTableStart = STRG.Tell(); - STRG.WriteLong( NameEntries.size() ); - STRG.WriteLong( 0 ); // Dummy name table size - uint NameTableOffsetsStart = STRG.Tell(); + const uint32 NameTableStart = STRG.Tell(); + STRG.WriteLong(NameEntries.size()); + STRG.WriteLong(0); // Dummy name table size + const uint32 NameTableOffsetsStart = STRG.Tell(); - for (uint NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++) + for (size_t NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++) { - STRG.WriteLong( 0 ); // Dummy name offset - STRG.WriteLong( NameEntries[NameIdx].Index ); + STRG.WriteLong(0); // Dummy name offset + STRG.WriteLong(NameEntries[NameIdx].Index); } // Write out names - std::vector NameOffsets( NameEntries.size() ); + std::vector NameOffsets(NameEntries.size()); - for (uint NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++) + for (size_t NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++) { NameOffsets[NameIdx] = STRG.Tell() - NameTableOffsetsStart; - STRG.WriteString( NameEntries[NameIdx].Name ); + STRG.WriteString(NameEntries[NameIdx].Name); } // Fill out sizes and offsets - uint NameTableEnd = STRG.Tell(); - uint NameTableSize = NameTableEnd - NameTableOffsetsStart; + const uint32 NameTableEnd = STRG.Tell(); + const uint32 NameTableSize = NameTableEnd - NameTableOffsetsStart; STRG.GoTo(NameTableStart); STRG.Skip(4); STRG.WriteLong(NameTableSize); - for (uint NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++) + for (const uint32 offset : NameOffsets) { - STRG.WriteLong( NameOffsets[NameIdx] ); + STRG.WriteLong(offset); STRG.Skip(4); } diff --git a/src/Core/Resource/StringTable/CStringTable.cpp b/src/Core/Resource/StringTable/CStringTable.cpp index 04cd0219..57ce2e40 100644 --- a/src/Core/Resource/StringTable/CStringTable.cpp +++ b/src/Core/Resource/StringTable/CStringTable.cpp @@ -77,11 +77,11 @@ static std::pair GetSupportedLanguages(EGame Game, ERe // Utility function - retrieve the index of a given language static int FindLanguageIndex(const CStringTable* pkInTable, ELanguage InLanguage) { - for (uint LanguageIdx = 0; LanguageIdx < pkInTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < pkInTable->NumLanguages(); LanguageIdx++) { if (pkInTable->LanguageByIndex(LanguageIdx) == InLanguage) { - return LanguageIdx; + return static_cast(LanguageIdx); } } @@ -89,47 +89,46 @@ static int FindLanguageIndex(const CStringTable* pkInTable, ELanguage InLanguage } /** Returns a string given a language/index pair */ -TString CStringTable::GetString(ELanguage Language, uint StringIndex) const +TString CStringTable::GetString(ELanguage Language, size_t StringIndex) const { - int LanguageIdx = FindLanguageIndex(this, Language); + const int LanguageIdx = FindLanguageIndex(this, Language); if (LanguageIdx >= 0 && mLanguages[LanguageIdx].Strings.size() > StringIndex) { return mLanguages[LanguageIdx].Strings[StringIndex].String; } - else - { - return ""; - } + + return ""; } /** Updates a string for a given language */ -void CStringTable::SetString(ELanguage Language, uint StringIndex, const TString& kNewString) +void CStringTable::SetString(ELanguage Language, size_t StringIndex, TString kNewString) { - int LanguageIdx = FindLanguageIndex(this, Language); - int EnglishIdx = FindLanguageIndex(this, ELanguage::English); + const int LanguageIdx = FindLanguageIndex(this, Language); + const int EnglishIdx = FindLanguageIndex(this, ELanguage::English); if (LanguageIdx >= 0 && mLanguages[LanguageIdx].Strings.size() > StringIndex) { - mLanguages[LanguageIdx].Strings[StringIndex].String = kNewString; - mLanguages[LanguageIdx].Strings[StringIndex].IsLocalized = - (LanguageIdx == EnglishIdx || kNewString != mLanguages[EnglishIdx].Strings[StringIndex].String); + auto& string = mLanguages[LanguageIdx].Strings[StringIndex]; + + string.IsLocalized = LanguageIdx == EnglishIdx || kNewString != mLanguages[EnglishIdx].Strings[StringIndex].String; + string.String = std::move(kNewString); } } /** Updates a string name */ -void CStringTable::SetStringName(uint StringIndex, const TString& kNewName) +void CStringTable::SetStringName(size_t StringIndex, TString kNewName) { // Sanity check - make sure the string index is valid - ASSERT( NumStrings() > StringIndex ); + ASSERT(NumStrings() > StringIndex); // Expand the name listing if needed and assign the name if (mStringNames.size() <= StringIndex) { - mStringNames.resize( StringIndex + 1 ); + mStringNames.resize(StringIndex + 1); } - mStringNames[StringIndex] = kNewName; + mStringNames[StringIndex] = std::move(kNewName); // Strip empty string names while (mStringNames.back().IsEmpty()) @@ -137,37 +136,36 @@ void CStringTable::SetStringName(uint StringIndex, const TString& kNewName) } /** Move string to another position in the table */ -void CStringTable::MoveString(uint StringIndex, uint NewIndex) +void CStringTable::MoveString(size_t StringIndex, size_t NewIndex) { - ASSERT( NumStrings() > StringIndex ); - ASSERT( NumStrings() > NewIndex ); + ASSERT(NumStrings() > StringIndex); + ASSERT(NumStrings() > NewIndex); if (NewIndex == StringIndex) return; // Update string data - for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++) + for (SLanguageData& Language : mLanguages) { - SLanguageData& Language = mLanguages[LanguageIdx]; SStringData String = Language.Strings[StringIndex]; if (NewIndex > StringIndex) { - for (uint i=StringIndex; iNewIndex; i--) - Language.Strings[i] = Language.Strings[i-1]; + for (size_t i = StringIndex; i > NewIndex; i--) + Language.Strings[i] = Language.Strings[i - 1]; } - Language.Strings[NewIndex] = String; + Language.Strings[NewIndex] = std::move(String); } // Update string name - uint MinIndex = Math::Min(StringIndex, NewIndex); - uint MaxIndex = Math::Max(StringIndex, NewIndex); + const size_t MinIndex = std::min(StringIndex, NewIndex); + const size_t MaxIndex = std::max(StringIndex, NewIndex); if (MinIndex < mStringNames.size()) { @@ -180,15 +178,15 @@ void CStringTable::MoveString(uint StringIndex, uint NewIndex) if (NewIndex > StringIndex) { - for (uint i=StringIndex; iNewIndex; i--) - mStringNames[i] = mStringNames[i-1]; + for (size_t i = StringIndex; i > NewIndex; i--) + mStringNames[i] = mStringNames[i - 1]; } - mStringNames[NewIndex] = Name; + mStringNames[NewIndex] = std::move(Name); // Strip empty string names while (mStringNames.back().IsEmpty()) @@ -197,37 +195,37 @@ void CStringTable::MoveString(uint StringIndex, uint NewIndex) } /** Add a new string to the table */ -void CStringTable::AddString(uint AtIndex) +void CStringTable::AddString(size_t AtIndex) { if (AtIndex < NumStrings()) { if (mStringNames.size() > AtIndex) { - mStringNames.insert( mStringNames.begin() + AtIndex, 1, "" ); + mStringNames.insert(mStringNames.begin() + AtIndex, 1, ""); } } else - AtIndex = NumStrings(); - - for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++) { - SLanguageData& Language = mLanguages[LanguageIdx]; - Language.Strings.insert( Language.Strings.begin() + AtIndex, 1, SStringData() ); + AtIndex = NumStrings(); + } + + for (SLanguageData& Language : mLanguages) + { + Language.Strings.insert(Language.Strings.begin() + AtIndex, 1, SStringData()); } } /** Remove a string from the table */ -void CStringTable::RemoveString(uint StringIndex) +void CStringTable::RemoveString(size_t StringIndex) { - ASSERT( StringIndex < NumStrings() ); + ASSERT(StringIndex < NumStrings()); if (mStringNames.size() > StringIndex) - mStringNames.erase( mStringNames.begin() + StringIndex ); + mStringNames.erase(mStringNames.begin() + StringIndex); - for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++) + for (SLanguageData& Language : mLanguages) { - SLanguageData& Language = mLanguages[LanguageIdx]; - Language.Strings.erase( Language.Strings.begin() + StringIndex ); + Language.Strings.erase(Language.Strings.begin() + StringIndex); } } @@ -235,7 +233,7 @@ void CStringTable::RemoveString(uint StringIndex) void CStringTable::InitializeNewResource() { // Initialize data for whatever languages are supported by our game/region - ERegion Region = ( Entry() && Entry()->Project() ? Entry()->Project()->Region() : ERegion::NTSC ); + const ERegion Region = ( Entry() && Entry()->Project() ? Entry()->Project()->Region() : ERegion::NTSC ); const auto [data, dataSize] = GetSupportedLanguages(Game(), Region); mLanguages.resize(dataSize); @@ -258,7 +256,7 @@ std::unique_ptr CStringTable::BuildDependencyTree() const { // STRGs can reference FONTs with the &font=; formatting tag and TXTRs with the &image=; tag auto pTree = std::make_unique(); - EIDLength IDLength = CAssetID::GameIDLength( Game() ); + EIDLength IDLength = CAssetID::GameIDLength(Game()); for (const SLanguageData& language : mLanguages) { @@ -276,13 +274,15 @@ std::unique_ptr CStringTable::BuildDependencyTree() const } // Get tag name and parameters - int NameEnd = kString.IndexOf('=', TagIdx); - int TagEnd = kString.IndexOf(';', TagIdx); - if (NameEnd == -1 || TagEnd == -1) continue; + const int NameEnd = kString.IndexOf('=', TagIdx); + const int TagEnd = kString.IndexOf(';', TagIdx); + if (NameEnd == -1 || TagEnd == -1) + continue; - TString TagName = kString.SubString(TagIdx + 1, NameEnd - TagIdx - 1); + const TString TagName = kString.SubString(TagIdx + 1, NameEnd - TagIdx - 1); TString ParamString = kString.SubString(NameEnd + 1, TagEnd - NameEnd - 1); - if (ParamString.IsEmpty()) continue; + if (ParamString.IsEmpty()) + continue; // Font if (TagName == "font") @@ -295,9 +295,8 @@ std::unique_ptr CStringTable::BuildDependencyTree() const } ASSERT(ParamString.Size() == IDLength * 2); - pTree->AddDependency( CAssetID::FromString(ParamString) ); + pTree->AddDependency(CAssetID::FromString(ParamString)); } - // Image else if (TagName == "image") { @@ -307,20 +306,25 @@ std::unique_ptr CStringTable::BuildDependencyTree() const uint TexturesStart = 0; if (ImageType == "A") + { TexturesStart = 2; - + } else if (ImageType == "SI") + { TexturesStart = 3; - + } else if (ImageType == "SA") + { TexturesStart = 4; - + } else if (ImageType == "B") + { TexturesStart = 2; - + } else if (ImageType.IsHexString(false, static_cast(IDLength) * 2)) + { TexturesStart = 0; - + } else { errorf("Unrecognized image type: %s", *ImageType); @@ -330,7 +334,7 @@ std::unique_ptr CStringTable::BuildDependencyTree() const // Load texture IDs TStringList::iterator Iter = Params.begin(); - for (uint ParamIdx = 0; ParamIdx < Params.size(); ParamIdx++, Iter++) + for (uint ParamIdx = 0; ParamIdx < Params.size(); ParamIdx++, ++Iter) { if (ParamIdx >= TexturesStart) { @@ -365,8 +369,9 @@ TString CStringTable::StripFormatting(const TString& kInString) if (Out[CharIdx] == '&') { if (TagStart == -1) + { TagStart = CharIdx; - + } else { Out.Remove(TagStart, 1); @@ -374,11 +379,10 @@ TString CStringTable::StripFormatting(const TString& kInString) CharIdx--; } } - else if (TagStart != -1 && Out[CharIdx] == ';') { - int TagEnd = CharIdx + 1; - int TagLen = TagEnd - TagStart; + const int TagEnd = CharIdx + 1; + const int TagLen = TagEnd - TagStart; Out.Remove(TagStart, TagLen); CharIdx = TagStart - 1; TagStart = -1; diff --git a/src/Core/Resource/StringTable/CStringTable.h b/src/Core/Resource/StringTable/CStringTable.h index 59bd64ce..3f470134 100644 --- a/src/Core/Resource/StringTable/CStringTable.h +++ b/src/Core/Resource/StringTable/CStringTable.h @@ -53,34 +53,34 @@ public: explicit CStringTable(CResourceEntry *pEntry = nullptr) : CResource(pEntry) {} /** Returns the number of languages in the table */ - uint NumLanguages() const { return mLanguages.size(); } + size_t NumLanguages() const { return mLanguages.size(); } /** Returns the number of strings in the table */ - uint NumStrings() const { return mLanguages.empty() ? 0 : mLanguages[0].Strings.size(); } + size_t NumStrings() const { return mLanguages.empty() ? 0 : mLanguages[0].Strings.size(); } /** Returns languages used by index */ - ELanguage LanguageByIndex(uint Index) const { return mLanguages.size() > Index ? mLanguages[Index].Language : ELanguage::Invalid; } + ELanguage LanguageByIndex(size_t Index) const { return mLanguages.size() > Index ? mLanguages[Index].Language : ELanguage::Invalid; } /** Returns the string name by string index. May be blank if the string at the requested index is unnamed */ - TString StringNameByIndex(uint Index) const { return mStringNames.size() > Index ? mStringNames[Index] : ""; } + TString StringNameByIndex(size_t Index) const { return mStringNames.size() > Index ? mStringNames[Index] : ""; } /** Returns a string given a language/index pair */ - TString GetString(ELanguage Language, uint StringIndex) const; + TString GetString(ELanguage Language, size_t StringIndex) const; /** Updates a string for a given language */ - void SetString(ELanguage Language, uint StringIndex, const TString& kNewString); + void SetString(ELanguage Language, size_t StringIndex, TString kNewString); /** Updates a string name */ - void SetStringName(uint StringIndex, const TString& kNewName); + void SetStringName(size_t StringIndex, TString kNewName); /** Move string to another position in the table */ - void MoveString(uint StringIndex, uint NewIndex); + void MoveString(size_t StringIndex, size_t NewIndex); /** Add a new string to the table */ - void AddString(uint AtIndex); + void AddString(size_t AtIndex); /** Remove a string from the table */ - void RemoveString(uint StringIndex); + void RemoveString(size_t StringIndex); /** Initialize new resource data */ void InitializeNewResource() override; diff --git a/src/Editor/StringEditor/CStringEditor.cpp b/src/Editor/StringEditor/CStringEditor.cpp index 365946ff..558afb14 100644 --- a/src/Editor/StringEditor/CStringEditor.cpp +++ b/src/Editor/StringEditor/CStringEditor.cpp @@ -115,9 +115,9 @@ void CStringEditor::InitUI() // Set up language tabs mpUI->EditLanguageTabBar->setExpanding(false); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { - ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx); + const ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx); const char* pkLanguageName = TEnumReflection::ConvertValueToString(Language); mpUI->EditLanguageTabBar->addTab(pkLanguageName); } @@ -197,14 +197,14 @@ void CStringEditor::LoadSettings() QSettings Settings; // Set language - ELanguage Language = (ELanguage) Settings.value(gkpLanguageSetting, (int) ELanguage::English).toInt(); + const auto Language = static_cast(Settings.value(gkpLanguageSetting, static_cast(ELanguage::English)).toInt()); - for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) + for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) { if (mpStringTable->LanguageByIndex(LanguageIdx) == Language) { SetActiveLanguage(Language); - mpUI->EditLanguageTabBar->setCurrentIndex(LanguageIdx); + mpUI->EditLanguageTabBar->setCurrentIndex(static_cast(LanguageIdx)); break; } } @@ -246,17 +246,17 @@ void CStringEditor::UpdateUI() mpUI->RemoveStringButton->setEnabled( pSelectionModel->hasSelection() ); // Update language tabs - uint LanguageIndex = mpUI->EditLanguageTabBar->currentIndex(); - ELanguage TabLanguage = mpStringTable->LanguageByIndex(LanguageIndex); + const auto LanguageIndex = static_cast(mpUI->EditLanguageTabBar->currentIndex()); + const ELanguage TabLanguage = mpStringTable->LanguageByIndex(LanguageIndex); if (TabLanguage != mCurrentLanguage) { - for (uint LangIdx = 0; LangIdx < mpStringTable->NumLanguages(); LangIdx++) + for (size_t LangIdx = 0; LangIdx < mpStringTable->NumLanguages(); LangIdx++) { if (mpStringTable->LanguageByIndex(LangIdx) == mCurrentLanguage) { mpUI->EditLanguageTabBar->blockSignals(true); - mpUI->EditLanguageTabBar->setCurrentIndex(LangIdx); + mpUI->EditLanguageTabBar->setCurrentIndex(static_cast(LangIdx)); mpUI->EditLanguageTabBar->blockSignals(false); break; } @@ -295,14 +295,14 @@ void CStringEditor::OnStringSelected(const QModelIndex& kIndex) void CStringEditor::OnLanguageChanged(int LanguageIndex) { - ASSERT( LanguageIndex >= 0 && LanguageIndex < (int) mpStringTable->NumLanguages() ); - ELanguage Language = mpStringTable->LanguageByIndex(LanguageIndex); + ASSERT(LanguageIndex >= 0 && LanguageIndex < static_cast(mpStringTable->NumLanguages())); + const ELanguage Language = mpStringTable->LanguageByIndex(LanguageIndex); - if (Language != mCurrentLanguage) - { - IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, Language); - UndoStack().push(pCommand); - } + if (Language == mCurrentLanguage) + return; + + IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, Language); + UndoStack().push(pCommand); } void CStringEditor::OnStringNameEdited() @@ -312,7 +312,8 @@ void CStringEditor::OnStringNameEdited() if (mpStringTable->StringNameByIndex(mCurrentStringIndex) != NewName) { IUndoCommand* pCommand = new TSerializeUndoCommand("Edit String Name", mpStringTable, false); - mpStringTable->SetStringName( mCurrentStringIndex, NewName ); + + mpStringTable->SetStringName(mCurrentStringIndex, std::move(NewName)); mIsEditingStringName = true; UndoStack().push(pCommand); } @@ -320,12 +321,13 @@ void CStringEditor::OnStringNameEdited() void CStringEditor::OnStringTextEdited() { - TString NewText = TO_TSTRING( mpUI->StringTextEdit->toPlainText() ); + TString NewText = TO_TSTRING(mpUI->StringTextEdit->toPlainText()); if (mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex) != NewText) { IUndoCommand* pCommand = new TSerializeUndoCommand("Edit String", mpStringTable, false); - mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, NewText); + + mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, std::move(NewText)); mIsEditingStringData = true; UndoStack().push(pCommand); } @@ -355,13 +357,13 @@ void CStringEditor::OnRemoveString() if (mpUI->StringNameListView->selectionModel()->hasSelection()) { UndoStack().beginMacro("Remove String"); - uint Index = mCurrentStringIndex; + const size_t Index = mCurrentStringIndex; // Change selection to a new string. // Do this before actually removing the string so that if the action is undone, the // editor will not attempt to re-select the string before it gets readded to the table. - uint NewStringCount = mpStringTable->NumStrings() - 1; - uint NewIndex = (Index >= NewStringCount ? NewStringCount - 1 : Index); + const size_t NewStringCount = mpStringTable->NumStrings() - 1; + const size_t NewIndex = (Index >= NewStringCount ? NewStringCount - 1 : Index); IUndoCommand* pCommand = new CSetStringIndexCommand(this, Index, NewIndex); UndoStack().push(pCommand); @@ -406,39 +408,39 @@ void CStringEditor::IncrementStringIndex() void CStringEditor::DecrementStringIndex() { - uint NewIndex = mCurrentStringIndex - 1; + const uint32 NewIndex = mCurrentStringIndex - 1; - if (NewIndex != -1) - { - IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex); - UndoStack().push(pCommand); - } + if (NewIndex == UINT32_MAX) + return; + + IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex); + UndoStack().push(pCommand); } void CStringEditor::IncrementLanguageIndex() { - for (uint i=0; iNumLanguages() - 1; i++) + for (size_t i = 0; i < mpStringTable->NumLanguages() - 1; i++) { - if (mpStringTable->LanguageByIndex(i) == mCurrentLanguage) - { - ELanguage NewLanguage = mpStringTable->LanguageByIndex(i+1); - IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage); - UndoStack().push(pCommand); - break; - } + if (mpStringTable->LanguageByIndex(i) != mCurrentLanguage) + continue; + + const ELanguage NewLanguage = mpStringTable->LanguageByIndex(i + 1); + IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage); + UndoStack().push(pCommand); + break; } } void CStringEditor::DecrementLanguageIndex() { - for (uint i=mpStringTable->NumLanguages() - 1; i>0; i--) + for (size_t i = mpStringTable->NumLanguages() - 1; i > 0; i--) { - if (mpStringTable->LanguageByIndex(i) == mCurrentLanguage) - { - ELanguage NewLanguage = mpStringTable->LanguageByIndex(i-1); - IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage); - UndoStack().push(pCommand); - break; - } + if (mpStringTable->LanguageByIndex(i) != mCurrentLanguage) + continue; + + const ELanguage NewLanguage = mpStringTable->LanguageByIndex(i - 1); + IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage); + UndoStack().push(pCommand); + break; } } diff --git a/src/Editor/StringEditor/CStringListModel.cpp b/src/Editor/StringEditor/CStringListModel.cpp index 97810d95..0d191a1d 100644 --- a/src/Editor/StringEditor/CStringListModel.cpp +++ b/src/Editor/StringEditor/CStringListModel.cpp @@ -16,26 +16,25 @@ CStringListModel::CStringListModel(CStringEditor* pInEditor) /** Change the preview language display */ void CStringListModel::SetPreviewLanguage(ELanguage InLanguage) { - if (mStringPreviewLanguage != InLanguage) - { - mStringPreviewLanguage = InLanguage; + if (mStringPreviewLanguage == InLanguage) + return; - // Emit data changed for user role for the full range of strings - int NumStrings = mpStringTable ? mpStringTable->NumStrings() : 0; + mStringPreviewLanguage = InLanguage; - if (NumStrings) - { - QVector Roles; - Roles << Qt::UserRole; - emit dataChanged( index(0), index(NumStrings-1), Roles ); - } - } + // Emit data changed for user role for the full range of strings + const int NumStrings = mpStringTable ? static_cast(mpStringTable->NumStrings()) : 0; + if (NumStrings == 0) + return; + + QVector Roles; + Roles << Qt::UserRole; + emit dataChanged(index(0), index(NumStrings - 1), Roles); } /** QAbstractListModel interface */ int CStringListModel::rowCount(const QModelIndex& kParent) const { - return mpStringTable ? mpStringTable->NumStrings() : 0; + return mpStringTable ? static_cast(mpStringTable->NumStrings()) : 0; } QVariant CStringListModel::data(const QModelIndex& kIndex, int Role) const @@ -45,7 +44,7 @@ QVariant CStringListModel::data(const QModelIndex& kIndex, int Role) const return QVariant::Invalid; } - int StringIndex = kIndex.row(); + const auto StringIndex = static_cast(kIndex.row()); // display/tooltip role: return the string name if (Role == Qt::DisplayRole || Role == Qt::ToolTipRole) @@ -131,13 +130,13 @@ bool CStringListModel::dropMimeData(const QMimeData* pkData, Qt::DropAction Acti } // If the user placed the string at the end of the list, then the index we receive // will be out of range, so cap it to a valid index. - else if (Row >= (int) mpStringTable->NumStrings()) + else if (Row >= static_cast(mpStringTable->NumStrings())) { - Row = mpStringTable->NumStrings() - 1; + Row = static_cast(mpStringTable->NumStrings()) - 1; } // If the string is being moved further down the list, then account for the fact that // the rest of the strings below it will be bumped up. - else if (Row > (int) pkStringMimeData->StringIndex()) + else if (Row > static_cast(pkStringMimeData->StringIndex())) { Row--; }