Code/Editor

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-08-02 17:56:56 -07:00
parent 3b28267569
commit a14b4e478e
47 changed files with 208 additions and 1219 deletions
@@ -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;
+8 -7
View File
@@ -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;
+1 -2
View File
@@ -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"
+3 -3
View File
@@ -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)
+1 -2
View File
@@ -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
+4 -843
View File
@@ -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
+4 -184
View File
@@ -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);
int CompareIgnoreCase(const AZStd::wstring& str0, const AZStd::wstring& str1);
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);
// 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);
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
// ANSI -> ASCII
string ConvertAnsiToAscii(const char* str, char badChar);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_STRINGHELPERS_H
+3 -3
View File
@@ -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
{
+1 -1
View File
@@ -161,7 +161,7 @@ private:
const SXmlHistoryGroup* CurrGroup;
TGroupIndexMap CurrUserIndex;
string HistoryDescription;
AZStd::string HistoryDescription;
bool IsNullUndo;
bool HistoryInvalidated;
TXmlHistotyGroupPtrList ActiveGroups;