mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Deprecate and remove xtl::format in favor of plString::Format
This commit is contained in:
@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include "hsStlUtils.h"
|
||||
#include "hsTemplates.h"
|
||||
#include "plString.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -214,6 +215,7 @@ void hsStatusMessageF(const char * fmt, ...)
|
||||
|
||||
#endif
|
||||
|
||||
// TODO: Deprecate these in favor of plString
|
||||
char * hsFormatStr(const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
@ -225,8 +227,7 @@ char * hsFormatStr(const char * fmt, ...)
|
||||
|
||||
char * hsFormatStrV(const char * fmt, va_list args)
|
||||
{
|
||||
std::string buf;
|
||||
xtl::formatv(buf,fmt,args);
|
||||
plString buf = plString::IFormat(fmt, args);
|
||||
return hsStrcpy(buf.c_str());
|
||||
}
|
||||
|
||||
@ -460,6 +461,8 @@ char *hsWStringToString( const wchar_t *str )
|
||||
//
|
||||
char** DisplaySystemVersion()
|
||||
{
|
||||
// TODO: I so want to std::vector<plString> this, but that requires
|
||||
// including more headers in HeadSpin.h :(
|
||||
#if HS_BUILD_FOR_WIN32
|
||||
#ifndef VER_SUITE_PERSONAL
|
||||
#define VER_SUITE_PERSONAL 0x200
|
||||
@ -554,7 +557,7 @@ char** DisplaySystemVersion()
|
||||
|
||||
if ( osvi.dwMajorVersion <= 4 )
|
||||
{
|
||||
versionStrs.Append(hsStrcpy (xtl::format("version %d.%d %s (Build %d)\n",
|
||||
versionStrs.Append(hsStrcpy (plString::Format("version %d.%d %s (Build %d)\n",
|
||||
osvi.dwMajorVersion,
|
||||
osvi.dwMinorVersion,
|
||||
osvi.szCSDVersion,
|
||||
@ -562,7 +565,7 @@ char** DisplaySystemVersion()
|
||||
}
|
||||
else
|
||||
{
|
||||
versionStrs.Append(hsStrcpy (xtl::format("%s (Build %d)\n",
|
||||
versionStrs.Append(hsStrcpy (plString::Format("%s (Build %d)\n",
|
||||
osvi.szCSDVersion,
|
||||
osvi.dwBuildNumber & 0xFFFF).c_str()));
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ std::wstring & trimleft(std::wstring & s, const wchar_t * charset)
|
||||
|
||||
std::string & trimright(std::string & s, const char * charset)
|
||||
{
|
||||
int idx = s.find_last_not_of(charset);
|
||||
size_t idx = s.find_last_not_of(charset);
|
||||
|
||||
if (std::string::npos == idx)
|
||||
{
|
||||
@ -77,7 +77,7 @@ std::string & trimright(std::string & s, const char * charset)
|
||||
|
||||
std::wstring & trimright(std::wstring & s, const wchar_t * charset)
|
||||
{
|
||||
int idx = s.find_last_not_of(charset);
|
||||
size_t idx = s.find_last_not_of(charset);
|
||||
|
||||
if (std::wstring::npos == idx)
|
||||
{
|
||||
@ -107,197 +107,6 @@ std::wstring & trim(std::wstring & s, const wchar_t * charset)
|
||||
return s;
|
||||
}
|
||||
|
||||
// c-string
|
||||
std::string trim(const char * s, const char * charset)
|
||||
{
|
||||
std::string result = s;
|
||||
trimleft(result,charset);
|
||||
trimright(result,charset);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring trim(const wchar_t * s, const wchar_t * charset)
|
||||
{
|
||||
std::wstring result = s;
|
||||
trimleft(result,charset);
|
||||
trimright(result,charset);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// format
|
||||
std::string format(const char * fmt, ...)
|
||||
{
|
||||
std::string result;
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
formatv(result,fmt,args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring format(const wchar_t * fmt, ...)
|
||||
{
|
||||
std::wstring result;
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
formatv(result,fmt,args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string formatv(const char * fmt, va_list args)
|
||||
{
|
||||
std::string result;
|
||||
formatv( result, fmt, args );
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring formatv(const wchar_t * fmt, va_list args)
|
||||
{
|
||||
std::wstring result;
|
||||
formatv( result, fmt, args );
|
||||
return result;
|
||||
}
|
||||
|
||||
bool format(std::string & out, const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
bool r = formatv(out,fmt,args);
|
||||
va_end(args);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool format(std::wstring & out, const wchar_t * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
bool r = formatv(out,fmt,args);
|
||||
va_end(args);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool formatv(std::string & out, const char * fmt, va_list args)
|
||||
{
|
||||
#define kBufSz 2048
|
||||
|
||||
char buf[kBufSz];
|
||||
char * pbuf = buf;
|
||||
int len = 0;
|
||||
int attempts = 0;
|
||||
bool success = false;
|
||||
const int kMaxAttempts = 40;
|
||||
|
||||
do
|
||||
{
|
||||
int maxlen = kBufSz*attempts+kBufSz-1;
|
||||
len = hsVsnprintf(pbuf,maxlen,fmt,args);
|
||||
attempts++;
|
||||
success = (len>=0 && len<maxlen);
|
||||
if (!success)
|
||||
{
|
||||
if (pbuf!=buf)
|
||||
delete [] pbuf;
|
||||
pbuf = new char[kBufSz+kBufSz*attempts];
|
||||
}
|
||||
}
|
||||
while (!success && attempts<kMaxAttempts);
|
||||
|
||||
if (success)
|
||||
{
|
||||
pbuf[len] = '\0';
|
||||
out = pbuf;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
pbuf[len] = '\0';
|
||||
out = pbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
out = "";
|
||||
if ( attempts==kMaxAttempts )
|
||||
{
|
||||
hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting string. Result is likely truncated!", 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if (pbuf!=buf)
|
||||
delete [] pbuf;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool formatv(std::wstring & out, const wchar_t * fmt, va_list args)
|
||||
{
|
||||
#define kBufSz 2048
|
||||
|
||||
wchar_t buf[kBufSz];
|
||||
wchar_t * pbuf = buf;
|
||||
int len = 0;
|
||||
int attempts = 0;
|
||||
bool success = false;
|
||||
const int kMaxAttempts = 40;
|
||||
|
||||
do
|
||||
{
|
||||
int maxlen = kBufSz*attempts+kBufSz-1;
|
||||
len = hsVsnwprintf(pbuf,maxlen,fmt,args);
|
||||
attempts++;
|
||||
success = (len>=0 && len<maxlen);
|
||||
if (!success)
|
||||
{
|
||||
if (pbuf!=buf)
|
||||
delete [] pbuf;
|
||||
pbuf = new wchar_t[kBufSz+kBufSz*attempts];
|
||||
}
|
||||
}
|
||||
while (!success && attempts<kMaxAttempts);
|
||||
|
||||
if (success)
|
||||
{
|
||||
pbuf[len] = L'\0';
|
||||
out = pbuf;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
pbuf[len] = L'\0';
|
||||
out = pbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
out = L"";
|
||||
if ( attempts==kMaxAttempts )
|
||||
{
|
||||
hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting wstring. Result is likely truncated!", 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if (pbuf!=buf)
|
||||
delete [] pbuf;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef std::vector<std::string> StringVector;
|
||||
typedef std::vector<std::wstring> WStringVector;
|
||||
typedef std::list<std::string> StringList;
|
||||
typedef std::list<std::wstring> WStringList;
|
||||
typedef std::set<std::string> StringSet;
|
||||
typedef std::set<std::wstring> WStringSet;
|
||||
|
||||
template bool GetStringGroup<StringList>(const std::string& s, StringList& group, char sep);
|
||||
template bool GetStringGroup<WStringList>(const std::wstring& s, WStringList& group, wchar_t sep);
|
||||
template bool GetStringGroup<StringVector>(const std::string& s, StringVector& group, char sep);
|
||||
template bool GetStringGroup<WStringVector>(const std::wstring& s, WStringVector& group, wchar_t sep);
|
||||
template bool GetStringGroup<StringSet>(const std::string& s, StringSet& group, char sep);
|
||||
template bool GetStringGroup<WStringSet>(const std::wstring& s, WStringSet& group, wchar_t sep);
|
||||
*/
|
||||
|
||||
template <typename T> bool GetStringGroup(const std::string& s, T& group, char sep)
|
||||
{
|
||||
bool ret = false;
|
||||
@ -339,15 +148,6 @@ template <typename T> bool GetStringGroup(const std::wstring& s, T& group, wchar
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
template bool GetStringGroupAsString<StringList>(const StringList& group, std::string& s, char sep);
|
||||
template bool GetStringGroupAsString<WStringList>(const WStringList& group, std::wstring& s, wchar_t sep);
|
||||
template bool GetStringGroupAsString<StringVector>(const StringVector& group, std::string& s, char sep);
|
||||
template bool GetStringGroupAsString<WStringVector>(const WStringVector& group, std::wstring& s, wchar_t sep);
|
||||
template bool GetStringGroupAsString<StringSet>(const StringSet& group, std::string& s, char sep);
|
||||
template bool GetStringGroupAsString<WStringSet>(const WStringSet& group, std::wstring& s, wchar_t sep);
|
||||
*/
|
||||
|
||||
template <typename T> bool GetStringGroupAsString(const T& group, std::string& s, char sep)
|
||||
{
|
||||
typename T::const_iterator it = group.begin();
|
||||
|
@ -62,18 +62,6 @@ std::string & trimright(std::string & s, const char * charset=" \t\n\r");
|
||||
std::wstring & trimright(std::wstring & s, const wchar_t * charset=L" \t\n\r");
|
||||
std::string & trim(std::string & s, const char * charset=" \t\n\r");
|
||||
std::wstring & trim(std::wstring & s, const wchar_t * charset=L" \t\n\r");
|
||||
// c-string trim
|
||||
std::string trim(const char * s, const char * charset=" \t\n\r");
|
||||
std::wstring trim(const wchar_t * s, const wchar_t * charset=L" \t\n\r");
|
||||
// format
|
||||
std::string format(const char * fmt, ...);
|
||||
std::wstring format(const wchar_t * fmt, ...);
|
||||
std::string formatv(const char * fmt, va_list args);
|
||||
std::wstring formatv(const wchar_t * fmt, va_list args);
|
||||
bool format(std::string & out, const char * fmt, ...);
|
||||
bool format(std::wstring & out, const wchar_t * fmt, ...);
|
||||
bool formatv(std::string & out, const char * fmt, va_list args);
|
||||
bool formatv(std::wstring & out, const wchar_t * fmt, va_list args);
|
||||
|
||||
|
||||
template <typename T> bool GetStringGroup(const std::string& s, T& group, char sep = ',');
|
||||
|
@ -123,9 +123,8 @@ uint32_t hsStream::WriteFmt(const char * fmt, ...)
|
||||
|
||||
uint32_t hsStream::WriteFmtV(const char * fmt, va_list av)
|
||||
{
|
||||
std::string buf;
|
||||
xtl::formatv( buf, fmt, av );
|
||||
return Write( buf.length(), buf.data() );
|
||||
plString buf = plString::IFormat(fmt, av);
|
||||
return Write( buf.GetSize(), buf.c_str() );
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeStringLong(const plString &string)
|
||||
|
@ -83,6 +83,9 @@ public:
|
||||
hsStream() : fBytesRead(0), fPosition(0) {}
|
||||
virtual ~hsStream() { }
|
||||
|
||||
// Pre-filename-stringification shortcut:
|
||||
bool Open_TEMP(const plString & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
|
||||
|
||||
virtual bool Open(const char *, const char * = "rb")=0;
|
||||
virtual bool Open(const wchar_t *, const wchar_t * = L"rb")=0;
|
||||
virtual bool Close()=0;
|
||||
|
@ -750,6 +750,15 @@ std::vector<plString> plString::Split(const char *split, size_t maxSplits) const
|
||||
return result;
|
||||
}
|
||||
|
||||
plString plString::Fill(size_t count, char c)
|
||||
{
|
||||
plStringBuffer<char> buf;
|
||||
char *data = buf.CreateWritableBuffer(count + 1);
|
||||
memset(data, c, count);
|
||||
data[count] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
plString operator+(const plString &left, const plString &right)
|
||||
{
|
||||
plString cat;
|
||||
|
@ -299,6 +299,8 @@ public:
|
||||
std::vector<plString> Split(const char *split, size_t maxSplits = kSizeAuto) const;
|
||||
std::vector<plString> Tokenize(const char *delims = " \t\r\n\f\v") const;
|
||||
|
||||
static plString Fill(size_t count, char c);
|
||||
|
||||
public:
|
||||
struct less
|
||||
{
|
||||
|
Reference in New Issue
Block a user