Switch CStringTable over to using UTF-8 internally
This commit is contained in:
parent
e950634db2
commit
fc29370427
|
@ -517,20 +517,20 @@ void GenerateAssetNames(CGameProject *pProj)
|
|||
{
|
||||
if (It->IsNamed()) continue;
|
||||
CStringTable *pString = (CStringTable*) It->Load();
|
||||
TWideString String;
|
||||
TString String;
|
||||
|
||||
for (u32 iStr = 0; iStr < pString->NumStrings() && String.IsEmpty(); iStr++)
|
||||
String = CStringTable::StripFormatting( pString->String("ENGL", iStr) ).Trimmed();
|
||||
|
||||
if (!String.IsEmpty())
|
||||
{
|
||||
TWideString Name = String.SubString(0, Math::Min<u32>(String.Size(), 50)).Trimmed();
|
||||
Name.Replace(L"\n", L" ");
|
||||
TString Name = String.SubString(0, Math::Min<u32>(String.Size(), 50)).Trimmed();
|
||||
Name.Replace("\n", " ");
|
||||
|
||||
while (Name.EndsWith(L".") || TWideString::IsWhitespace(Name.Back()))
|
||||
while (Name.EndsWith(".") || TString::IsWhitespace(Name.Back()))
|
||||
Name = Name.ChopBack(1);
|
||||
|
||||
ApplyGeneratedName(pString->Entry(), kStringsDir, Name.ToUTF8());
|
||||
ApplyGeneratedName(pString->Entry(), kStringsDir, Name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@ class CStringTable : public CResource
|
|||
struct SLangTable
|
||||
{
|
||||
CFourCC Language;
|
||||
std::vector<TWideString> Strings;
|
||||
std::vector<TString> Strings;
|
||||
};
|
||||
std::vector<SLangTable> mLangTables;
|
||||
|
||||
|
@ -28,10 +28,10 @@ public:
|
|||
inline u32 NumStrings() const { return mNumStrings; }
|
||||
inline u32 NumLanguages() const { return mLangTables.size(); }
|
||||
inline CFourCC LanguageTag(u32 Index) const { return mLangTables[Index].Language; }
|
||||
inline TWideString String(u32 LangIndex, u32 StringIndex) const { return mLangTables[LangIndex].Strings[StringIndex]; }
|
||||
inline TString StringName(u32 StringIndex) const { return mStringNames[StringIndex]; }
|
||||
inline TString String(u32 LangIndex, u32 StringIndex) const { return mLangTables[LangIndex].Strings[StringIndex]; }
|
||||
inline TString StringName(u32 StringIndex) const { return mStringNames[StringIndex]; }
|
||||
|
||||
TWideString String(CFourCC Lang, u32 StringIndex) const
|
||||
TString String(CFourCC Lang, u32 StringIndex) const
|
||||
{
|
||||
for (u32 iLang = 0; iLang < NumLanguages(); iLang++)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
return String(iLang, StringIndex);
|
||||
}
|
||||
|
||||
return TWideString();
|
||||
return TString();
|
||||
}
|
||||
|
||||
CDependencyTree* BuildDependencyTree() const
|
||||
|
@ -54,53 +54,53 @@ public:
|
|||
|
||||
for (u32 iStr = 0; iStr < rkTable.Strings.size(); iStr++)
|
||||
{
|
||||
const TWideString& rkStr = rkTable.Strings[iStr];
|
||||
const TString& rkStr = rkTable.Strings[iStr];
|
||||
|
||||
for (u32 TagIdx = rkStr.IndexOf(L'&'); TagIdx != -1; TagIdx = rkStr.IndexOf(L'&', TagIdx + 1))
|
||||
for (u32 TagIdx = rkStr.IndexOf('&'); TagIdx != -1; TagIdx = rkStr.IndexOf('&', TagIdx + 1))
|
||||
{
|
||||
// Check for double ampersand (escape character in DKCR, not sure about other games)
|
||||
if (rkStr.At(TagIdx + 1) == L'&')
|
||||
if (rkStr.At(TagIdx + 1) == '&')
|
||||
{
|
||||
TagIdx++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get tag name and parameters
|
||||
u32 NameEnd = rkStr.IndexOf(L'=', TagIdx);
|
||||
u32 TagEnd = rkStr.IndexOf(L';', TagIdx);
|
||||
u32 NameEnd = rkStr.IndexOf('=', TagIdx);
|
||||
u32 TagEnd = rkStr.IndexOf(';', TagIdx);
|
||||
if (NameEnd == -1 || TagEnd == -1) continue;
|
||||
|
||||
TWideString TagName = rkStr.SubString(TagIdx + 1, NameEnd - TagIdx - 1);
|
||||
TWideString ParamString = rkStr.SubString(NameEnd + 1, TagEnd - NameEnd - 1);
|
||||
TString TagName = rkStr.SubString(TagIdx + 1, NameEnd - TagIdx - 1);
|
||||
TString ParamString = rkStr.SubString(NameEnd + 1, TagEnd - NameEnd - 1);
|
||||
|
||||
// Font
|
||||
if (TagName == L"font")
|
||||
if (TagName == "font")
|
||||
{
|
||||
if (Game() >= eCorruptionProto)
|
||||
{
|
||||
ASSERT(ParamString.StartsWith(L"0x"));
|
||||
ASSERT(ParamString.StartsWith("0x"));
|
||||
ParamString = ParamString.ChopFront(2);
|
||||
}
|
||||
|
||||
ASSERT(ParamString.Size() == IDLength * 2);
|
||||
pTree->AddDependency( CAssetID::FromString(ParamString.ToUTF8()) );
|
||||
pTree->AddDependency( CAssetID::FromString(ParamString) );
|
||||
}
|
||||
|
||||
// Image
|
||||
else if (TagName == L"image")
|
||||
else if (TagName == "image")
|
||||
{
|
||||
// Determine which params are textures based on image type
|
||||
TWideStringList Params = ParamString.Split(L",");
|
||||
TWideString ImageType = Params.front();
|
||||
TStringList Params = ParamString.Split(",");
|
||||
TString ImageType = Params.front();
|
||||
u32 TexturesStart = -1;
|
||||
|
||||
if (ImageType == L"A")
|
||||
if (ImageType == "A")
|
||||
TexturesStart = 2;
|
||||
|
||||
else if (ImageType == L"SI")
|
||||
else if (ImageType == "SI")
|
||||
TexturesStart = 3;
|
||||
|
||||
else if (ImageType == L"SA")
|
||||
else if (ImageType == "SA")
|
||||
TexturesStart = 4;
|
||||
|
||||
else if (ImageType.IsHexString(false, IDLength * 2))
|
||||
|
@ -108,28 +108,28 @@ public:
|
|||
|
||||
else
|
||||
{
|
||||
Log::Error("Unrecognized image type: " + ImageType.ToUTF8());
|
||||
Log::Error("Unrecognized image type: " + ImageType);
|
||||
DEBUG_BREAK;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load texture IDs
|
||||
TWideStringList::iterator Iter = Params.begin();
|
||||
TStringList::iterator Iter = Params.begin();
|
||||
|
||||
for (u32 iParam = 0; iParam < Params.size(); iParam++, Iter++)
|
||||
{
|
||||
if (iParam >= TexturesStart)
|
||||
{
|
||||
TWideString Param = *Iter;
|
||||
TString Param = *Iter;
|
||||
|
||||
if (Game() >= eCorruptionProto)
|
||||
{
|
||||
ASSERT(Param.StartsWith(L"0x"));
|
||||
ASSERT(Param.StartsWith("0x"));
|
||||
Param = Param.ChopFront(2);
|
||||
}
|
||||
|
||||
ASSERT(Param.Size() == IDLength * 2);
|
||||
pTree->AddDependency( CAssetID::FromString(Param.ToUTF8()) );
|
||||
pTree->AddDependency( CAssetID::FromString(Param) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,14 +140,14 @@ public:
|
|||
return pTree;
|
||||
}
|
||||
|
||||
static TWideString StripFormatting(const TWideString& rkStr)
|
||||
static TString StripFormatting(const TString& rkStr)
|
||||
{
|
||||
TWideString Out = rkStr;
|
||||
TString Out = rkStr;
|
||||
int TagStart = -1;
|
||||
|
||||
for (u32 iChr = 0; iChr < Out.Size(); iChr++)
|
||||
{
|
||||
if (Out[iChr] == L'&')
|
||||
if (Out[iChr] == '&')
|
||||
{
|
||||
if (TagStart == -1)
|
||||
TagStart = iChr;
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
else if (TagStart != -1 && Out[iChr] == L';')
|
||||
else if (TagStart != -1 && Out[iChr] == ';')
|
||||
{
|
||||
int TagEnd = iChr + 1;
|
||||
int TagLen = TagEnd - TagStart;
|
||||
|
|
|
@ -63,7 +63,7 @@ void CWorld::SetAreaLayerInfo(CGameArea *pArea)
|
|||
TString CWorld::InGameName() const
|
||||
{
|
||||
if (mpWorldName)
|
||||
return mpWorldName->String("ENGL", 0).ToUTF8();
|
||||
return mpWorldName->String("ENGL", 0);
|
||||
else
|
||||
return Entry()->Name();
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ TString CWorld::AreaInGameName(u32 AreaIndex) const
|
|||
const SArea& rkArea = mAreas[AreaIndex];
|
||||
|
||||
if (rkArea.pAreaName)
|
||||
return rkArea.pAreaName->String("ENGL", 0).ToUTF8();
|
||||
return rkArea.pAreaName->String("ENGL", 0);
|
||||
else
|
||||
return "!!" + rkArea.InternalName;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ void CStringLoader::LoadPrimeDemoSTRG(IInputStream& rSTRG)
|
|||
for (u32 iStr = 0; iStr < NumStrings; iStr++)
|
||||
{
|
||||
rSTRG.Seek(TableStart + StringOffsets[iStr], SEEK_SET);
|
||||
Lang->Strings[iStr] = rSTRG.ReadWString();
|
||||
Lang->Strings[iStr] = rSTRG.ReadWString().ToUTF8();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ void CStringLoader::LoadPrimeSTRG(IInputStream& rSTRG)
|
|||
for (u32 iStr = 0; iStr < NumStrings; iStr++)
|
||||
{
|
||||
rSTRG.Seek(LangStart + StringOffsets[iStr], SEEK_SET);
|
||||
pLang->Strings[iStr] = rSTRG.ReadWString();
|
||||
pLang->Strings[iStr] = rSTRG.ReadWString().ToUTF8();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ void CStringLoader::LoadCorruptionSTRG(IInputStream& rSTRG)
|
|||
rSTRG.Seek(StringsStart + LangOffsets[iLang][iStr], SEEK_SET);
|
||||
rSTRG.Seek(0x4, SEEK_CUR); // Skipping string size
|
||||
|
||||
pLang->Strings[iStr] = rSTRG.ReadString().ToUTF16();
|
||||
pLang->Strings[iStr] = rSTRG.ReadString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue