Code/Editor

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
monroegm-disable-blank-issue-2
Esteban Papp 4 years ago
parent 3b28267569
commit a14b4e478e

@ -526,7 +526,7 @@ void CBaseLibraryManager::Serialize(XmlNodeRef& node, bool bLoading)
QString CBaseLibraryManager::MakeUniqueItemName(const QString& srcName, const QString& libName)
{
// unlikely we'll ever encounter more than 16
std::vector<string> possibleDuplicates;
std::vector<AZStd::string> possibleDuplicates;
possibleDuplicates.reserve(16);
// search for strings in the database that might have a similar name (ignore case)
@ -550,7 +550,7 @@ QString CBaseLibraryManager::MakeUniqueItemName(const QString& srcName, const QS
const QString& name = pItem->GetName();
if (name.startsWith(srcName, Qt::CaseInsensitive))
{
possibleDuplicates.push_back(string(name.toUtf8().data()));
possibleDuplicates.push_back(AZStd::string(name.toUtf8().data()));
}
}
pEnum->Release();

@ -79,9 +79,9 @@ CEditorCommandManager::~CEditorCommandManager()
m_uiCommands.clear();
}
string CEditorCommandManager::GetFullCommandName(const AZStd::string& module, const string& name)
AZStd::string CEditorCommandManager::GetFullCommandName(const AZStd::string& module, const AZStd::string& name)
{
string fullName = module;
AZStd::string fullName = module;
fullName += ".";
fullName += name;
return fullName;
@ -91,10 +91,10 @@ bool CEditorCommandManager::AddCommand(CCommand* pCommand, TPfnDeleter deleter)
{
assert(pCommand);
string module = pCommand->GetModule();
string name = pCommand->GetName();
AZStd::string module = pCommand->GetModule();
AZStd::string name = pCommand->GetName();
if (IsRegistered(module, name) && m_bWarnDuplicate)
if (IsRegistered(module.c_str(), name.c_str()) && m_bWarnDuplicate)
{
QString errMsg;
@ -118,7 +118,7 @@ bool CEditorCommandManager::AddCommand(CCommand* pCommand, TPfnDeleter deleter)
bool CEditorCommandManager::UnregisterCommand(const char* module, const char* name)
{
string fullName = GetFullCommandName(module, name);
AZStd::string fullName = GetFullCommandName(module, name);
CommandTable::iterator itr = m_commands.find(fullName);
if (itr != m_commands.end())
@ -154,7 +154,7 @@ bool CEditorCommandManager::RegisterUICommand(
return false;
}
return AttachUIInfo(GetFullCommandName(module, name), uiInfo);
return AttachUIInfo(GetFullCommandName(module, name).c_str(), uiInfo);
}
bool CEditorCommandManager::AttachUIInfo(const char* fullCmdName, const CCommand0::SUIInfo& uiInfo)
@ -190,14 +190,14 @@ bool CEditorCommandManager::AttachUIInfo(const char* fullCmdName, const CCommand
return true;
}
bool CEditorCommandManager::GetUIInfo(const string& module, const string& name, CCommand0::SUIInfo& uiInfo) const
bool CEditorCommandManager::GetUIInfo(const AZStd::string& module, const AZStd::string& name, CCommand0::SUIInfo& uiInfo) const
{
string fullName = GetFullCommandName(module, name);
AZStd::string fullName = GetFullCommandName(module, name);
return GetUIInfo(fullName, uiInfo);
}
bool CEditorCommandManager::GetUIInfo(const string& fullCmdName, CCommand0::SUIInfo& uiInfo) const
bool CEditorCommandManager::GetUIInfo(const AZStd::string& fullCmdName, CCommand0::SUIInfo& uiInfo) const
{
CommandTable::const_iterator iter = m_commands.find(fullCmdName);
@ -223,9 +223,9 @@ int CEditorCommandManager::GenNewCommandId()
return uniqueId++;
}
QString CEditorCommandManager::Execute(const string& module, const string& name, const CCommand::CArgs& args)
QString CEditorCommandManager::Execute(const AZStd::string& module, const AZStd::string& name, const CCommand::CArgs& args)
{
string fullName = GetFullCommandName(module, name);
AZStd::string fullName = GetFullCommandName(module, name);
CommandTable::iterator iter = m_commands.find(fullName);
if (iter != m_commands.end())
@ -245,18 +245,18 @@ QString CEditorCommandManager::Execute(const string& module, const string& name,
return "";
}
QString CEditorCommandManager::Execute(const string& cmdLine)
QString CEditorCommandManager::Execute(const AZStd::string& cmdLine)
{
string cmdTxt, argsTxt;
AZStd::string cmdTxt, argsTxt;
size_t argStart = cmdLine.find_first_of(' ');
cmdTxt = cmdLine.substr(0, argStart);
argsTxt = "";
if (argStart != string::npos)
if (argStart != AZStd::string::npos)
{
argsTxt = cmdLine.substr(argStart + 1);
argsTxt.Trim();
AZ::StringFunc::TrimWhiteSpace(argsTxt, true, true);
}
CommandTable::iterator itr = m_commands.find(cmdTxt);
@ -301,7 +301,7 @@ void CEditorCommandManager::Execute(int commandId)
}
}
void CEditorCommandManager::GetCommandList(std::vector<string>& cmds) const
void CEditorCommandManager::GetCommandList(std::vector<AZStd::string>& cmds) const
{
cmds.clear();
cmds.reserve(m_commands.size());
@ -315,9 +315,9 @@ void CEditorCommandManager::GetCommandList(std::vector<string>& cmds) const
std::sort(cmds.begin(), cmds.end());
}
string CEditorCommandManager::AutoComplete(const string& substr) const
AZStd::string CEditorCommandManager::AutoComplete(const AZStd::string& substr) const
{
std::vector<string> cmds;
std::vector<AZStd::string> cmds;
GetCommandList(cmds);
// If substring is empty return first command.
@ -358,7 +358,7 @@ string CEditorCommandManager::AutoComplete(const string& substr) const
bool CEditorCommandManager::IsRegistered(const char* module, const char* name) const
{
string fullName = GetFullCommandName(module, name);
AZStd::string fullName = GetFullCommandName(module, name);
CommandTable::const_iterator iter = m_commands.find(fullName);
if (iter != m_commands.end())
@ -373,7 +373,7 @@ bool CEditorCommandManager::IsRegistered(const char* module, const char* name) c
bool CEditorCommandManager::IsRegistered(const char* cmdLine_) const
{
string cmdTxt, argsTxt, cmdLine(cmdLine_);
AZStd::string cmdTxt, argsTxt, cmdLine(cmdLine_);
size_t argStart = cmdLine.find_first_of(' ');
cmdTxt = cmdLine.substr(0, argStart);
CommandTable::const_iterator iter = m_commands.find(cmdTxt);
@ -402,9 +402,9 @@ bool CEditorCommandManager::IsRegistered(int commandId) const
return false;
}
void CEditorCommandManager::SetCommandAvailableInScripting(const string& module, const string& name)
void CEditorCommandManager::SetCommandAvailableInScripting(const AZStd::string& module, const AZStd::string& name)
{
string fullName = GetFullCommandName(module, name);
AZStd::string fullName = GetFullCommandName(module, name);
CommandTable::iterator iter = m_commands.find(fullName);
if (iter != m_commands.end())
@ -413,7 +413,7 @@ void CEditorCommandManager::SetCommandAvailableInScripting(const string& module,
}
}
bool CEditorCommandManager::IsCommandAvailableInScripting(const string& fullCmdName) const
bool CEditorCommandManager::IsCommandAvailableInScripting(const AZStd::string& fullCmdName) const
{
CommandTable::const_iterator iter = m_commands.find(fullCmdName);
@ -425,16 +425,16 @@ bool CEditorCommandManager::IsCommandAvailableInScripting(const string& fullCmdN
return false;
}
bool CEditorCommandManager::IsCommandAvailableInScripting(const string& module, const string& name) const
bool CEditorCommandManager::IsCommandAvailableInScripting(const AZStd::string& module, const AZStd::string& name) const
{
string fullName = GetFullCommandName(module, name);
AZStd::string fullName = GetFullCommandName(module, name);
return IsCommandAvailableInScripting(fullName);
}
void CEditorCommandManager::LogCommand(const string& fullCmdName, const CCommand::CArgs& args) const
void CEditorCommandManager::LogCommand(const AZStd::string& fullCmdName, const CCommand::CArgs& args) const
{
string cmdLine = fullCmdName;
AZStd::string cmdLine = fullCmdName;
for (int i = 0; i < args.GetArgCount(); ++i)
{
@ -509,7 +509,7 @@ void CEditorCommandManager::LogCommand(const string& fullCmdName, const CCommand
if (pScriptTermDialog)
{
string text = "> ";
AZStd::string text = "> ";
text += cmdLine;
text += "\r\n";
pScriptTermDialog->AppendText(text.c_str());
@ -526,14 +526,14 @@ QString CEditorCommandManager::ExecuteAndLogReturn(CCommand* pCommand, const CCo
return result;
}
void CEditorCommandManager::GetArgsFromString(const string& argsTxt, CCommand::CArgs& argList)
void CEditorCommandManager::GetArgsFromString(const AZStd::string& argsTxt, CCommand::CArgs& argList)
{
const char quoteSymbol = '\'';
int curPos = 0;
int prevPos = 0;
string arg = argsTxt.Tokenize(" ", curPos);
while (!arg.empty())
AZStd::vector<AZStd::string> tokens;
AZ::StringFunc::Tokenize(argsTxt, tokens, ' ');
for(AZStd::string& arg : tokens)
{
if (arg[0] == quoteSymbol) // A special consideration for a quoted string
{
@ -542,11 +542,11 @@ void CEditorCommandManager::GetArgsFromString(const string& argsTxt, CCommand::C
size_t openingQuotePos = argsTxt.find(quoteSymbol, prevPos);
size_t closingQuotePos = argsTxt.find(quoteSymbol, curPos);
if (closingQuotePos != string::npos)
if (closingQuotePos != AZStd::string::npos)
{
arg = argsTxt.substr(openingQuotePos + 1, closingQuotePos - openingQuotePos - 1);
size_t nextArgPos = argsTxt.find(' ', closingQuotePos + 1);
curPos = nextArgPos != string::npos ? nextArgPos + 1 : argsTxt.length();
curPos = nextArgPos != AZStd::string::npos ? nextArgPos + 1 : argsTxt.length();
for (; curPos < argsTxt.length(); ++curPos) // Skip spaces.
{
@ -565,6 +565,5 @@ void CEditorCommandManager::GetArgsFromString(const string& argsTxt, CCommand::C
argList.Add(arg.c_str());
prevPos = curPos;
arg = argsTxt.Tokenize(" ", curPos);
}
}

@ -53,9 +53,9 @@ public:
QString Execute(const AZStd::string& cmdLine);
QString Execute(const AZStd::string& module, const AZStd::string& name, const CCommand::CArgs& args);
void Execute(int commandId);
void GetCommandList(std::vector<string>& cmds) const;
void GetCommandList(std::vector<AZStd::string>& cmds) const;
//! Used in the console dialog
string AutoComplete(const AZStd::string& substr) const;
AZStd::string AutoComplete(const AZStd::string& substr) const;
bool IsRegistered(const char* module, const char* name) const;
bool IsRegistered(const char* cmdLine) const;
bool IsRegistered(int commandId) const;
@ -74,7 +74,7 @@ protected:
};
//! A full command name to an actual command mapping
typedef std::map<string, SCommandTableEntry> CommandTable;
typedef std::map<AZStd::string, SCommandTableEntry> CommandTable;
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
CommandTable m_commands;
@ -86,7 +86,7 @@ protected:
bool m_bWarnDuplicate;
static int GenNewCommandId();
static string GetFullCommandName(const AZStd::string& module, const AZStd::string& name);
static AZStd::string GetFullCommandName(const AZStd::string& module, const AZStd::string& name);
static void GetArgsFromString(const AZStd::string& argsTxt, CCommand::CArgs& argList);
void LogCommand(const AZStd::string& fullCmdName, const CCommand::CArgs& args) const;
QString ExecuteAndLogReturn(CCommand* pCommand, const CCommand::CArgs& args);

@ -127,9 +127,9 @@ namespace Config
case IConfigVar::eType_STRING:
{
string currentValue = 0;
AZStd::string currentValue = 0;
var->Get(&currentValue);
node->setAttr(szName, currentValue);
node->setAttr(szName, currentValue.c_str());
break;
}
}
@ -186,7 +186,7 @@ namespace Config
case IConfigVar::eType_STRING:
{
string currentValue = 0;
AZStd::string currentValue = 0;
var->GetDefault(&currentValue);
QString readValue(currentValue.c_str());
if (node->getAttr(szName, readValue))

@ -76,8 +76,8 @@ namespace Config
protected:
EType m_type;
uint8 m_flags;
string m_name;
string m_description;
AZStd::string m_name;
AZStd::string m_description;
void* m_ptr;
ICVar* m_pCVar;
};

@ -180,7 +180,7 @@ bool ConsoleLineEdit::event(QEvent* ev)
if (newStr.isEmpty())
{
newStr = GetIEditor()->GetCommandManager()->AutoComplete(cstring.toUtf8().data());
newStr = GetIEditor()->GetCommandManager()->AutoComplete(cstring.toUtf8().data()).c_str();
}
}
@ -211,7 +211,7 @@ void ConsoleLineEdit::keyPressEvent(QKeyEvent* ev)
{
if (commandManager->IsRegistered(str.toUtf8().data()))
{
commandManager->Execute(QtUtil::ToString(str));
commandManager->Execute(str.toUtf8().data());
}
else
{

@ -400,7 +400,7 @@ void CFolderTreeCtrl::RemoveEmptyFolderItems(const QString& folder)
void CFolderTreeCtrl::Edit(const QString& path)
{
CFileUtil::EditTextFile(QtUtil::ToString(path), 0, IFileUtil::FILE_TYPE_SCRIPT);
CFileUtil::EditTextFile(path.toUtf8().data(), 0, IFileUtil::FILE_TYPE_SCRIPT);
}
void CFolderTreeCtrl::ShowInExplorer(const QString& path)

@ -132,7 +132,9 @@ void LocalStringPropertyEditor::onEditClicked()
if (pMgr->GetLocalizedInfoByIndex(i, sInfo))
{
item.desc = tr("English Text:\r\n");
item.desc += QString::fromWCharArray(Unicode::Convert<wstring>(sInfo.sUtf8TranslatedText).c_str());
AZStd::wstring utf8TranslatedTextW;
AZStd::to_wstring(utf8TranslatedTextW, sInfo.sUtf8TranslatedText);
item.desc += QString::fromWCharArray(utf8TranslatedTextW.c_str());
item.name = sInfo.sKey;
items.push_back(item);
}

@ -127,7 +127,7 @@ private:
std::vector<int> keySelectionFlags;
_smart_ptr<ISplineBackup> undo;
_smart_ptr<ISplineBackup> redo;
string id;
AZStd::string id;
ISplineInterpolator* pSpline;
};

@ -54,7 +54,7 @@ class ISplineSet
{
public:
virtual ISplineInterpolator* GetSplineFromID(const AZStd::string& id) = 0;
virtual string GetIDFromSpline(ISplineInterpolator* pSpline) = 0;
virtual AZStd::string GetIDFromSpline(ISplineInterpolator* pSpline) = 0;
virtual int GetSplineCount() const = 0;
virtual int GetKeyCountAtTime(float time, float threshold) const = 0;
};

@ -206,7 +206,7 @@ namespace
static void LogToDebug([[maybe_unused]] QtMsgType Type, [[maybe_unused]] const QMessageLogContext& Context, const QString& message)
{
AZ::Debug::Platform::OutputToDebugger("Qt", message.utf8());
AZ::Debug::Platform::OutputToDebugger("Qt", message.toUtf8().data());
AZ::Debug::Platform::OutputToDebugger(nullptr, "\n");
}
}

@ -52,7 +52,7 @@ protected:
}
private:
AZ::AllocatorScope<AZ::OSAllocator, AZ::SystemAllocator, AZ::LegacyAllocator, CryStringAllocator> m_allocatorScope;
AZ::AllocatorScope<AZ::OSAllocator, AZ::SystemAllocator, AZ::LegacyAllocator> m_allocatorScope;
SSystemGlobalEnvironment m_stubEnv;
AZ::IO::LocalFileIO m_fileIO;
NiceMock<CryPakMock>* m_cryPak;

@ -272,8 +272,8 @@ void CCryDocManager::OnFileNew()
m_pDefTemplate->OpenDocumentFile(NULL);
// if returns NULL, the user has already been alerted
}
BOOL CCryDocManager::DoPromptFileName(QString& fileName, [[maybe_unused]] UINT nIDSTitle,
[[maybe_unused]] DWORD lFlags, BOOL bOpenFileDialog, [[maybe_unused]] CDocTemplate* pTemplate)
bool CCryDocManager::DoPromptFileName(QString& fileName, [[maybe_unused]] UINT nIDSTitle,
[[maybe_unused]] DWORD lFlags, bool bOpenFileDialog, [[maybe_unused]] CDocTemplate* pTemplate)
{
CLevelFileDialog levelFileDialog(bOpenFileDialog);
levelFileDialog.show();
@ -287,7 +287,7 @@ BOOL CCryDocManager::DoPromptFileName(QString& fileName, [[maybe_unused]] UINT n
return false;
}
CCryEditDoc* CCryDocManager::OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU)
CCryEditDoc* CCryDocManager::OpenDocumentFile(const char* lpszFileName, bool bAddToMRU)
{
assert(lpszFileName != NULL);
@ -657,7 +657,7 @@ struct SharedData
//
// This function uses a technique similar to that described in KB
// article Q141752 to locate the previous instance of the application. .
BOOL CCryEditApp::FirstInstance(bool bForceNewInstance)
bool CCryEditApp::FirstInstance(bool bForceNewInstance)
{
QSystemSemaphore sem(QString(O3DEApplicationName) + "_sem", 1);
sem.acquire();
@ -805,12 +805,12 @@ void CCryEditApp::InitDirectory()
// Needed to work with custom memory manager.
//////////////////////////////////////////////////////////////////////////
CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible /*= true*/)
CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(const char* lpszPathName, bool bMakeVisible /*= true*/)
{
return OpenDocumentFile(lpszPathName, true, bMakeVisible);
}
CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, [[maybe_unused]] BOOL bMakeVisible)
CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(const char* lpszPathName, bool bAddToMRU, [[maybe_unused]] bool bMakeVisible)
{
CCryEditDoc* pCurDoc = GetIEditor()->GetDocument();
@ -849,7 +849,7 @@ CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL
return pCurDoc;
}
CCrySingleDocTemplate::Confidence CCrySingleDocTemplate::MatchDocType(LPCTSTR lpszPathName, CCryEditDoc*& rpDocMatch)
CCrySingleDocTemplate::Confidence CCrySingleDocTemplate::MatchDocType(const char* lpszPathName, CCryEditDoc*& rpDocMatch)
{
assert(lpszPathName != NULL);
rpDocMatch = NULL;
@ -1059,7 +1059,7 @@ AZ::Outcome<void, AZStd::string> CCryEditApp::InitGameSystem(HWND hwndForInputSy
}
/////////////////////////////////////////////////////////////////////////////
BOOL CCryEditApp::CheckIfAlreadyRunning()
bool CCryEditApp::CheckIfAlreadyRunning()
{
bool bForceNewInstance = false;
@ -1303,7 +1303,7 @@ void CCryEditApp::InitLevel(const CEditCommandLineInfo& cmdInfo)
}
/////////////////////////////////////////////////////////////////////////////
BOOL CCryEditApp::InitConsole()
bool CCryEditApp::InitConsole()
{
// Execute command from cmdline -exec_line if applicable
if (!m_execLineCmd.isEmpty())
@ -1593,7 +1593,7 @@ void CCryEditApp::RunInitPythonScript(CEditCommandLineInfo& cmdInfo)
/////////////////////////////////////////////////////////////////////////////
// CCryEditApp initialization
BOOL CCryEditApp::InitInstance()
bool CCryEditApp::InitInstance()
{
QElapsedTimer startupTimer;
startupTimer.start();
@ -2281,7 +2281,7 @@ void CCryEditApp::EnableIdleProcessing()
AZ_Assert(m_disableIdleProcessingCounter >= 0, "m_disableIdleProcessingCounter must be nonnegative");
}
BOOL CCryEditApp::OnIdle([[maybe_unused]] LONG lCount)
bool CCryEditApp::OnIdle([[maybe_unused]] LONG lCount)
{
if (0 == m_disableIdleProcessingCounter)
{
@ -3226,7 +3226,7 @@ void CCryEditApp::OnCreateLevel()
//////////////////////////////////////////////////////////////////////////
bool CCryEditApp::CreateLevel(bool& wasCreateLevelOperationCancelled)
{
BOOL bIsDocModified = GetIEditor()->GetDocument()->IsModified();
bool bIsDocModified = GetIEditor()->GetDocument()->IsModified();
if (GetIEditor()->GetDocument()->IsDocumentReady() && bIsDocModified)
{
QString str = QObject::tr("Level %1 has been changed. Save Level?").arg(GetIEditor()->GetGameEngine()->GetLevelName());
@ -3280,7 +3280,7 @@ bool CCryEditApp::CreateLevel(bool& wasCreateLevelOperationCancelled)
GetIEditor()->GetDocument()->DeleteTemporaryLevel();
}
if (levelName.length() == 0 || !CryStringUtils::IsValidFileName(levelName.toUtf8().data()))
if (levelName.length() == 0 || !AZ::StringFunc::Path::IsValid(levelName.toUtf8().data()))
{
QMessageBox::critical(AzToolsFramework::GetActiveWindow(), QString(), QObject::tr("Level name is invalid, please choose another name."));
return false;
@ -3313,13 +3313,15 @@ bool CCryEditApp::CreateLevel(bool& wasCreateLevelOperationCancelled)
DWORD dw = GetLastError();
#ifdef WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
wchar_t windowsErrorMessageW[ERROR_LEN] = { 0 };
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
windowsErrorMessage.data(),
windowsErrorMessage.length(), NULL);
windowsErrorMessageW,
ERROR_LEN - 1, NULL);
_getcwd(cwd.data(), cwd.length());
AZStd::to_string(windowsErrorMessage.data(), ERROR_LEN, windowsErrorMessageW);
#else
windowsErrorMessage = strerror(dw);
cwd = QDir::currentPath().toUtf8();
@ -3393,7 +3395,7 @@ void CCryEditApp::OnOpenSlice()
}
//////////////////////////////////////////////////////////////////////////
CCryEditDoc* CCryEditApp::OpenDocumentFile(LPCTSTR lpszFileName)
CCryEditDoc* CCryEditApp::OpenDocumentFile(const char* lpszFileName)
{
if (m_openingLevel)
{
@ -4250,7 +4252,7 @@ extern "C" int AZ_DLL_EXPORT CryEditMain(int argc, char* argv[])
int exitCode = 0;
BOOL didCryEditStart = CCryEditApp::instance()->InitInstance();
bool didCryEditStart = CCryEditApp::instance()->InitInstance();
AZ_Error("Editor", didCryEditStart, "O3DE Editor did not initialize correctly, and will close."
"\nThis could be because of incorrectly configured components, or missing required gems."
"\nSee other errors for more details.");

@ -135,16 +135,16 @@ public:
virtual void AddToRecentFileList(const QString& lpszPathName);
ECreateLevelResult CreateLevel(const QString& levelName, QString& fullyQualifiedLevelName);
static void InitDirectory();
BOOL FirstInstance(bool bForceNewInstance = false);
bool FirstInstance(bool bForceNewInstance = false);
void InitFromCommandLine(CEditCommandLineInfo& cmdInfo);
BOOL CheckIfAlreadyRunning();
bool CheckIfAlreadyRunning();
//! @return successful outcome if initialization succeeded. or failed outcome with error message.
AZ::Outcome<void, AZStd::string> InitGameSystem(HWND hwndForInputSystem);
void CreateSplashScreen();
void InitPlugins();
bool InitGame();
BOOL InitConsole();
bool InitConsole();
int IdleProcessing(bool bBackground);
bool IsWindowInForeground();
void RunInitPythonScript(CEditCommandLineInfo& cmdInfo);
@ -171,10 +171,10 @@ public:
// Overrides
// ClassWizard generated virtual function overrides
public:
virtual BOOL InitInstance();
virtual bool InitInstance();
virtual int ExitInstance(int exitCode = 0);
virtual BOOL OnIdle(LONG lCount);
virtual CCryEditDoc* OpenDocumentFile(LPCTSTR lpszFileName);
virtual bool OnIdle(LONG lCount);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszFileName);
CCryDocManager* GetDocManager() { return m_pDocManager; }
@ -454,9 +454,9 @@ public:
~CCrySingleDocTemplate() {};
// avoid creating another CMainFrame
// close other type docs before opening any things
virtual CCryEditDoc* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOL bMakeVisible);
virtual CCryEditDoc* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE);
virtual Confidence MatchDocType(LPCTSTR lpszPathName, CCryEditDoc*& rpDocMatch);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszPathName, bool bAddToMRU, bool bMakeVisible);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszPathName, bool bMakeVisible = TRUE);
virtual Confidence MatchDocType(const char* lpszPathName, CCryEditDoc*& rpDocMatch);
private:
const QMetaObject* m_documentClass = nullptr;
@ -471,9 +471,9 @@ public:
CCrySingleDocTemplate* SetDefaultTemplate(CCrySingleDocTemplate* pNew);
// Copied from MFC to get rid of the silly ugly unoverridable doc-type pick dialog
virtual void OnFileNew();
virtual BOOL DoPromptFileName(QString& fileName, UINT nIDSTitle,
DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate);
virtual CCryEditDoc* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU);
virtual bool DoPromptFileName(QString& fileName, UINT nIDSTitle,
DWORD lFlags, bool bOpenFileDialog, CDocTemplate* pTemplate);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszFileName, bool bAddToMRU);
QVector<CCrySingleDocTemplate*> m_templateList;
};

@ -426,8 +426,8 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename)
Audio::AudioSystemRequestBus::BroadcastResult(controlsPath, &Audio::AudioSystemRequestBus::Events::GetControlsPath);
QString sAudioLevelPath(controlsPath);
sAudioLevelPath += "levels/";
string const sLevelNameOnly = PathUtil::GetFileName(fileName.toUtf8().data());
sAudioLevelPath += sLevelNameOnly;
AZStd::string const sLevelNameOnly = PathUtil::GetFileName(fileName.toUtf8().data());
sAudioLevelPath += sLevelNameOnly.c_str();
QByteArray path = sAudioLevelPath.toUtf8();
Audio::SAudioManagerRequestData<Audio::eAMRT_PARSE_CONTROLS_DATA> oAMData(path, Audio::eADS_LEVEL_SPECIFIC);
Audio::SAudioRequest oAudioRequestData;
@ -1919,7 +1919,7 @@ void CCryEditDoc::LogLoadTime(int time)
CLogFile::FormatLine("[LevelLoadTime] Level %s loaded in %d seconds", level.toUtf8().data(), time / 1000);
#if defined(AZ_PLATFORM_WINDOWS)
SetFileAttributes(filename.toUtf8().data(), FILE_ATTRIBUTE_ARCHIVE);
SetFileAttributesW(filename.toStdWString().c_str(), FILE_ATTRIBUTE_ARCHIVE);
#endif
FILE* file = nullptr;
@ -2152,7 +2152,7 @@ void CCryEditDoc::OnEnvironmentPropertyChanged(IVariable* pVar)
}
}
QString CCryEditDoc::GetCryIndexPath(const LPCTSTR levelFilePath)
QString CCryEditDoc::GetCryIndexPath(const char* levelFilePath)
{
QString levelPath = Path::GetPath(levelFilePath);
QString levelName = Path::GetFileName(levelFilePath);

@ -180,7 +180,7 @@ protected:
void OnStartLevelResourceList();
static void OnValidateSurfaceTypesChanged(ICVar*);
QString GetCryIndexPath(const LPCTSTR levelFilePath);
QString GetCryIndexPath(const char* levelFilePath);
//////////////////////////////////////////////////////////////////////////
// SliceEditorEntityOwnershipServiceNotificationBus::Handler

@ -210,7 +210,7 @@ namespace
const char* PyGetCurrentLevelName()
{
// Using static member to capture temporary data
static string tempLevelName;
static AZStd::string tempLevelName;
tempLevelName = GetIEditor()->GetGameEngine()->GetLevelName().toUtf8().data();
return tempLevelName.c_str();
}
@ -218,7 +218,7 @@ namespace
const char* PyGetCurrentLevelPath()
{
// Using static member to capture temporary data
static string tempLevelPath;
static AZStd::string tempLevelPath;
tempLevelPath = GetIEditor()->GetGameEngine()->GetLevelPath().toUtf8().data();
return tempLevelPath.c_str();
}

@ -55,10 +55,10 @@ bool CEditorFileMonitor::RegisterListener(IFileChangeListener* pListener, const
//////////////////////////////////////////////////////////////////////////
static string CanonicalizePath(const char* path)
static AZStd::string CanonicalizePath(const char* path)
{
auto canon = QFileInfo(path).canonicalFilePath();
return canon.isEmpty() ? string(path) : string(canon.toUtf8());
return canon.isEmpty() ? AZStd::string(path) : AZStd::string(canon.toUtf8());
}
//////////////////////////////////////////////////////////////////////////
@ -66,8 +66,8 @@ bool CEditorFileMonitor::RegisterListener(IFileChangeListener* pListener, const
{
bool success = true;
string gameFolder = Path::GetEditingGameDataFolder().c_str();
string naivePath;
AZStd::string gameFolder = Path::GetEditingGameDataFolder().c_str();
AZStd::string naivePath;
CFileChangeMonitor* fileChangeMonitor = CFileChangeMonitor::Instance();
AZ_Assert(fileChangeMonitor, "CFileChangeMonitor singleton missing.");
@ -75,12 +75,12 @@ bool CEditorFileMonitor::RegisterListener(IFileChangeListener* pListener, const
// Append slash in preparation for appending the second part.
naivePath = PathUtil::AddSlash(naivePath);
naivePath += sFolderRelativeToGame;
naivePath.replace('/', '\\');
AZ::StringFunc::Replace(naivePath, '/', '\\');
// Remove the final slash if the given item is a folder so the file change monitor correctly picks up on it.
naivePath = PathUtil::RemoveSlash(naivePath);
string canonicalizedPath = CanonicalizePath(naivePath.c_str());
AZStd::string canonicalizedPath = CanonicalizePath(naivePath.c_str());
if (fileChangeMonitor->IsDirectory(canonicalizedPath.c_str()) || fileChangeMonitor->IsFile(canonicalizedPath.c_str()))
{

@ -378,11 +378,11 @@ void CGameExporter::ExportFileList(const QString& path, const QString& levelName
{
// process the folder of the specified map name, producing a filelist.xml file
// that can later be used for map downloads
string newpath;
AZStd::string newpath;
QString filename = levelName;
string mapname = (filename + ".dds").toUtf8().data();
string metaname = (filename + ".xml").toUtf8().data();
AZStd::string mapname = (filename + ".dds").toUtf8().data();
AZStd::string metaname = (filename + ".xml").toUtf8().data();
XmlNodeRef rootNode = gEnv->pSystem->CreateXmlNode("download");
rootNode->setAttr("name", filename.toUtf8().data());
@ -434,9 +434,9 @@ void CGameExporter::ExportFileList(const QString& path, const QString& levelName
newFileNode->setAttr("size", handle.m_fileDesc.nSize);
unsigned char md5[16];
string filenameToHash = GetIEditor()->GetGameEngine()->GetLevelPath().toUtf8().data();
AZStd::string filenameToHash = GetIEditor()->GetGameEngine()->GetLevelPath().toUtf8().data();
filenameToHash += "/";
filenameToHash += string{ handle.m_filename.data(), handle.m_filename.size() };
filenameToHash += AZStd::string{ handle.m_filename.data(), handle.m_filename.size() };
if (gEnv->pCryPak->ComputeMD5(filenameToHash.data(), md5))
{
char md5string[33];

@ -26,6 +26,7 @@ AZ_POP_DISABLE_WARNING
#include <AzCore/IO/Path/Path.h>
#include <AzCore/JSON/document.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/Utils/Utils.h>
// AzFramework
#include <AzFramework/Terrain/TerrainDataRequestBus.h>
@ -1107,16 +1108,18 @@ void CEditorImpl::DetectVersion()
DWORD dwHandle;
UINT len;
char ver[1024 * 8];
wchar_t ver[1024 * 8];
AZ::Utils::GetExecutablePath(exe, _MAX_PATH);
AZStd::wstring exeW;
AZStd::to_wstring(exeW, exe);
int verSize = GetFileVersionInfoSize(exe, &dwHandle);
int verSize = GetFileVersionInfoSizeW(exeW.c_str(), &dwHandle);
if (verSize > 0)
{
GetFileVersionInfo(exe, dwHandle, 1024 * 8, ver);
GetFileVersionInfoW(exeW.c_str(), dwHandle, 1024 * 8, ver);
VS_FIXEDFILEINFO* vinfo;
VerQueryValue(ver, "\\", (void**)&vinfo, &len);
VerQueryValueW(ver, L"\\", (void**)&vinfo, &len);
m_fileVersion.v[0] = vinfo->dwFileVersionLS & 0xFFFF;
m_fileVersion.v[1] = vinfo->dwFileVersionLS >> 16;
@ -1557,31 +1560,31 @@ IExportManager* CEditorImpl::GetExportManager()
void CEditorImpl::AddUIEnums()
{
// Spec settings for shadow casting lights
string SpecString[4];
AZStd::string SpecString[4];
QStringList types;
types.push_back("Never=0");
SpecString[0].Format("VeryHigh Spec=%d", CONFIG_VERYHIGH_SPEC);
SpecString[0] = AZStd::string::format("VeryHigh Spec=%d", CONFIG_VERYHIGH_SPEC);
types.push_back(SpecString[0].c_str());
SpecString[1].Format("High Spec=%d", CONFIG_HIGH_SPEC);
SpecString[1] = AZStd::string::format("High Spec=%d", CONFIG_HIGH_SPEC);
types.push_back(SpecString[1].c_str());
SpecString[2].Format("Medium Spec=%d", CONFIG_MEDIUM_SPEC);
SpecString[2] = AZStd::string::format("Medium Spec=%d", CONFIG_MEDIUM_SPEC);
types.push_back(SpecString[2].c_str());
SpecString[3].Format("Low Spec=%d", CONFIG_LOW_SPEC);
SpecString[3] = AZStd::string::format("Low Spec=%d", CONFIG_LOW_SPEC);
types.push_back(SpecString[3].c_str());
m_pUIEnumsDatabase->SetEnumStrings("CastShadows", types);
// Power-of-two percentages
string percentStringPOT[5];
AZStd::string percentStringPOT[5];
types.clear();
percentStringPOT[0].Format("Default=%d", 0);
percentStringPOT[0] = AZStd::string::format("Default=%d", 0);
types.push_back(percentStringPOT[0].c_str());
percentStringPOT[1].Format("12.5=%d", 1);
percentStringPOT[1] = AZStd::string::format("12.5=%d", 1);
types.push_back(percentStringPOT[1].c_str());
percentStringPOT[2].Format("25=%d", 2);
percentStringPOT[2] = AZStd::string::format("25=%d", 2);
types.push_back(percentStringPOT[2].c_str());
percentStringPOT[3].Format("50=%d", 3);
percentStringPOT[3] = AZStd::string::format("50=%d", 3);
types.push_back(percentStringPOT[3].c_str());
percentStringPOT[4].Format("100=%d", 4);
percentStringPOT[4] = AZStd::string::format("100=%d", 4);
types.push_back(percentStringPOT[4].c_str());
m_pUIEnumsDatabase->SetEnumStrings("ShadowMinResPercent", types);
}

@ -18,7 +18,7 @@
#include "Util/EditorUtils.h"
inline string ToString(const QString& s)
inline AZStd::string ToString(const QString& s)
{
return s.toUtf8().data();
}
@ -85,7 +85,7 @@ public:
return m_args[i];
}
private:
DynArray<string> m_args;
DynArray<AZStd::string> m_args;
unsigned char m_stringFlags; // This is needed to quote string parameters when logging a command.
};
@ -104,15 +104,15 @@ public:
protected:
friend class CEditorCommandManager;
string m_module;
string m_name;
string m_description;
string m_example;
AZStd::string m_module;
AZStd::string m_name;
AZStd::string m_description;
AZStd::string m_example;
bool m_bAlsoAvailableInScripting;
template <typename T>
static string ToString_(T t) { return ::ToString(t); }
static inline string ToString_(const char* val)
static AZStd::string ToString_(T t) { return ::ToString(t); }
static inline AZStd::string ToString_(const char* val)
{ return val; }
template <typename T>
static bool FromString_(T& t, const char* s) { return ::FromString(t, s); }
@ -146,10 +146,10 @@ public:
// UI metadata for this command, if any
struct SUIInfo
{
string caption;
string tooltip;
string description;
string iconFilename;
AZStd::string caption;
AZStd::string tooltip;
AZStd::string description;
AZStd::string iconFilename;
int iconIndex;
int commandId; // Windows command id

@ -98,7 +98,7 @@ CLevelFileDialog::CLevelFileDialog(bool openDialog, QWidget* parent)
connect(ui->nameLineEdit, &QLineEdit::textChanged, this, &CLevelFileDialog::OnNameChanged);
}
// reject invalid file names (see CryStringUtils::IsValidFileName)
// reject invalid file names
ui->nameLineEdit->setValidator(new QRegExpValidator(QRegExp("^[a-zA-Z0-9_\\-./]*$"), ui->nameLineEdit));
ReloadTree();
@ -315,7 +315,7 @@ void CLevelFileDialog::OnNewFolder()
const QString newFolderName = inputDlg.textValue();
const QString newFolderPath = parentFullPath + "/" + newFolderName;
if (!CryStringUtils::IsValidFileName(newFolderName.toUtf8().data()))
if (!AZ::StringFunc::Path::IsValid(newFolderName.toUtf8().data()))
{
QMessageBox box(this);
box.setText(tr("Please enter a single, valid folder name(standard English alphanumeric characters only)"));
@ -416,7 +416,7 @@ bool CLevelFileDialog::ValidateSaveLevelPath(QString& errorMessage) const
const QString enteredPath = GetEnteredPath();
const QString levelPath = GetLevelPath();
if (!CryStringUtils::IsValidFileName(Path::GetFileName(levelPath).toUtf8().data()))
if (!AZ::StringFunc::Path::IsValid(Path::GetFileName(levelPath).toUtf8().data()))
{
errorMessage = tr("Please enter a valid level name (standard English alphanumeric characters only)");
return false;

@ -180,14 +180,14 @@ void CLogFile::FormatLineV(const char * format, va_list argList)
void CLogFile::AboutSystem()
{
char szBuffer[MAX_LOGBUFFER_SIZE];
wchar_t szBufferW[MAX_LOGBUFFER_SIZE];
#if defined(AZ_PLATFORM_WINDOWS) || defined(AZ_PLATFORM_LINUX)
//////////////////////////////////////////////////////////////////////
// Write the system informations to the log
//////////////////////////////////////////////////////////////////////
char szProfileBuffer[128];
char szLanguageBuffer[64];
//char szCPUModel[64];
wchar_t szLanguageBufferW[64];
//wchar_t szCPUModel[64];
MEMORYSTATUS MemoryStatus;
#endif // defined(AZ_PLATFORM_WINDOWS) || defined(AZ_PLATFORM_LINUX)
@ -201,11 +201,13 @@ void CLogFile::AboutSystem()
//////////////////////////////////////////////////////////////////////
// Get system language
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE,
szLanguageBuffer, sizeof(szLanguageBuffer));
GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE,
szLanguageBufferW, sizeof(szLanguageBufferW));
AZStd::string szLanguageBuffer;
AZStd::to_string(szLanguageBuffer, szLanguageBufferW);
// Format and send OS information line
azsnprintf(szBuffer, MAX_LOGBUFFER_SIZE, "Current Language: %s ", szLanguageBuffer);
azsnprintf(szBuffer, MAX_LOGBUFFER_SIZE, "Current Language: %s ", szLanguageBuffer.c_str());
CryLog("%s", szBuffer);
#else
QLocale locale;
@ -294,7 +296,8 @@ AZ_POP_DISABLE_WARNING
//////////////////////////////////////////////////////////////////////
str += " (";
GetWindowsDirectory(szBuffer, sizeof(szBuffer));
GetWindowsDirectoryW(szBufferW, sizeof(szBufferW));
AZStd::to_string(szBuffer, MAX_LOGBUFFER_SIZE, szBufferW);
str += szBuffer;
str += ")";
CryLog("%s", str.toUtf8().data());
@ -381,12 +384,13 @@ AZ_POP_DISABLE_WARNING
#if defined(AZ_PLATFORM_WINDOWS)
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DisplayConfig);
GetPrivateProfileString("boot.description", "display.drv",
"(Unknown graphics card)", szProfileBuffer, sizeof(szProfileBuffer),
"system.ini");
GetPrivateProfileStringW(L"boot.description", L"display.drv",
L"(Unknown graphics card)", szLanguageBufferW, sizeof(szLanguageBufferW),
L"system.ini");
AZStd::to_string(szLanguageBuffer, szLanguageBufferW);
azsnprintf(szBuffer, MAX_LOGBUFFER_SIZE, "Current display mode is %dx%dx%d, %s",
DisplayConfig.dmPelsWidth, DisplayConfig.dmPelsHeight,
DisplayConfig.dmBitsPerPel, szProfileBuffer);
DisplayConfig.dmBitsPerPel, szLanguageBuffer.c_str());
CryLog("%s", szBuffer);
#else
auto screen = QGuiApplication::primaryScreen();

@ -1634,7 +1634,7 @@ void MainWindow::OnUpdateConnectionStatus()
status = tr("Pending Jobs : %1 Failed Jobs : %2").arg(m_connectionListener->GetJobsCount()).arg(failureCount);
statusBar->SetItem(QtUtil::ToQString("connection"), status, tooltip, icon);
statusBar->SetItem("connection", status, tooltip, icon);
if (m_showAPDisconnectDialog && m_connectionListener->GetState() != EConnectionState::Connected)
{

@ -60,11 +60,11 @@ bool CMailer::SendMail(const char* subject,
// Handle Recipients
MapiRecipDesc* recipients = new MapiRecipDesc[numRecipients];
std::vector<string> addresses;
std::vector<AZStd::string> addresses;
addresses.resize(numRecipients);
for (i = 0; i < numRecipients; i++)
{
addresses[i] = string("SMTP:") + _recipients[i];
addresses[i] = AZStd::string("SMTP:") + _recipients[i];
}
for (i = 0; i < numRecipients; i++)

@ -126,8 +126,8 @@ namespace
bool CPluginManager::LoadPlugins(const char* pPathWithMask)
{
QString strPath = QtUtil::ToQString(PathUtil::GetPath(pPathWithMask));
QString strMask = QString::fromUtf8(PathUtil::GetFile(pPathWithMask));
QString strPath = PathUtil::GetPath(pPathWithMask).c_str();
QString strMask = PathUtil::GetFile(pPathWithMask);
CLogFile::WriteLine("[Plugin Manager] Loading plugins...");

@ -88,7 +88,7 @@ private:
IEditor* const m_editor;
// Tool name
string m_toolName;
AZStd::string m_toolName;
// Context provider for the Asset Browser
AZ::AssetBrowserContextProvider m_assetBrowserContextProvider;

@ -101,10 +101,10 @@ public:
}
private:
typedef std::map<string, const SStaticResourceSelectorEntry*, stl::less_stricmp<string> > TTypeMap;
typedef std::map<AZStd::string, const SStaticResourceSelectorEntry*, stl::less_stricmp<AZStd::string> > TTypeMap;
TTypeMap m_typeMap;
std::map<string, string> m_globallySelectedResources;
std::map<AZStd::string, AZStd::string> m_globallySelectedResources;
};
// ---------------------------------------------------------------------------

@ -37,7 +37,7 @@ CSelectSequenceDialog::GetItems(std::vector<SItem>& outItems)
{
IAnimSequence* pSeq = pMovieSys->GetSequence(i);
SItem item;
string fullname = pSeq->GetName();
AZStd::string fullname = pSeq->GetName();
item.name = fullname.c_str();
outItems.push_back(item);
}

@ -350,7 +350,7 @@ void CToolBoxManager::LoadShelves(QString scriptPath, QString shelvesPath, Actio
continue;
}
QString shelfName(PathUtil::GetFileName(files[idx].filename.toUtf8().data()));
QString shelfName(PathUtil::GetFileName(files[idx].filename.toUtf8().data()).c_str());
AmazonToolbar toolbar(shelfName, shelfName);
Load(shelvesPath + QString("/") + files[idx].filename, &toolbar, false, actionManager);
@ -408,7 +408,7 @@ void CToolBoxManager::Load(QString xmlpath, AmazonToolbar* pToolbar, bool bToolb
AZ::IO::FixedMaxPathString engineRoot = AZ::Utils::GetEnginePath();
QDir engineDir = !engineRoot.empty() ? QDir(QString(engineRoot.c_str())) : QDir::current();
string enginePath = PathUtil::AddSlash(engineDir.absolutePath().toUtf8().data());
AZStd::string enginePath = PathUtil::AddSlash(engineDir.absolutePath().toUtf8().data());
for (int i = 0; i < toolBoxNode->getChildCount(); ++i)
{
@ -434,11 +434,11 @@ void CToolBoxManager::Load(QString xmlpath, AmazonToolbar* pToolbar, bool bToolb
continue;
}
string shelfPath = PathUtil::GetParentDirectory(xmlpath.toUtf8().data());
string fullIconPath = enginePath + PathUtil::AddSlash(shelfPath.c_str());
AZStd::string shelfPath = PathUtil::GetParentDirectory(xmlpath.toUtf8().data());
AZStd::string fullIconPath = enginePath + PathUtil::AddSlash(shelfPath.c_str());
fullIconPath.append(iconPath.toUtf8().data());
pMacro->SetIconPath(fullIconPath);
pMacro->SetIconPath(fullIconPath.c_str());
QString toolTip(macroNode->getAttr("tooltip"));
pMacro->action()->setToolTip(toolTip);

@ -52,7 +52,7 @@ public:
CFileUtil::ScanDirectory((Path::GetEditingGameDataFolder() + "/Fonts/").c_str(), "*.xml", fa, true);
for (size_t i = 0; i < fa.size(); ++i)
{
string name = fa[i].filename.toUtf8().data();
AZStd::string name = fa[i].filename.toUtf8().data();
PathUtil::RemoveExtension(name);
mv_font->AddEnumItem(name.c_str(), name.c_str());
}

@ -91,7 +91,7 @@ bool CSequenceKeyUIControls::OnKeySelectionChange(CTrackViewKeyBundle& selectedK
bool bNotParent = !bNotMe || pCurrentSequence->IsAncestorOf(pSequence) == false;
if (bNotMe && bNotParent)
{
string seqName = pCurrentSequence->GetName();
AZStd::string seqName = pCurrentSequence->GetName();
QString ownerIdString = CTrackViewDialog::GetEntityIdAsString(pCurrentSequence->GetSequenceComponentEntityId());
mv_sequence->AddEnumItem(seqName.c_str(), ownerIdString);

@ -1010,13 +1010,13 @@ bool CTrackViewAnimNode::SetName(const char* pName)
}
}
string oldName = GetName();
AZStd::string oldName = GetName();
m_animNode->SetName(pName);
CTrackViewSequence* sequence = GetSequence();
AZ_Assert(sequence, "Nodes should never have a null sequence.");
sequence->OnNodeRenamed(this, oldName);
sequence->OnNodeRenamed(this, oldName.c_str());
return true;
}

@ -61,7 +61,7 @@ void CTrackViewFindDlg::FillData()
ObjName obj;
obj.m_objName = pNode->GetName();
obj.m_directorName = pNode->HasDirectorAsParent() ? pNode->HasDirectorAsParent()->GetName() : "";
string fullname = seq->GetName();
AZStd::string fullname = seq->GetName();
obj.m_seqName = fullname.c_str();
m_objs.push_back(obj);
}

@ -2516,7 +2516,7 @@ int CTrackViewNodesCtrl::GetMatNameAndSubMtlIndexFromName(QString& matName, cons
if (const char* pCh = strstr(nodeName, ".["))
{
char matPath[MAX_PATH];
azstrcpy(matPath, nodeName, (size_t)(pCh - nodeName));
azstrncpy(matPath, nodeName, (size_t)(pCh - nodeName));
matName = matPath;
pCh += 2;
if ((*pCh) != 0)

@ -1073,7 +1073,7 @@ std::deque<CTrackViewTrack*> CTrackViewSequence::GetMatchingTracks(CTrackViewAni
{
std::deque<CTrackViewTrack*> matchingTracks;
const string trackName = trackNode->getAttr("name");
const AZStd::string trackName = trackNode->getAttr("name");
CAnimParamType animParamType;
animParamType.LoadFromXml(trackNode);
@ -1133,11 +1133,11 @@ void CTrackViewSequence::GetMatchedPasteLocationsRec(std::vector<TMatchedTrackLo
for (unsigned int nodeIndex = 0; nodeIndex < numChildNodes; ++nodeIndex)
{
XmlNodeRef xmlChildNode = clipboardNode->getChild(nodeIndex);
const string tagName = xmlChildNode->getTag();
const AZStd::string tagName = xmlChildNode->getTag();
if (tagName == "Node")
{
const string nodeName = xmlChildNode->getAttr("name");
const AZStd::string nodeName = xmlChildNode->getAttr("name");
int nodeType = static_cast<int>(AnimNodeType::Invalid);
xmlChildNode->getAttr("type", nodeType);
@ -1159,7 +1159,7 @@ void CTrackViewSequence::GetMatchedPasteLocationsRec(std::vector<TMatchedTrackLo
}
else if (tagName == "Track")
{
const string trackName = xmlChildNode->getAttr("name");
const AZStd::string trackName = xmlChildNode->getAttr("name");
CAnimParamType trackParamType;
trackParamType.Serialize(xmlChildNode, true);

@ -81,7 +81,7 @@ void CTVNewSequenceDialog::OnOK()
for (int k = 0; k < GetIEditor()->GetSequenceManager()->GetCount(); ++k)
{
CTrackViewSequence* pSequence = GetIEditor()->GetSequenceManager()->GetSequenceByIndex(k);
QString fullname = QtUtil::ToQString(pSequence->GetName());
QString fullname = pSequence->GetName();
if (fullname.compare(m_sequenceName, Qt::CaseInsensitive) == 0)
{

@ -45,7 +45,7 @@ int CAutoDirectoryRestoreFileDialog::exec()
foreach(const QString&fileName, selectedFiles())
{
QFileInfo info(fileName);
if (!CryStringUtils::IsValidFileName(info.fileName().toStdString().c_str()))
if (!AZ::StringFunc::Path::IsValid(info.fileName().toStdString().c_str()))
{
QMessageBox::warning(this, tr("Error"), tr("Please select a valid file name (standard English alphanumeric characters only)"));
problem = true;

@ -264,7 +264,7 @@ void CFileUtil::EditTextureFile(const char* textureFile, [[maybe_unused]] bool b
}
bool failedToLaunch = true;
QByteArray textureEditorPath = gSettings.textureEditor.toUtf8();
const QString& textureEditorPath = gSettings.textureEditor;
// Give the user a warning if they don't have a texture editor configured
if (textureEditorPath.isEmpty())
@ -278,8 +278,7 @@ void CFileUtil::EditTextureFile(const char* textureFile, [[maybe_unused]] bool b
// Use the Win32 API calls to open the right editor; the OS knows how to do this even better than
// Qt does.
QString fullTexturePathFixedForWindows = QString(fullTexturePath.data()).replace('/', '\\');
QByteArray fullTexturePathFixedForWindowsUtf8 = fullTexturePathFixedForWindows.toUtf8();
HINSTANCE hInst = ShellExecute(NULL, "open", textureEditorPath.data(), fullTexturePathFixedForWindowsUtf8.data(), NULL, SW_SHOWNORMAL);
HINSTANCE hInst = ShellExecuteW(NULL, L"open", textureEditorPath.toStdWString().c_str(), fullTexturePathFixedForWindows.toStdWString().c_str(), NULL, SW_SHOWNORMAL);
failedToLaunch = ((DWORD_PTR)hInst <= 32);
#elif defined(AZ_PLATFORM_MAC)
failedToLaunch = QProcess::execute(QString("/usr/bin/open"), {"-a", gSettings.textureEditor, QString(fullTexturePath.data()) }) != 0;
@ -298,7 +297,7 @@ void CFileUtil::EditTextureFile(const char* textureFile, [[maybe_unused]] bool b
//////////////////////////////////////////////////////////////////////////
bool CFileUtil::EditMayaFile(const char* filepath, const bool bExtractFromPak, const bool bUseGameFolder)
{
QString dosFilepath = QtUtil::ToQString(PathUtil::ToDosPath(filepath));
QString dosFilepath = PathUtil::ToDosPath(filepath).c_str();
if (bExtractFromPak)
{
ExtractFile(dosFilepath);
@ -313,7 +312,7 @@ bool CFileUtil::EditMayaFile(const char* filepath, const bool bExtractFromPak, c
dosFilepath = sGameFolder + '\\' + filepath;
}
dosFilepath = PathUtil::ToDosPath(dosFilepath.toUtf8().data());
dosFilepath = PathUtil::ToDosPath(dosFilepath.toUtf8().data()).c_str();
}
const char* engineRoot;
@ -1304,7 +1303,7 @@ IFileUtil::ECopyTreeResult CFileUtil::CopyTree(const QString& strSourceDirectory
// all with the same names and all with the same files names inside. If you would make a depth-first search
// you could end up with the files from the deepest folder in ALL your folders.
std::vector<string> ignoredPatterns;
std::vector<AZStd::string> ignoredPatterns;
StringHelpers::Split(ignoreFilesAndFolders, "|", false, ignoredPatterns);
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
@ -2218,7 +2217,9 @@ uint32 CFileUtil::GetAttributes(const char* filename, bool bUseSourceControl /*=
return SCC_FILE_ATTRIBUTE_READONLY | SCC_FILE_ATTRIBUTE_INPAK;
}
DWORD dwAttrib = ::GetFileAttributes(file.GetAdjustedFilename());
AZStd::wstring fileW;
AZStd::to_wstring(fileW, file.GetAdjustedFilename());
DWORD dwAttrib = ::GetFileAttributesW(fileW.c_str());
if (dwAttrib == INVALID_FILE_ATTRIBUTES)
{
return SCC_FILE_ATTRIBUTE_INVALID;

@ -24,8 +24,7 @@ bool CImageASC::Save(const QString& fileName, const CFloatImage& image)
uint32 height = image.GetHeight();
float* pixels = image.GetData();
string fileHeader;
fileHeader.Format(
AZStd::string fileHeader = AZStd::string::format(
// Number of columns and rows in the data
"ncols %d\n"
"nrows %d\n"

@ -399,8 +399,8 @@ bool CImageTIF::SaveRAW(const QString& fileName, const void* pData, int width, i
if (preset && preset[0])
{
string tiffphotoshopdata, valueheader;
string presetkeyvalue = string("/preset=") + string(preset);
AZStd::string tiffphotoshopdata, valueheader;
AZStd::string presetkeyvalue = AZStd::string("/preset=") + AZStd::string(preset);
valueheader.push_back('\x1C');
valueheader.push_back('\x02');
@ -472,7 +472,7 @@ const char* CImageTIF::GetPreset(const QString& fileName)
libtiffDummyWriteProc, libtiffDummySeekProc,
libtiffDummyCloseProc, libtiffDummySizeProc, libtiffDummyMapFileProc, libtiffDummyUnmapFileProc);
string strReturn;
AZStd::string strReturn;
char* preset = NULL;
int size;
if (tif)

@ -86,8 +86,7 @@ bool CImageUtil::SavePGM(const QString& fileName, const CImageEx& image)
uint32* pixels = image.GetData();
// Create the file header.
string fileHeader;
fileHeader.Format(
AZStd::string fileHeader = AZStd::string::format(
// P2 = PGM header for ASCII output. (P5 is PGM header for binary output)
"P2\n"
// width and height of the image

@ -7,117 +7,10 @@
*/
#include <platform.h>
#include "StringHelpers.h"
#include "Util.h"
#include "StringUtils.h" // From CryCommon
#include "UnicodeFunctions.h"
#include <cctype>
#include <algorithm>
#include <AzCore/PlatformIncl.h> // WideCharToMultibyte(), CP_UTF8, etc.
#include <AzCore/Casting/numeric_cast.h>
static inline char ToLower(const char c)
{
return tolower(c);
}
static inline wchar_t ToLower(const wchar_t c)
{
return towlower(c);
}
static inline char ToUpper(const char c)
{
return toupper(c);
}
static inline wchar_t ToUpper(const wchar_t c)
{
return towupper(c);
}
static inline int Vscprintf(const char* format, va_list argList)
{
#if defined(AZ_PLATFORM_WINDOWS)
return _vscprintf(format, argList);
#elif AZ_TRAIT_OS_PLATFORM_APPLE || defined(AZ_PLATFORM_LINUX)
int retval;
va_list argcopy;
va_copy(argcopy, argList);
retval = azvsnprintf(NULL, 0, format, argcopy);
va_end(argcopy);
return retval;
#else
#error Not supported!
#endif
}
static inline int Vscprintf(const wchar_t* format, va_list argList)
{
#if defined(AZ_PLATFORM_WINDOWS)
return _vscwprintf(format, argList);
#elif AZ_TRAIT_OS_PLATFORM_APPLE || defined(AZ_PLATFORM_LINUX)
int retval;
va_list argcopy;
va_copy(argcopy, argList);
retval = azvsnwprintf(NULL, 0, format, argcopy);
va_end(argcopy);
return retval;
#else
#error Not supported!
#endif
}
static inline int Vsnprintf_s(char* str, size_t sizeInBytes, [[maybe_unused]] size_t count, const char* format, va_list argList)
{
return azvsnprintf(str, sizeInBytes, format, argList);
}
static inline int Vsnprintf_s(wchar_t* str, size_t sizeInBytes, [[maybe_unused]] size_t count, const wchar_t* format, va_list argList)
{
return azvsnwprintf(str, sizeInBytes, format, argList);
}
int StringHelpers::Compare(const AZStd::string& str0, const AZStd::string& str1)
{
const size_t minLength = Util::getMin(str0.length(), str1.length());
const int result = std::memcmp(str0.c_str(), str1.c_str(), minLength);
if (result)
{
return result;
}
else
{
return (str0.length() == str1.length())
? 0
: ((str0.length() < str1.length()) ? -1 : +1);
}
}
int StringHelpers::Compare(const wstring& str0, const wstring& str1)
{
const size_t minLength = Util::getMin(str0.length(), str1.length());
for (size_t i = 0; i < minLength; ++i)
{
const wchar_t c0 = str0[i];
const wchar_t c1 = str1[i];
if (c0 != c1)
{
return (c0 < c1) ? -1 : 1;
}
}
return (str0.length() == str1.length())
? 0
: ((str0.length() < str1.length()) ? -1 : +1);
}
#include <AzCore/std/string/string.h>
int StringHelpers::CompareIgnoreCase(const AZStd::string& str0, const AZStd::string& str1)
{
@ -135,7 +28,7 @@ int StringHelpers::CompareIgnoreCase(const AZStd::string& str0, const AZStd::str
}
}
int StringHelpers::CompareIgnoreCase(const wstring& str0, const wstring& str1)
int StringHelpers::CompareIgnoreCase(const AZStd::wstring& str0, const AZStd::wstring& str1)
{
const size_t minLength = Util::getMin(str0.length(), str1.length());
for (size_t i = 0; i < minLength; ++i)
@ -153,402 +46,6 @@ int StringHelpers::CompareIgnoreCase(const wstring& str0, const wstring& str1)
: ((str0.length() < str1.length()) ? -1 : +1);
}
bool StringHelpers::Equals(const AZStd::string& str0, const AZStd::string& str1)
{
if (str0.length() != str1.length())
{
return false;
}
return std::memcmp(str0.c_str(), str1.c_str(), str1.length()) == 0;
}
bool StringHelpers::Equals(const wstring& str0, const wstring& str1)
{
if (str0.length() != str1.length())
{
return false;
}
return std::memcmp(str0.c_str(), str1.c_str(), str1.length() * sizeof(wstring::value_type)) == 0;
}
bool StringHelpers::EqualsIgnoreCase(const AZStd::string& str0, const AZStd::string& str1)
{
if (str0.length() != str1.length())
{
return false;
}
return azmemicmp(str0.c_str(), str1.c_str(), str1.length()) == 0;
}
bool StringHelpers::EqualsIgnoreCase(const wstring& str0, const wstring& str1)
{
const size_t str1Length = str1.length();
if (str0.length() != str1Length)
{
return false;
}
for (size_t i = 0; i < str1Length; ++i)
{
if (towlower(str0[i]) != towlower(str1[i]))
{
return false;
}
}
return true;
}
bool StringHelpers::StartsWith(const AZStd::string& str, const AZStd::string& pattern)
{
if (str.length() < pattern.length())
{
return false;
}
return std::memcmp(str.c_str(), pattern.c_str(), pattern.length()) == 0;
}
bool StringHelpers::StartsWith(const wstring& str, const wstring& pattern)
{
if (str.length() < pattern.length())
{
return false;
}
return std::memcmp(str.c_str(), pattern.c_str(), pattern.length() * sizeof(wstring::value_type)) == 0;
}
bool StringHelpers::StartsWithIgnoreCase(const AZStd::string& str, const AZStd::string& pattern)
{
if (str.length() < pattern.length())
{
return false;
}
return azmemicmp(str.c_str(), pattern.c_str(), pattern.length()) == 0;
}
bool StringHelpers::StartsWithIgnoreCase(const wstring& str, const wstring& pattern)
{
const size_t patternLength = pattern.length();
if (str.length() < patternLength)
{
return false;
}
for (size_t i = 0; i < patternLength; ++i)
{
if (towlower(str[i]) != towlower(pattern[i]))
{
return false;
}
}
return true;
}
bool StringHelpers::EndsWith(const AZStd::string& str, const AZStd::string& pattern)
{
if (str.length() < pattern.length())
{
return false;
}
return std::memcmp(str.c_str() + str.length() - pattern.length(), pattern.c_str(), pattern.length()) == 0;
}
bool StringHelpers::EndsWith(const wstring& str, const wstring& pattern)
{
if (str.length() < pattern.length())
{
return false;
}
return std::memcmp(str.c_str() + str.length() - pattern.length(), pattern.c_str(), pattern.length() * sizeof(wstring::value_type)) == 0;
}
bool StringHelpers::EndsWithIgnoreCase(const AZStd::string& str, const AZStd::string& pattern)
{
if (str.length() < pattern.length())
{
return false;
}
return azmemicmp(str.c_str() + str.length() - pattern.length(), pattern.c_str(), pattern.length()) == 0;
}
bool StringHelpers::EndsWithIgnoreCase(const wstring& str, const wstring& pattern)
{
const size_t patternLength = pattern.length();
if (str.length() < patternLength)
{
return false;
}
for (size_t i = str.length() - patternLength, j = 0; i < patternLength; ++i, ++j)
{
if (towlower(str[i]) != towlower(pattern[j]))
{
return false;
}
}
return true;
}
bool StringHelpers::Contains(const AZStd::string& str, const AZStd::string& pattern)
{
const size_t patternLength = pattern.length();
if (str.length() < patternLength)
{
return false;
}
const size_t n = str.length() - patternLength + 1;
for (size_t i = 0; i < n; ++i)
{
if (std::memcmp(str.c_str() + i, pattern.c_str(), patternLength) == 0)
{
return true;
}
}
return false;
}
bool StringHelpers::Contains(const wstring& str, const wstring& pattern)
{
const size_t patternLength = pattern.length();
if (str.length() < patternLength)
{
return false;
}
const size_t n = str.length() - patternLength + 1;
for (size_t i = 0; i < n; ++i)
{
if (std::memcmp(str.c_str() + i, pattern.c_str(), patternLength * sizeof(wstring::value_type)) == 0)
{
return true;
}
}
return false;
}
bool StringHelpers::ContainsIgnoreCase(const AZStd::string& str, const AZStd::string& pattern)
{
const size_t patternLength = pattern.length();
if (str.length() < patternLength)
{
return false;
}
const size_t n = str.length() - patternLength + 1;
for (size_t i = 0; i < n; ++i)
{
if (azmemicmp(str.c_str() + i, pattern.c_str(), patternLength) == 0)
{
return true;
}
}
return false;
}
bool StringHelpers::ContainsIgnoreCase(const wstring& str, const wstring& pattern)
{
const size_t patternLength = pattern.length();
if (patternLength == 0)
{
return true;
}
if (str.length() < patternLength)
{
return false;
}
const wstring::value_type firstPatternLetter = towlower(pattern[0]);
const size_t n = str.length() - patternLength + 1;
for (size_t i = 0; i < n; ++i)
{
bool match = true;
for (size_t j = 0; j < patternLength; ++j)
{
if (towlower(str[i + j]) != towlower(pattern[j]))
{
match = false;
break;
}
}
if (match)
{
return true;
}
}
return false;
}
string StringHelpers::TrimLeft(const AZStd::string& s)
{
const size_t first = s.find_first_not_of(" \r\t");
return (first == s.npos) ? string() : s.substr(first);
}
wstring StringHelpers::TrimLeft(const wstring& s)
{
const size_t first = s.find_first_not_of(L" \r\t");
return (first == s.npos) ? wstring() : s.substr(first);
}
string StringHelpers::TrimRight(const AZStd::string& s)
{
const size_t last = s.find_last_not_of(" \r\t");
return (last == s.npos) ? s : s.substr(0, last + 1);
}
wstring StringHelpers::TrimRight(const wstring& s)
{
const size_t last = s.find_last_not_of(L" \r\t");
return (last == s.npos) ? s : s.substr(0, last + 1);
}
string StringHelpers::Trim(const AZStd::string& s)
{
return TrimLeft(TrimRight(s));
}
wstring StringHelpers::Trim(const wstring& s)
{
return TrimLeft(TrimRight(s));
}
template <class TS>
static inline TS RemoveDuplicateSpaces_Tpl(const TS& s)
{
TS res;
bool spaceFound = false;
for (size_t i = 0, n = s.length(); i < n; ++i)
{
if ((s[i] == ' ') || (s[i] == '\r') || (s[i] == '\t'))
{
spaceFound = true;
}
else
{
if (spaceFound)
{
res += ' ';
spaceFound = false;
}
res += s[i];
}
}
if (spaceFound)
{
res += ' ';
}
return res;
}
string StringHelpers::RemoveDuplicateSpaces(const AZStd::string& s)
{
return RemoveDuplicateSpaces_Tpl(s);
}
wstring StringHelpers::RemoveDuplicateSpaces(const wstring& s)
{
return RemoveDuplicateSpaces_Tpl(s);
}
template <class TS>
static inline TS MakeLowerCase_Tpl(const TS& s)
{
TS copy;
copy.reserve(s.length());
for (typename TS::const_iterator it = s.begin(), end = s.end(); it != end; ++it)
{
copy.append(1, ToLower(*it));
}
return copy;
}
string StringHelpers::MakeLowerCase(const AZStd::string& s)
{
return MakeLowerCase_Tpl(s);
}
wstring StringHelpers::MakeLowerCase(const wstring& s)
{
return MakeLowerCase_Tpl(s);
}
template <class TS>
static inline TS MakeUpperCase_Tpl(const TS& s)
{
TS copy;
copy.reserve(s.length());
for (typename TS::const_iterator it = s.begin(), end = s.end(); it != end; ++it)
{
copy.append(1, ToUpper(*it));
}
return copy;
}
string StringHelpers::MakeUpperCase(const AZStd::string& s)
{
return MakeUpperCase_Tpl(s);
}
wstring StringHelpers::MakeUpperCase(const wstring& s)
{
return MakeUpperCase_Tpl(s);
}
template <class TS>
static inline TS Replace_Tpl(const TS& s, const typename TS::value_type oldChar, const typename TS::value_type newChar)
{
TS copy;
copy.reserve(s.length());
for (typename TS::const_iterator it = s.begin(), end = s.end(); it != end; ++it)
{
const typename TS::value_type c = (*it);
copy.append(1, ((c == oldChar) ? newChar : c));
}
return copy;
}
string StringHelpers::Replace(const AZStd::string& s, char oldChar, char newChar)
{
return Replace_Tpl(s, oldChar, newChar);
}
wstring StringHelpers::Replace(const wstring& s, wchar_t oldChar, wchar_t newChar)
{
return Replace_Tpl(s, oldChar, newChar);
}
void StringHelpers::ConvertStringByRef(string& out, const AZStd::string& in)
{
out = in;
}
void StringHelpers::ConvertStringByRef(wstring& out, const AZStd::string& in)
{
Unicode::Convert(out, in);
}
void StringHelpers::ConvertStringByRef(string& out, const wstring& in)
{
Unicode::Convert(out, in);
}
void StringHelpers::ConvertStringByRef(wstring& out, const wstring& in)
{
out = in;
}
template <class TS>
static inline void Split_Tpl(const TS& str, const TS& separator, bool bReturnEmptyPartsToo, std::vector<TS>& outParts)
{
@ -588,348 +85,12 @@ static inline void Split_Tpl(const TS& str, const TS& separator, bool bReturnEmp
}
}
template <class TS>
static inline void SplitByAnyOf_Tpl(const TS& str, const TS& separators, bool bReturnEmptyPartsToo, std::vector<TS>& outParts)
{
if (str.empty())
{
return;
}
if (separators.empty())
{
for (size_t i = 0; i < str.length(); ++i)
{
outParts.push_back(str.substr(i, 1));
}
return;
}
size_t partStart = 0;
for (;; )
{
const size_t pos = str.find_first_of(separators, partStart);
if (pos == TS::npos)
{
break;
}
if (bReturnEmptyPartsToo || (pos > partStart))
{
outParts.push_back(str.substr(partStart, pos - partStart));
}
partStart = pos + 1;
}
if (bReturnEmptyPartsToo || (partStart < str.length()))
{
outParts.push_back(str.substr(partStart, str.length() - partStart));
}
}
void StringHelpers::Split(const AZStd::string& str, const AZStd::string& separator, bool bReturnEmptyPartsToo, std::vector<string>& outParts)
void StringHelpers::Split(const AZStd::string& str, const AZStd::string& separator, bool bReturnEmptyPartsToo, std::vector<AZStd::string>& outParts)
{
Split_Tpl(str, separator, bReturnEmptyPartsToo, outParts);
}
void StringHelpers::Split(const wstring& str, const wstring& separator, bool bReturnEmptyPartsToo, std::vector<wstring>& outParts)
void StringHelpers::Split(const AZStd::wstring& str, const AZStd::wstring& separator, bool bReturnEmptyPartsToo, std::vector<AZStd::wstring>& outParts)
{
Split_Tpl(str, separator, bReturnEmptyPartsToo, outParts);
}
void StringHelpers::SplitByAnyOf(const AZStd::string& str, const AZStd::string& separators, bool bReturnEmptyPartsToo, std::vector<string>& outParts)
{
SplitByAnyOf_Tpl(str, separators, bReturnEmptyPartsToo, outParts);
}
void StringHelpers::SplitByAnyOf(const wstring& str, const wstring& separators, bool bReturnEmptyPartsToo, std::vector<wstring>& outParts)
{
SplitByAnyOf_Tpl(str, separators, bReturnEmptyPartsToo, outParts);
}
template <class TS>
static inline TS FormatVA_Tpl(const typename TS::value_type* const format, va_list parg)
{
if ((format == 0) || (format[0] == 0))
{
return TS();
}
std::vector<typename TS::value_type> bf;
size_t capacity = 0;
size_t wantedCapacity = Vscprintf(format, parg);
wantedCapacity += 2; // '+ 2' to prevent uncertainty when Vsnprintf_s() returns 'size - 1'
for (;; )
{
if (wantedCapacity > capacity)
{
capacity = wantedCapacity;
bf.resize(capacity + 1);
}
const int countWritten = Vsnprintf_s(&bf[0], capacity + 1, _TRUNCATE, format, parg);
if ((countWritten >= 0) && (capacity > (size_t)countWritten + 1))
{
bf[countWritten] = 0;
return TS(&bf[0]);
}
wantedCapacity = capacity * 2;
}
}
string StringHelpers::FormatVA(const char* const format, va_list parg)
{
return FormatVA_Tpl<string>(format, parg);
}
wstring StringHelpers::FormatVA(const wchar_t* const format, va_list parg)
{
return FormatVA_Tpl<wstring>(format, parg);
}
//////////////////////////////////////////////////////////////////////////
template <class TC>
static inline void SafeCopy_Tpl(TC* const pDstBuffer, const size_t dstBufferSizeInBytes, const TC* const pSrc)
{
if (dstBufferSizeInBytes >= sizeof(TC))
{
const size_t n = dstBufferSizeInBytes / sizeof(TC) - 1;
size_t i;
for (i = 0; i < n && pSrc[i]; ++i)
{
pDstBuffer[i] = pSrc[i];
}
pDstBuffer[i] = 0;
}
}
template <class TC>
static inline void SafeCopyPadZeros_Tpl(TC* const pDstBuffer, const size_t dstBufferSizeInBytes, const TC* const pSrc)
{
if (dstBufferSizeInBytes > 0)
{
const size_t n = (dstBufferSizeInBytes < sizeof(TC)) ? 0 : dstBufferSizeInBytes / sizeof(TC) - 1;
size_t i;
for (i = 0; i < n && pSrc[i]; ++i)
{
pDstBuffer[i] = pSrc[i];
}
memset(&pDstBuffer[i], 0, dstBufferSizeInBytes - i * sizeof(TC));
}
}
void StringHelpers::SafeCopy(char* const pDstBuffer, const size_t dstBufferSizeInBytes, const char* const pSrc)
{
SafeCopy_Tpl<char>(pDstBuffer, dstBufferSizeInBytes, pSrc);
}
void StringHelpers::SafeCopy(wchar_t* const pDstBuffer, const size_t dstBufferSizeInBytes, const wchar_t* const pSrc)
{
SafeCopy_Tpl<wchar_t>(pDstBuffer, dstBufferSizeInBytes, pSrc);
}
void StringHelpers::SafeCopyPadZeros(char* const pDstBuffer, const size_t dstBufferSizeInBytes, const char* const pSrc)
{
SafeCopyPadZeros_Tpl<char>(pDstBuffer, dstBufferSizeInBytes, pSrc);
}
void StringHelpers::SafeCopyPadZeros(wchar_t* const pDstBuffer, const size_t dstBufferSizeInBytes, const wchar_t* const pSrc)
{
SafeCopyPadZeros_Tpl<wchar_t>(pDstBuffer, dstBufferSizeInBytes, pSrc);
}
//////////////////////////////////////////////////////////////////////////
bool StringHelpers::Utf16ContainsAsciiOnly(const wchar_t* wstr)
{
while (*wstr)
{
if (*wstr > 127 || *wstr < 0)
{
return false;
}
++wstr;
}
return true;
}
string StringHelpers::ConvertAsciiUtf16ToAscii(const wchar_t* wstr)
{
const size_t len = wcslen(wstr);
string result;
result.reserve(len);
for (size_t i = 0; i < len; ++i)
{
result.push_back(wstr[i] & 0x7F);
}
return result;
}
wstring StringHelpers::ConvertAsciiToUtf16(const char* str)
{
const size_t len = strlen(str);
wstring result;
result.reserve(len);
for (size_t i = 0; i < len; ++i)
{
result.push_back(str[i] & 0x7F);
}
return result;
}
#if defined(AZ_PLATFORM_WINDOWS)
static string ConvertUtf16ToMultibyte(const wchar_t* wstr, uint codePage, char badChar)
{
if (wstr[0] == 0)
{
return string();
}
const int len = aznumeric_caster(wcslen(wstr));
// Request needed buffer size, in bytes
int neededByteCount = WideCharToMultiByte(
codePage,
0,
wstr,
len,
0,
0,
((badChar && codePage != CP_UTF8) ? &badChar : NULL),
NULL);
if (neededByteCount <= 0)
{
return string();
}
++neededByteCount; // extra space for terminating zero
std::vector<char> buffer(neededByteCount);
const int byteCount = WideCharToMultiByte(
codePage,
0,
wstr,
len,
&buffer[0], // output buffer
neededByteCount - 1, // size of the output buffer in bytes
((badChar && codePage != CP_UTF8) ? &badChar : NULL),
NULL);
if (byteCount != neededByteCount - 1)
{
return string();
}
buffer[byteCount] = 0;
return string(&buffer[0]);
}
static wstring ConvertMultibyteToUtf16(const char* str, uint codePage)
{
if (str[0] == 0)
{
return wstring();
}
const int len = aznumeric_caster(strlen(str));
// Request needed buffer size, in characters
int neededCharCount = MultiByteToWideChar(
codePage,
0,
str,
len,
0,
0);
if (neededCharCount <= 0)
{
return wstring();
}
++neededCharCount; // extra space for terminating zero
std::vector<wchar_t> wbuffer(neededCharCount);
const int charCount = MultiByteToWideChar(
codePage,
0,
str,
len,
&wbuffer[0], // output buffer
neededCharCount - 1); // size of the output buffer in characters
if (charCount != neededCharCount - 1)
{
return wstring();
}
wbuffer[charCount] = 0;
return wstring(&wbuffer[0]);
}
wstring StringHelpers::ConvertUtf8ToUtf16(const char* str)
{
return ConvertMultibyteToUtf16(str, CP_UTF8);
}
string StringHelpers::ConvertUtf16ToUtf8(const wchar_t* wstr)
{
return ConvertUtf16ToMultibyte(wstr, CP_UTF8, 0);
}
wstring StringHelpers::ConvertAnsiToUtf16(const char* str)
{
return ConvertMultibyteToUtf16(str, CP_ACP);
}
string StringHelpers::ConvertUtf16ToAnsi(const wchar_t* wstr, char badChar)
{
return ConvertUtf16ToMultibyte(wstr, CP_ACP, badChar);
}
#endif //AZ_PLATFORM_WINDOWS
string StringHelpers::ConvertAnsiToAscii(const char* str, char badChar)
{
const size_t len = strlen(str);
string result;
result.reserve(len);
for (size_t i = 0; i < len; ++i)
{
char c = str[i];
if (c < 0 || c > 127)
{
c = badChar;
}
result.push_back(c);
}
return result;
}
// eof

@ -13,193 +13,13 @@
namespace StringHelpers
{
// compares two strings to see if they are the same or different, case sensitive
// returns 0 if the strings are the same, a -1 if the first string is bigger, or a 1 if the second string is bigger
int Compare(const AZStd::string& str0, const AZStd::string& str1);
int Compare(const wstring& str0, const wstring& str1);
// compares two strings to see if they are the same or different, case is ignored
// returns 0 if the strings are the same, a -1 if the first string is bigger, or a 1 if the second string is bigger
int CompareIgnoreCase(const AZStd::string& str0, const AZStd::string& str1);
int CompareIgnoreCase(const wstring& str0, const wstring& str1);
// compares two strings to see if they are the same, case senstive
// returns true if they are the same or false if they are different
bool Equals(const AZStd::string& str0, const AZStd::string& str1);
bool Equals(const wstring& str0, const wstring& str1);
// compares two strings to see if they are the same, case is ignored
// returns true if they are the same or false if they are different
bool EqualsIgnoreCase(const AZStd::string& str0, const AZStd::string& str1);
bool EqualsIgnoreCase(const wstring& str0, const wstring& str1);
// checks to see if a string starts with a specified string, case sensitive
// returns true if the string does start with a specified string or false if it does not
bool StartsWith(const AZStd::string& str, const AZStd::string& pattern);
bool StartsWith(const wstring& str, const wstring& pattern);
// checks to see if a string starts with a specified string, case is ignored
// returns true if the string does start with a specified string or false if it does not
bool StartsWithIgnoreCase(const AZStd::string& str, const AZStd::string& pattern);
bool StartsWithIgnoreCase(const wstring& str, const wstring& pattern);
// checks to see if a string ends with a specified string, case sensitive
// returns true if the string does end with a specified string or false if it does not
bool EndsWith(const AZStd::string& str, const AZStd::string& pattern);
bool EndsWith(const wstring& str, const wstring& pattern);
// checks to see if a string ends with a specified string, case is ignored
// returns true if the string does end with a specified string or false if it does not
bool EndsWithIgnoreCase(const AZStd::string& str, const AZStd::string& pattern);
bool EndsWithIgnoreCase(const wstring& str, const wstring& pattern);
// checks to see if a string contains a specified string, case sensitive
// returns true if the string does contain the specified string or false if it does not
bool Contains(const AZStd::string& str, const AZStd::string& pattern);
bool Contains(const wstring& str, const wstring& pattern);
// checks to see if a string contains a specified string, case is ignored
// returns true if the string does contain the specified string or false if it does not
bool ContainsIgnoreCase(const AZStd::string& str, const AZStd::string& pattern);
bool ContainsIgnoreCase(const wstring& str, const wstring& pattern);
string TrimLeft(const AZStd::string& s);
wstring TrimLeft(const wstring& s);
string TrimRight(const AZStd::string& s);
wstring TrimRight(const wstring& s);
string Trim(const AZStd::string& s);
wstring Trim(const wstring& s);
string RemoveDuplicateSpaces(const AZStd::string& s);
wstring RemoveDuplicateSpaces(const wstring& s);
// converts a string with upper case characters to be all lower case
// returns the string in all lower case
string MakeLowerCase(const AZStd::string& s);
wstring MakeLowerCase(const wstring& s);
// converts a string with lower case characters to be all upper case
// returns the string in all upper case
string MakeUpperCase(const AZStd::string& s);
wstring MakeUpperCase(const wstring& s);
// replace a specified character in a string with a specified replacement character
// returns string with specified character replaced
string Replace(const AZStd::string& s, char oldChar, char newChar);
wstring Replace(const wstring& s, wchar_t oldChar, wchar_t newChar);
void ConvertStringByRef(string& out, const AZStd::string& in);
void ConvertStringByRef(wstring& out, const AZStd::string& in);
void ConvertStringByRef(string& out, const wstring& in);
void ConvertStringByRef(wstring& out, const wstring& in);
template <typename O, typename I>
O ConvertString(const I& in)
{
O out;
ConvertStringByRef(out, in);
return out;
}
void Split(const AZStd::string& str, const AZStd::string& separator, bool bReturnEmptyPartsToo, std::vector<string>& outParts);
void Split(const wstring& str, const wstring& separator, bool bReturnEmptyPartsToo, std::vector<wstring>& outParts);
void SplitByAnyOf(const AZStd::string& str, const AZStd::string& separators, bool bReturnEmptyPartsToo, std::vector<string>& outParts);
void SplitByAnyOf(const wstring& str, const wstring& separators, bool bReturnEmptyPartsToo, std::vector<wstring>& outParts);
string FormatVA(const char* const format, va_list parg);
wstring FormatVA(const wchar_t* const format, va_list parg);
inline string Format(const char* const format, ...)
{
if ((format == 0) || (format[0] == 0))
{
return string();
}
va_list parg;
va_start(parg, format);
const string result = FormatVA(format, parg);
va_end(parg);
return result;
}
inline wstring Format(const wchar_t* const format, ...)
{
if ((format == 0) || (format[0] == 0))
{
return wstring();
}
va_list parg;
va_start(parg, format);
const wstring result = FormatVA(format, parg);
va_end(parg);
return result;
}
//////////////////////////////////////////////////////////////////////////
void SafeCopy(char* const pDstBuffer, const size_t dstBufferSizeInBytes, const char* const pSrc);
void SafeCopy(wchar_t* const pDstBuffer, const size_t dstBufferSizeInBytes, const wchar_t* const pSrc);
void SafeCopyPadZeros(char* const pDstBuffer, const size_t dstBufferSizeInBytes, const char* const pSrc);
void SafeCopyPadZeros(wchar_t* const pDstBuffer, const size_t dstBufferSizeInBytes, const wchar_t* const pSrc);
//////////////////////////////////////////////////////////////////////////
// ASCII
// ANSI (system default Windows ANSI code page)
// UTF-8
// UTF-16
// ASCII -> UTF-16
bool Utf16ContainsAsciiOnly(const wchar_t* wstr);
string ConvertAsciiUtf16ToAscii(const wchar_t* wstr);
wstring ConvertAsciiToUtf16(const char* str);
// UTF-8 <-> UTF-16
#if defined(AZ_PLATFORM_WINDOWS)
wstring ConvertUtf8ToUtf16(const char* str);
string ConvertUtf16ToUtf8(const wchar_t* wstr);
inline string ConvertUtfToUtf8(const char* str)
{
return string(str);
}
inline string ConvertUtfToUtf8(const wchar_t* wstr)
{
return ConvertUtf16ToUtf8(wstr);
}
inline wstring ConvertUtfToUtf16(const char* str)
{
return ConvertUtf8ToUtf16(str);
}
inline wstring ConvertUtfToUtf16(const wchar_t* wstr)
{
return wstring(wstr);
}
// ANSI <-> UTF-8, UTF-16
wstring ConvertAnsiToUtf16(const char* str);
string ConvertUtf16ToAnsi(const wchar_t* wstr, char badChar);
int CompareIgnoreCase(const AZStd::wstring& str0, const AZStd::wstring& str1);
inline string ConvertAnsiToUtf8(const char* str)
{
return ConvertUtf16ToUtf8(ConvertAnsiToUtf16(str).c_str());
}
inline string ConvertUtf8ToAnsi(const char* str, char badChar)
{
return ConvertUtf16ToAnsi(ConvertUtf8ToUtf16(str).c_str(), badChar);
}
#endif
void Split(const AZStd::string& str, const AZStd::string& separator, bool bReturnEmptyPartsToo, std::vector<AZStd::string>& outParts);
void Split(const AZStd::wstring& str, const AZStd::wstring& separator, bool bReturnEmptyPartsToo, std::vector<AZStd::wstring>& outParts);
// ANSI -> ASCII
string ConvertAnsiToAscii(const char* str, char badChar);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_STRINGHELPERS_H

@ -427,7 +427,7 @@ const AZStd::string& CXmlHistoryManager::GetVersionDesc(int number) const
return it->second.HistoryDescription;
}
static string undef("UNDEFINED");
static AZStd::string undef("UNDEFINED");
return undef;
}
@ -493,7 +493,7 @@ void CXmlHistoryManager::SetActiveGroupInt(const SXmlHistoryGroup* pGroup, const
UnloadInt();
TEventHandlerList eventHandler;
string undoDesc;
AZStd::string undoDesc;
if (pGroup)
{
@ -534,7 +534,7 @@ void CXmlHistoryManager::SetActiveGroupInt(const SXmlHistoryGroup* pGroup, const
}
}
}
undoDesc.Format("Changed View to \"%s\"", displayName ? displayName : "UNDEFINED");
undoDesc = AZStd::string::format("Changed View to \"%s\"", displayName ? displayName : "UNDEFINED");
}
else
{

@ -161,7 +161,7 @@ private:
const SXmlHistoryGroup* CurrGroup;
TGroupIndexMap CurrUserIndex;
string HistoryDescription;
AZStd::string HistoryDescription;
bool IsNullUndo;
bool HistoryInvalidated;
TXmlHistotyGroupPtrList ActiveGroups;

@ -2907,14 +2907,13 @@ void CXConsole::Paste()
Utf8::Unchecked::octet_iterator end(data.end());
for (Utf8::Unchecked::octet_iterator it(data.begin()); it != end; ++it)
{
const uint32 cp = *it;
const wchar_t cp = *it;
if (cp != '\r')
{
// Convert UCS code-point into UTF-8 string
AZStd::fixed_string<5> utf8_buf = {0};
size_t size = 5;
it.to_utf8_sequence(cp, utf8_buf.data(), size);
AddInputUTF8(utf8_buf);
AZStd::to_string(utf8_buf.data(), 5, &cp, 1);
AddInputUTF8(utf8_buf.c_str());
}
}
}

Loading…
Cancel
Save