mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Alright, this _TEMP_CONVERT_ stuff was a stupid idea
This commit is contained in:
@ -139,40 +139,36 @@ uint32_t hsStream::WriteFmtV(const char * fmt, va_list av)
|
||||
return Write( buf.length(), buf.data() );
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeStringLong(const char *string)
|
||||
uint32_t hsStream::WriteSafeStringLong(const plString &string)
|
||||
{
|
||||
uint32_t len = 0;
|
||||
if (string)
|
||||
len = strlen(string);
|
||||
uint32_t len = string.GetSize();
|
||||
WriteLE32(len);
|
||||
if (len > 0)
|
||||
{
|
||||
char *buff = new char[len+1];
|
||||
const char *buffp = string.c_str();
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
buff[i] = ~string[i];
|
||||
WriteByte(~buffp[i]);
|
||||
}
|
||||
buff[len] = '\0';
|
||||
uint32_t result = Write(len, buff);
|
||||
delete [] buff;
|
||||
return result;
|
||||
return static_cast<uint32_t>(i);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeWStringLong(const wchar_t *string)
|
||||
uint32_t hsStream::WriteSafeWStringLong(const plString &string)
|
||||
{
|
||||
uint32_t len = wcslen(string);
|
||||
plStringBuffer<wchar_t> wbuff = string.ToWchar();
|
||||
uint32_t len = wbuff.GetSize();
|
||||
WriteLE32(len);
|
||||
if (len > 0)
|
||||
{
|
||||
int i;
|
||||
const wchar_t *buffp = wbuff.GetData();
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
wchar_t buff = ~string[i];
|
||||
WriteLE16((uint16_t)buff);
|
||||
WriteLE16((uint16_t)~buffp[i]);
|
||||
}
|
||||
WriteLE16((uint16_t)L'\0');
|
||||
}
|
||||
@ -224,35 +220,31 @@ wchar_t *hsStream::ReadSafeWStringLong()
|
||||
return retVal;
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeString(const char *string)
|
||||
uint32_t hsStream::WriteSafeString(const plString &string)
|
||||
{
|
||||
int len = 0;
|
||||
if (string)
|
||||
len = strlen(string);
|
||||
hsAssert(len<0xf000, xtl::format("string len of %d is too long for WriteSafeString %s, use WriteSafeStringLong",
|
||||
string, len).c_str() );
|
||||
int len = string.GetSize();
|
||||
hsAssert(len<0xf000, plString::Format("string len of %d is too long for WriteSafeString %s, use WriteSafeStringLong",
|
||||
len, string.c_str()).c_str() );
|
||||
|
||||
WriteLE16(len | 0xf000);
|
||||
if (len > 0)
|
||||
{
|
||||
char *buff = new char[len+1];
|
||||
int i;
|
||||
const char *buffp = string.c_str();
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
buff[i] = ~string[i];
|
||||
WriteByte(~buffp[i]);
|
||||
}
|
||||
buff[len] = '\0';
|
||||
uint32_t result = Write(len, buff);
|
||||
delete [] buff;
|
||||
return result;
|
||||
return static_cast<uint32_t>(i);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeWString(const wchar_t *string)
|
||||
uint32_t hsStream::WriteSafeWString(const plString &string)
|
||||
{
|
||||
int len = wcslen(string);
|
||||
plStringBuffer<wchar_t> wbuff = string.ToWchar();
|
||||
int len = wbuff.GetSize();
|
||||
hsAssert(len<0xf000, xtl::format("string len of %d is too long for WriteSafeWString, use WriteSafeWStringLong",
|
||||
len).c_str() );
|
||||
|
||||
@ -260,10 +252,10 @@ uint32_t hsStream::WriteSafeWString(const wchar_t *string)
|
||||
if (len > 0)
|
||||
{
|
||||
int i;
|
||||
const wchar_t *buffp = wbuff.GetData();
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
wchar_t buff = ~string[i];
|
||||
WriteLE16((uint16_t)buff);
|
||||
WriteLE16((uint16_t)~buffp[i]);
|
||||
}
|
||||
WriteLE16((uint16_t)L'\0');
|
||||
}
|
||||
@ -328,16 +320,6 @@ wchar_t *hsStream::ReadSafeWString()
|
||||
return retVal;
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeString(const plString &string)
|
||||
{
|
||||
return WriteSafeString(_TEMP_CONVERT_TO_CONST_CHAR(string));
|
||||
}
|
||||
|
||||
uint32_t hsStream::WriteSafeWString(const plString &string)
|
||||
{
|
||||
return WriteSafeWString(_TEMP_CONVERT_TO_WCHAR_T(string));
|
||||
}
|
||||
|
||||
plString hsStream::ReadSafeString_TEMP()
|
||||
{
|
||||
char *buffer = ReadSafeString();
|
||||
|
@ -124,22 +124,20 @@ public:
|
||||
virtual bool IsCompressed() { return false; }
|
||||
|
||||
uint32_t WriteString(const char cstring[]);
|
||||
uint32_t WriteString(const plString & string) { return WriteString(_TEMP_CONVERT_TO_CONST_CHAR(string)); }
|
||||
uint32_t WriteString(const plString & string) { return WriteString(string.c_str()); }
|
||||
uint32_t WriteFmt(const char * fmt, ...);
|
||||
uint32_t WriteFmtV(const char * fmt, va_list av);
|
||||
|
||||
uint32_t WriteSafeStringLong(const char *string); // uses 4 bytes for length
|
||||
uint32_t WriteSafeWStringLong(const wchar_t *string);
|
||||
uint32_t WriteSafeStringLong(const plString &string); // uses 4 bytes for length
|
||||
uint32_t WriteSafeWStringLong(const plString &string);
|
||||
char * ReadSafeStringLong();
|
||||
wchar_t * ReadSafeWStringLong();
|
||||
|
||||
uint32_t WriteSafeString(const char *string); // uses 2 bytes for length
|
||||
uint32_t WriteSafeWString(const wchar_t *string);
|
||||
uint32_t WriteSafeString(const plString &string); // uses 2 bytes for length
|
||||
uint32_t WriteSafeWString(const plString &string);
|
||||
char * ReadSafeString();
|
||||
wchar_t * ReadSafeWString();
|
||||
|
||||
uint32_t WriteSafeString(const plString &string); // uses 2 bytes for length
|
||||
uint32_t WriteSafeWString(const plString &string);
|
||||
plString ReadSafeString_TEMP();
|
||||
plString ReadSafeWString_TEMP();
|
||||
|
||||
|
@ -50,24 +50,7 @@ plGeneric::plGeneric(const int& val): fType(kInt), fBoolVal(false), fIntVal(val)
|
||||
|
||||
plGeneric::plGeneric(const double& val): fType(kFloat), fBoolVal(false), fIntVal(0), fFloatVal(val) {}
|
||||
|
||||
plGeneric::plGeneric(const char* val): fType(kString), fBoolVal(false), fIntVal(0), fFloatVal(0.0)
|
||||
{
|
||||
wchar_t* temp = hsStringToWString(val);
|
||||
fStringVal = temp;
|
||||
delete [] temp;
|
||||
}
|
||||
|
||||
plGeneric::plGeneric(const std::string& val): fType(kString), fBoolVal(false), fIntVal(0), fFloatVal(0.0)
|
||||
{
|
||||
wchar_t* temp = hsStringToWString(val.c_str());
|
||||
fStringVal = temp;
|
||||
delete [] temp;
|
||||
}
|
||||
|
||||
plGeneric::plGeneric(const wchar_t* val): fType(kString), fBoolVal(false), fIntVal(0), fFloatVal(0.0),
|
||||
fStringVal(val) {}
|
||||
|
||||
plGeneric::plGeneric(const std::wstring& val): fType(kString), fBoolVal(false), fIntVal(0), fFloatVal(0.0),
|
||||
plGeneric::plGeneric(const plString& val): fType(kString), fBoolVal(false), fIntVal(0), fFloatVal(0.0),
|
||||
fStringVal(val) {}
|
||||
|
||||
void plGeneric::IReset()
|
||||
@ -76,7 +59,7 @@ void plGeneric::IReset()
|
||||
fBoolVal = false;
|
||||
fIntVal = 0;
|
||||
fFloatVal = 0.0;
|
||||
fStringVal = L"";
|
||||
fStringVal = plString();
|
||||
}
|
||||
|
||||
plGeneric& plGeneric::operator=(const bool& val)
|
||||
@ -103,35 +86,7 @@ plGeneric& plGeneric::operator=(const double& val)
|
||||
return *this;
|
||||
}
|
||||
|
||||
plGeneric& plGeneric::operator=(const char* val)
|
||||
{
|
||||
IReset();
|
||||
fType = kString;
|
||||
wchar_t* temp = hsStringToWString(val);
|
||||
fStringVal = temp;
|
||||
delete [] temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
plGeneric& plGeneric::operator=(const std::string& val)
|
||||
{
|
||||
IReset();
|
||||
fType = kString;
|
||||
wchar_t* temp = hsStringToWString(val.c_str());
|
||||
fStringVal = temp;
|
||||
delete [] temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
plGeneric& plGeneric::operator=(const wchar_t* val)
|
||||
{
|
||||
IReset();
|
||||
fType = kString;
|
||||
fStringVal = val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
plGeneric& plGeneric::operator=(const std::wstring& val)
|
||||
plGeneric& plGeneric::operator=(const plString& val)
|
||||
{
|
||||
IReset();
|
||||
fType = kString;
|
||||
@ -161,7 +116,7 @@ int plGeneric::Write(hsStream* stream)
|
||||
break;
|
||||
|
||||
case kString:
|
||||
stream->WriteSafeWString(fStringVal.c_str());
|
||||
stream->WriteSafeWString(fStringVal);
|
||||
break;
|
||||
}
|
||||
return stream->GetPosition();
|
||||
@ -189,14 +144,7 @@ int plGeneric::Read(hsStream* stream)
|
||||
break;
|
||||
|
||||
case kString:
|
||||
{
|
||||
wchar_t* temp = stream->ReadSafeWString();
|
||||
if (temp)
|
||||
{
|
||||
fStringVal = temp;
|
||||
delete [] temp;
|
||||
}
|
||||
}
|
||||
fStringVal = stream->ReadSafeWString_TEMP();
|
||||
break;
|
||||
}
|
||||
return stream->GetPosition();
|
||||
|
@ -62,7 +62,7 @@ private:
|
||||
bool fBoolVal;
|
||||
int fIntVal;
|
||||
double fFloatVal;
|
||||
std::wstring fStringVal;
|
||||
plString fStringVal;
|
||||
|
||||
void IReset();
|
||||
|
||||
@ -71,19 +71,13 @@ public:
|
||||
plGeneric(const bool& val);
|
||||
plGeneric(const int& val);
|
||||
plGeneric(const double& val);
|
||||
plGeneric(const char* val);
|
||||
plGeneric(const std::string& val);
|
||||
plGeneric(const wchar_t* val);
|
||||
plGeneric(const std::wstring& val);
|
||||
plGeneric(const plString& val);
|
||||
|
||||
void SetToNull() {IReset();}
|
||||
plGeneric& operator=(const bool& val);
|
||||
plGeneric& operator=(const int& val);
|
||||
plGeneric& operator=(const double& val);
|
||||
plGeneric& operator=(const char* val);
|
||||
plGeneric& operator=(const std::string& val);
|
||||
plGeneric& operator=(const wchar_t* val);
|
||||
plGeneric& operator=(const std::wstring& val);
|
||||
plGeneric& operator=(const plString& val);
|
||||
|
||||
// the cast functions will NOT cast from one type to another, use
|
||||
// GetType() to determine the type of parameter, then cast it to that type
|
||||
@ -91,8 +85,7 @@ public:
|
||||
operator bool() const {return fBoolVal;}
|
||||
operator int() const {return fIntVal;}
|
||||
operator double() const {return fFloatVal;}
|
||||
operator const wchar_t*() const {return fStringVal.c_str();}
|
||||
operator std::wstring() const {return fStringVal;}
|
||||
operator plString() const {return fStringVal;}
|
||||
|
||||
int Write(hsStream* stream);
|
||||
int Read(hsStream* stream);
|
||||
|
@ -46,16 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "HeadSpin.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/* NOTE & TODO:
|
||||
* These macros are intentionally annoyingly named, to mark what code
|
||||
* needs to be cleaned up after a larger portion of Plasma is converted
|
||||
* to plString.
|
||||
*/
|
||||
#define _TEMP_CONVERT_FROM_LITERAL(x) plString::FromUtf8((x))
|
||||
#define _TEMP_CONVERT_FROM_WCHAR_T(x) plString::FromWchar((x))
|
||||
#define _TEMP_CONVERT_TO_CONST_CHAR(x) ((x).c_str())
|
||||
#define _TEMP_CONVERT_TO_WCHAR_T(x) ((x).ToWchar().GetData())
|
||||
|
||||
typedef unsigned int UniChar;
|
||||
|
||||
#define SSO_CHARS (16)
|
||||
@ -173,13 +163,15 @@ private:
|
||||
public:
|
||||
plString() { }
|
||||
|
||||
//plString(const char *utf8) { IConvertFromUtf8(utf8, kSizeAuto, false); }
|
||||
//plString(const wchar_t *wstr) { IConvertFromWchar(wstr, kSizeAuto); }
|
||||
#ifndef PLSTRING_POLLUTE_ASCII_CAST
|
||||
plString(const char *ascii) { IConvertFromUtf8(ascii, kSizeAuto); }
|
||||
#endif
|
||||
plString(const plString ©) : fUtf8Buffer(copy.fUtf8Buffer) { }
|
||||
plString(const plStringBuffer<char> &init) { operator=(init); }
|
||||
|
||||
//plString &operator=(const char *utf8) { IConvertFromUtf8(utf8, kSizeAuto, false); return *this; }
|
||||
//plString &operator=(const wchar_t *wstr) { IConvertFromWchar(wstr, kSizeAuto); return *this; }
|
||||
#ifndef PLSTRING_POLLUTE_ASCII_CAST
|
||||
plString &operator=(const char *ascii) { IConvertFromUtf8(ascii, kSizeAuto); return *this; }
|
||||
#endif
|
||||
plString &operator=(const plString ©) { fUtf8Buffer = copy.fUtf8Buffer; return *this; }
|
||||
plString &operator=(const plStringBuffer<char> &init);
|
||||
|
||||
@ -213,8 +205,10 @@ public:
|
||||
return str;
|
||||
}
|
||||
|
||||
#ifndef PLSTRING_POLLUTE_C_STR
|
||||
const char *c_str(const char *substitute = "") const
|
||||
{ return IsEmpty() ? substitute : fUtf8Buffer.GetData(); }
|
||||
#endif
|
||||
|
||||
char CharAt(size_t position) const { return c_str()[position]; }
|
||||
|
||||
|
Reference in New Issue
Block a user