Browse Source

Provide some sample conversions to plFormat for testing and copying

Michael Hansen 11 years ago
parent
commit
933ae6ec17
  1. 2
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 2
      Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp
  3. 14
      Sources/Plasma/Apps/plUruLauncher/winmain.cpp
  4. 6
      Sources/Plasma/CoreLib/HeadSpin.cpp
  5. 6
      Sources/Plasma/CoreLib/hsStream.cpp
  6. 10
      Sources/Plasma/CoreLib/plFileSystem.cpp
  7. 8
      Sources/Plasma/CoreLib/plProduct.cpp
  8. 5
      Sources/Plasma/CoreLib/plString.cpp
  9. 10
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
  10. 16
      Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp
  11. 22
      Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h
  12. 2
      Sources/Plasma/PubUtilLib/plUnifiedTime/plUnifiedTime.cpp

2
Sources/Plasma/Apps/plClient/winmain.cpp

@ -1053,7 +1053,7 @@ BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
// When general.ini gets expanded, this will need to find a proper home somewhere.
{
plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini");
plString ini_str = plString::Format("App.SetLanguage %s\n", plLocalization::GetLanguageName(new_language));
plString ini_str = plFormat("App.SetLanguage {}\n", plLocalization::GetLanguageName(new_language));
hsStream* gini = plEncryptedStream::OpenEncryptedFileWrite(gipath);
gini->WriteString(ini_str);
gini->Close();

2
Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp

@ -354,7 +354,7 @@ static void IGotFileServIPs(ENetError result, void* param, const wchar_t* addr)
static void IEapSucksErrorProc(ENetProtocol protocol, ENetError error)
{
if (s_errorProc) {
plString msg = plString::Format("Protocol: %S", NetProtocolToString(protocol));
plString msg = plFormat("Protocol: {}", NetProtocolToString(protocol));
s_errorProc(error, msg);
}
}

14
Sources/Plasma/Apps/plUruLauncher/winmain.cpp

@ -185,7 +185,7 @@ static void PumpMessages()
static void IOnDownloadBegin(const plFileName& file)
{
plString msg = plString::Format("Downloading... %s", file.AsString().c_str());
plString msg = plFormat("Downloading... {}", file);
SetDlgItemTextW(s_dialog, IDC_TEXT, msg.ToWchar());
}
@ -195,8 +195,8 @@ static void IOnProgressTick(uint64_t curBytes, uint64_t totalBytes, const plStri
IShowMarquee(false);
// DL size
plString size = plString::Format("%s / %s", plFileSystem::ConvertFileSize(curBytes).c_str(),
plFileSystem::ConvertFileSize(totalBytes).c_str());
plString size = plFormat("{} / {}", plFileSystem::ConvertFileSize(curBytes),
plFileSystem::ConvertFileSize(totalBytes));
SetDlgItemTextW(s_dialog, IDC_DLSIZE, size.ToWchar());
// DL speed
@ -243,7 +243,7 @@ static handleptr_t ICreateProcess(const plFileName& exe, const plString& args)
si.cb = sizeof(si);
// Create wchar things and stuff :/
plString cmd = plString::Format("%s %s", exe.AsString().c_str(), args.c_str());
plString cmd = plFormat("{} {}", exe, args);
plStringBuffer<wchar_t> file = exe.AsString().ToWchar();
plStringBuffer<wchar_t> params = cmd.ToWchar();
@ -296,7 +296,7 @@ static handleptr_t ICreateProcess(const plFileName& exe, const plString& args)
static bool IInstallRedist(const plFileName& exe)
{
ISetDownloadStatus(plString::Format("Installing... %s", exe.AsString().c_str()));
ISetDownloadStatus(plFormat("Installing... {}", exe));
Sleep(2500); // let's Sleep for a bit so the user can see that we're doing something before the UAC dialog pops up!
// Try to guess some arguments... Unfortunately, the file manifest format is fairly immutable.
@ -350,7 +350,7 @@ static void IOnNetError(ENetError result, const plString& msg)
if (s_taskbar)
s_taskbar->SetProgressState(s_dialog, TBPF_ERROR);
s_error = plString::Format("Error: %S\r\n%s", NetErrorAsString(result), msg.c_str());
s_error = plFormat("Error: {}\r\n{}", NetErrorAsString(result), msg);
IQuit(PLASMA_PHAILURE);
}
@ -394,7 +394,7 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
// Ensure there is only ever one patcher running...
if (IsPatcherRunning()) {
plString text = plString::Format("%s is already running", plProduct::LongName().c_str());
plString text = plFormat("{} is already running", plProduct::LongName());
IShowErrorDialog(text.ToWchar());
return PLASMA_OK;
}

6
Sources/Plasma/CoreLib/HeadSpin.cpp

@ -49,7 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop
#include "hsTemplates.h"
#include "plString.h"
#include "plFormat.h"
///////////////////////////////////////////////////////////////////////////
@ -535,7 +535,7 @@ std::vector<plString> DisplaySystemVersion()
if ( osvi.dwMajorVersion <= 4 )
{
versionStrs.push_back(plString::Format("version %d.%d %s (Build %d)\n",
versionStrs.push_back(plFormat("version {}.{} {} (Build {})\n",
osvi.dwMajorVersion,
osvi.dwMinorVersion,
osvi.szCSDVersion,
@ -543,7 +543,7 @@ std::vector<plString> DisplaySystemVersion()
}
else
{
versionStrs.push_back(plString::Format("%s (Build %d)\n",
versionStrs.push_back(plFormat("{} (Build {})\n",
osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF));
}

6
Sources/Plasma/CoreLib/hsStream.cpp

@ -204,8 +204,8 @@ plString hsStream::ReadSafeWStringLong()
uint32_t hsStream::WriteSafeString(const plString &string)
{
int len = string.GetSize();
hsAssert(len<0xf000, plString::Format("string len of %d is too long for WriteSafeString %s, use WriteSafeStringLong",
len, string.c_str()).c_str() );
hsAssert(len<0xf000, plFormat("string len of {} is too long for WriteSafeString {}, use WriteSafeStringLong",
len, string).c_str() );
WriteLE16(len | 0xf000);
if (len > 0)
@ -226,7 +226,7 @@ uint32_t hsStream::WriteSafeWString(const plString &string)
{
plStringBuffer<uint16_t> wbuff = string.ToUtf16();
uint32_t len = wbuff.GetSize();
hsAssert(len<0xf000, plString::Format("string len of %d is too long for WriteSafeWString, use WriteSafeWStringLong",
hsAssert(len<0xf000, plFormat("string len of {} is too long for WriteSafeWString, use WriteSafeWStringLong",
len).c_str() );
WriteLE16(len | 0xf000);

10
Sources/Plasma/CoreLib/plFileSystem.cpp

@ -187,10 +187,8 @@ plFileName plFileName::Join(const plFileName &base, const plFileName &path)
char last = base.fName.CharAt(base.GetSize() - 1);
char first = path.fName.CharAt(0);
if (last != '/' && last != '\\') {
if (first != '/' && first != '\\') {
return plString::Format("%s" PATH_SEPARATOR_STR "%s",
base.fName.c_str(), path.fName.c_str());
}
if (first != '/' && first != '\\')
return plFormat("{}" PATH_SEPARATOR_STR "{}", base, path);
return base.fName + path.fName;
} else if (first != '/' && first != '\\') {
return base.fName + path.fName;
@ -549,7 +547,7 @@ plString plFileSystem::ConvertFileSize(uint64_t size)
{
const char* labels[] = { "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" };
if (size < 1024)
return plString::Format("%i B");
return plFormat("{} B", size);
uint64_t last_div = size;
for (size_t i = 0; i < arrsize(labels); ++i) {
@ -566,5 +564,5 @@ plString plFileSystem::ConvertFileSize(uint64_t size)
}
// this should never happen
return plString::Format("%i %s", last_div, labels[arrsize(labels) - 1]);
return plFormat("{} {}", last_div, labels[arrsize(labels) - 1]);
}

8
Sources/Plasma/CoreLib/plProduct.cpp

@ -44,7 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop
#include "plProduct.h"
#include "plString.h"
#include "plFormat.h"
static_assert(PRODUCT_BUILD_ID > 0, "Build ID cannot be zero");
static_assert(PRODUCT_BUILD_TYPE > 0, "Build Type cannot be zero");
@ -89,8 +89,8 @@ const char *plProduct::UUID() { return PRODUCT_UUID; }
plString plProduct::ProductString()
{
static plString _cache = plString::Format(
"%s.%u.%u - " RELEASE_ACCESS "." RELEASE_TYPE,
CoreName().c_str(), BranchId(), BuildId());
static plString _cache = plFormat(
"{}.{}.{} - " RELEASE_ACCESS "." RELEASE_TYPE,
CoreName(), BranchId(), BuildId());
return _cache;
}

5
Sources/Plasma/CoreLib/plString.cpp

@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop
#include "plString.h"
#include "plFormat.h"
#include <regex>
const plString plString::Null;
@ -609,7 +610,7 @@ bool plString::REMatch(const char *pattern, CaseSensitivity sense) const
if (std::regex_match(c_str(), re))
return true;
} catch (const std::regex_error& e) {
hsAssert(0, plString::Format("Regex match error: %s", e.what()).c_str());
hsAssert(0, plFormat("Regex match error: {}", e.what()).c_str());
}
return false;
@ -633,7 +634,7 @@ std::vector<plString> plString::RESearch(const char *pattern,
for (size_t i = 0; i < matches.size(); ++i)
substrings[i] = matches[i].str().c_str();
} catch (const std::regex_error& e) {
hsAssert(0, plString::Format("Regex search error: %s", e.what()).c_str());
hsAssert(0, plFormat("Regex search error: {}", e.what()).c_str());
}
return substrings;

10
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp

@ -251,7 +251,7 @@ void plNetClientMgr::SetNullSend(bool on)
const char* plNetClientMgr::GetServerLogTimeAsString(plString& timestamp) const
{
const plUnifiedTime st=GetServerTime();
timestamp = plString::Format("{%02d/%02d %02d:%02d:%02d}",
timestamp = plFormat("{{{_02}/{_02} {_02}:{_02}:{_02}}",
st.GetMonth(), st.GetDay(), st.GetHour(), st.GetMinute(), st.GetSecond());
return timestamp.c_str();
}
@ -264,7 +264,7 @@ const char* ProcessTab(const char* fmt)
static plString s;
if (fmt && *fmt=='\t')
{
s = plString::Format(" %s", fmt);
s = plFormat(" {}", fmt);
return s.c_str();
}
return fmt;
@ -1230,7 +1230,7 @@ void plNetClientMgr::IDisableNet () {
if (!GetFlagsBit(plNetClientApp::kPlayingGame))
{
// KI may not be loaded
plString title = plString::Format("%s Error", plProduct::CoreName().c_str());
plString title = plFormat("{} Error", plProduct::CoreName());
hsMessageBox(fDisableMsg->str, title.c_str(), hsMessageBoxNormal, hsMessageBoxIconError );
plClientMsg *quitMsg = new plClientMsg(plClientMsg::kQuit);
quitMsg->Send(hsgResMgr::ResMgr()->FindKey(kClient_KEY));
@ -1356,8 +1356,8 @@ bool plNetClientMgr::IFindModifier(plSynchedObject* obj, int16_t classIdx)
cnt++;
}
hsAssert(cnt<2, plString::Format("Object %s has multiple SDL modifiers of the same kind (%s)?",
obj->GetKeyName().c_str(), plFactory::GetNameOfClass(classIdx)).c_str());
hsAssert(cnt<2, plFormat("Object {} has multiple SDL modifiers of the same kind ({})?",
obj->GetKeyName(), plFactory::GetNameOfClass(classIdx)).c_str());
return cnt==0 ? false : true;
}

16
Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp

@ -957,9 +957,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
plString title;
unsigned nameLen = nc->GetPlayerName().GetSize();
if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
title = plString::Format("%s'", nc->GetPlayerName().c_str());
title = plFormat("{}'", nc->GetPlayerName());
else
title = plString::Format("%s's", nc->GetPlayerName().c_str());
title = plFormat("{}'s", nc->GetPlayerName());
info->SetAgeUserDefinedName(title.c_str());
}
if (!info->HasAgeDescription())
@ -968,9 +968,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
plString desc;
unsigned nameLen = nc->GetPlayerName().GetSize();
if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
desc = plFormat("{}' {}", nc->GetPlayerName(), info->GetAgeInstanceName());
else
desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
desc = plFormat("{}'s {}", nc->GetPlayerName(), info->GetAgeInstanceName());
info->SetAgeDescription(desc.c_str());
}
if (!info->HasAgeInstanceGuid()) {
@ -996,9 +996,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
plString title;
unsigned nameLen = nc->GetPlayerName().GetSize();
if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
title = plString::Format("%s'", nc->GetPlayerName().c_str());
title = plFormat("{}'", nc->GetPlayerName());
else
title = plString::Format("%s's", nc->GetPlayerName().c_str());
title = plFormat("{}'s", nc->GetPlayerName());
info->SetAgeUserDefinedName(title.c_str());
}
@ -1008,9 +1008,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
plString desc;
unsigned nameLen = nc->GetPlayerName().GetSize();
if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
desc = plFormat("{}' {}", nc->GetPlayerName(), info->GetAgeInstanceName());
else
desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
desc = plFormat("{}'s {}", nc->GetPlayerName(), info->GetAgeInstanceName());
info->SetAgeDescription( desc.c_str() );
}

22
Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h

@ -330,7 +330,7 @@ public:
// debug
plString AsString() const
{
return plString::Format("object=%s, %s",fObjectHelper.GetUoid().StringIze().c_str(), plNetMessage::AsString().c_str());
return plFormat("object={}, {}",fObjectHelper.GetUoid(), plNetMessage::AsString());
}
};
@ -506,7 +506,7 @@ public:
plString AsString() const
{
const char* noc=plFactory::GetTheFactory()->GetNameOfClass(StreamInfo()->GetStreamType());
return plString::Format("%s %s",plNetMsgStream::AsString().c_str(), noc ? noc : "?");
return plFormat("{} {}", plNetMsgStream::AsString(), noc ? noc : "?");
}
};
@ -556,8 +556,8 @@ public:
// debug
plString AsString() const
{
return plString::Format("object=%s initial=%d, %s",fObjectHelper.GetUoid().StringIze().c_str(), fIsInitialState,
plNetMsgGameMessage::AsString().c_str());
return plFormat("object={} initial={}, {}",fObjectHelper.GetUoid(), fIsInitialState,
plNetMsgGameMessage::AsString());
}
};
@ -647,7 +647,7 @@ public:
// debug
plString AsString() const
{
return plString::Format("pageFlags:%02X, paging %s, requestingState:%s, resetting=%d",
return plFormat("pageFlags:{_02X}, paging {}, requestingState:{}, resetting={}",
fPageFlags, (fPageFlags&kPagingOut)?"out":"in",
(fPageFlags&kRequestState)?"yes":"no", (fPageFlags & kResetList)!=0);
}
@ -754,7 +754,7 @@ public:
// debug
plString AsString() const
{
return plString::Format("len=%d",fVoiceData.size());
return plFormat("len={}",fVoiceData.size());
}
};
@ -792,7 +792,7 @@ public:
// debug
plString AsString() const
{
return plString::Format("lockReq=%d, %s",fLockRequest, plNetMsgStreamedObject::AsString().c_str());
return plFormat("lockReq={}, {}",fLockRequest, plNetMsgStreamedObject::AsString());
}
};
@ -979,11 +979,11 @@ public:
plString b1, b2;
int i;
for(i=0;i<fRegionsImIn.GetNumBitVectors(); i++)
b1 += plString::Format("0x%x ", fRegionsImIn.GetBitVector(i));
b1 += plFormat("0x{x} ", fRegionsImIn.GetBitVector(i));
for(i=0;i<fRegionsICareAbout.GetNumBitVectors(); i++)
b2 += plString::Format("0x%x ", fRegionsICareAbout.GetBitVector(i));
return plString::Format("rgnsImIn:%s, rgnsICareAbout:%s, %s",
b1.c_str(), b2.c_str(), plNetMessage::AsString().c_str() );
b2 += plFormat("0x{x} ", fRegionsICareAbout.GetBitVector(i));
return plFormat("rgnsImIn:{}, rgnsICareAbout:{}, {}",
b1, b2, plNetMessage::AsString());
}
};

2
Sources/Plasma/PubUtilLib/plUnifiedTime/plUnifiedTime.cpp

@ -315,7 +315,7 @@ const char* plUnifiedTime::Print() const
const char* plUnifiedTime::PrintWMillis() const
{
static plString s;
s = plString::Format("%s,s:%lu,ms:%d",
s = plFormat("{},s:{},ms:{}",
Print(), (unsigned long)GetSecs(), GetMillis() );
return s.c_str();
}

Loading…
Cancel
Save