Browse Source

Fix the plString stuff that didn't get caught in the merge

Michael Hansen 13 years ago
parent
commit
77a31686da
  1. 8
      Sources/Plasma/CoreLib/hsStream.cpp
  2. 40
      Sources/Plasma/CoreLib/plString.cpp
  3. 9
      Sources/Plasma/CoreLib/plString.h
  4. 12
      Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp

8
Sources/Plasma/CoreLib/hsStream.cpp

@ -322,18 +322,18 @@ wchar_t *hsStream::ReadSafeWString()
return retVal; return retVal;
} }
UInt32 hsStream::WriteSafeString_TEMP(const plString &string) uint32_t hsStream::WriteSafeString_TEMP(const plString &string)
{ {
return WriteSafeString(string.c_str()); return WriteSafeString(string.c_str());
} }
UInt32 hsStream::WriteSafeWString_TEMP(const plString &string) uint32_t hsStream::WriteSafeWString_TEMP(const plString &string)
{ {
plStringBuffer<wchar_t> wbuffer = string.ToWchar(); plStringBuffer<wchar_t> wbuffer = string.ToWchar();
return WriteSafeWString(wbuffer.GetData()); return WriteSafeWString(wbuffer.GetData());
} }
plString hsStream::ReadSafeString_TEMP() plString hsStream::ReadSafeString_TEMP()
{ {
char *buffer = ReadSafeString(); char *buffer = ReadSafeString();
plString result = plString::FromIso8859_1(buffer); plString result = plString::FromIso8859_1(buffer);
@ -341,7 +341,7 @@ plString hsStream::ReadSafeString_TEMP()
return result; return result;
} }
plString hsStream::ReadSafeWString_TEMP() plString hsStream::ReadSafeWString_TEMP()
{ {
wchar_t *wbuffer = ReadSafeWString(); wchar_t *wbuffer = ReadSafeWString();
plString result = plString::FromWchar(wbuffer); plString result = plString::FromWchar(wbuffer);

40
Sources/Plasma/CoreLib/plString.cpp

@ -38,7 +38,7 @@ const plString plString::Null;
#if WCHAR_BYTES == 2 #if WCHAR_BYTES == 2
#define u16slen(str, max) wcsnlen((const wchar_t *)(str), (max)) #define u16slen(str, max) wcsnlen((const wchar_t *)(str), (max))
#else #else
static inline size_t u16slen(const UInt16 *ustr, size_t max) static inline size_t u16slen(const uint16_t *ustr, size_t max)
{ {
size_t length = 0; size_t length = 0;
for ( ; *ustr++ && max--; ++length) for ( ; *ustr++ && max--; ++length)
@ -83,14 +83,14 @@ void plString::IConvertFromUtf8(const char *utf8, size_t size, bool steal)
: plStringBuffer<char>(utf8, size); : plStringBuffer<char>(utf8, size);
} }
void plString::IConvertFromUtf16(const UInt16 *utf16, size_t size) void plString::IConvertFromUtf16(const uint16_t *utf16, size_t size)
{ {
if ((long)size < 0) if ((long)size < 0)
size = u16slen(utf16, -(long)size); size = u16slen(utf16, -(long)size);
// Calculate the UTF-8 size // Calculate the UTF-8 size
size_t convlen = 0; size_t convlen = 0;
const UInt16 *sp = utf16; const uint16_t *sp = utf16;
while (sp < utf16 + size) { while (sp < utf16 + size) {
if (*sp >= 0xD800 && *sp <= 0xDFFF) { if (*sp >= 0xD800 && *sp <= 0xDFFF) {
// Surrogate pair // Surrogate pair
@ -107,7 +107,7 @@ void plString::IConvertFromUtf16(const UInt16 *utf16, size_t size)
} }
// And perform the actual conversion // And perform the actual conversion
char *utf8 = TRACKED_NEW char[convlen + 1]; char *utf8 = new char[convlen + 1];
char *dp = utf8; char *dp = utf8;
sp = utf16; sp = utf16;
while (sp < utf16 + size) { while (sp < utf16 + size) {
@ -154,7 +154,7 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
{ {
#if WCHAR_BYTES == 2 #if WCHAR_BYTES == 2
// We assume that if sizeof(wchar_t) == 2, the data is UTF-16 already // We assume that if sizeof(wchar_t) == 2, the data is UTF-16 already
IConvertFromUtf16((const UInt16 *)wstr, size); IConvertFromUtf16((const uint16_t *)wstr, size);
#else #else
if ((long)size < 0) if ((long)size < 0)
size = wcsnlen(wstr, -(long)size); size = wcsnlen(wstr, -(long)size);
@ -179,7 +179,7 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
} }
// And perform the actual conversion // And perform the actual conversion
char *utf8 = TRACKED_NEW char[convlen + 1]; char *utf8 = new char[convlen + 1];
char *dp = utf8; char *dp = utf8;
sp = wstr; sp = wstr;
while (sp < wstr + size) { while (sp < wstr + size) {
@ -227,7 +227,7 @@ void plString::IConvertFromIso8859_1(const char *astr, size_t size)
} }
// And perform the actual conversion // And perform the actual conversion
char *utf8 = TRACKED_NEW char[convlen + 1]; char *utf8 = new char[convlen + 1];
char *dp = utf8; char *dp = utf8;
sp = astr; sp = astr;
while (sp < astr + size) { while (sp < astr + size) {
@ -244,10 +244,10 @@ void plString::IConvertFromIso8859_1(const char *astr, size_t size)
fUtf8Buffer = plStringBuffer<char>::Steal(utf8, convlen); fUtf8Buffer = plStringBuffer<char>::Steal(utf8, convlen);
} }
plStringBuffer<UInt16> plString::ToUtf16() const plStringBuffer<uint16_t> plString::ToUtf16() const
{ {
if (IsNull()) if (IsNull())
return plStringBuffer<UInt16>(); return plStringBuffer<uint16_t>();
// Calculate the UTF-16 size // Calculate the UTF-16 size
size_t convlen = 0; size_t convlen = 0;
@ -270,8 +270,8 @@ plStringBuffer<UInt16> plString::ToUtf16() const
} }
// And perform the actual conversion // And perform the actual conversion
UInt16 *ustr = TRACKED_NEW UInt16[convlen + 1]; uint16_t *ustr = new uint16_t[convlen + 1];
UInt16 *dp = ustr; uint16_t *dp = ustr;
sp = utf8; sp = utf8;
while (sp < utf8 + srcSize) { while (sp < utf8 + srcSize) {
unsigned int unichar; unsigned int unichar;
@ -298,14 +298,14 @@ plStringBuffer<UInt16> plString::ToUtf16() const
} }
ustr[convlen] = 0; ustr[convlen] = 0;
return plStringBuffer<UInt16>::Steal(ustr, convlen); return plStringBuffer<uint16_t>::Steal(ustr, convlen);
} }
plStringBuffer<wchar_t> plString::ToWchar() const plStringBuffer<wchar_t> plString::ToWchar() const
{ {
#if WCHAR_BYTES == 2 #if WCHAR_BYTES == 2
// We assume that if sizeof(wchar_t) == 2, the data is UTF-16 already // We assume that if sizeof(wchar_t) == 2, the data is UTF-16 already
plStringBuffer<UInt16> utf16 = ToUtf16(); plStringBuffer<uint16_t> utf16 = ToUtf16();
return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf16); return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf16);
#else #else
if (IsNull()) if (IsNull())
@ -329,7 +329,7 @@ plStringBuffer<wchar_t> plString::ToWchar() const
} }
// And perform the actual conversion // And perform the actual conversion
wchar_t *wstr = TRACKED_NEW wchar_t[convlen + 1]; wchar_t *wstr = new wchar_t[convlen + 1];
wchar_t *dp = wstr; wchar_t *dp = wstr;
sp = utf8; sp = utf8;
while (sp < utf8 + srcSize) { while (sp < utf8 + srcSize) {
@ -380,7 +380,7 @@ plStringBuffer<char> plString::ToIso8859_1() const
} }
// And perform the actual conversion // And perform the actual conversion
char *astr = TRACKED_NEW char[convlen + 1]; char *astr = new char[convlen + 1];
char *dp = astr; char *dp = astr;
sp = utf8; sp = utf8;
while (sp < utf8 + srcSize) { while (sp < utf8 + srcSize) {
@ -463,7 +463,7 @@ plString plString::IFormat(const char *fmt, va_list vptr)
int size = 4096; int size = 4096;
for ( ;; ) { for ( ;; ) {
va_copy(vptr, vptr_save); va_copy(vptr, vptr_save);
char *bigbuffer = TRACKED_NEW char[size]; char *bigbuffer = new char[size];
chars = vsnprintf(bigbuffer, size, fmt, vptr); chars = vsnprintf(bigbuffer, size, fmt, vptr);
if (chars >= 0) if (chars >= 0)
return plString::Steal(bigbuffer); return plString::Steal(bigbuffer);
@ -473,7 +473,7 @@ plString plString::IFormat(const char *fmt, va_list vptr)
} }
} else if (chars >= 256) { } else if (chars >= 256) {
va_copy(vptr, vptr_save); va_copy(vptr, vptr_save);
char *bigbuffer = TRACKED_NEW char[chars+1]; char *bigbuffer = new char[chars+1];
vsnprintf(bigbuffer, chars+1, fmt, vptr); vsnprintf(bigbuffer, chars+1, fmt, vptr);
return plString::Steal(bigbuffer); return plString::Steal(bigbuffer);
} }
@ -611,7 +611,7 @@ plString plString::Substr(int start, size_t size) const
if (start == 0 && size == maxSize) if (start == 0 && size == maxSize)
return *this; return *this;
char *substr = TRACKED_NEW char[size + 1]; char *substr = new char[size + 1];
memcpy(substr, c_str() + start, size); memcpy(substr, c_str() + start, size);
substr[size] = 0; substr[size] = 0;
@ -624,7 +624,7 @@ plString plString::Substr(int start, size_t size) const
plString &plString::operator+=(const plString &str) plString &plString::operator+=(const plString &str)
{ {
size_t catsize = GetSize() + str.GetSize(); size_t catsize = GetSize() + str.GetSize();
char *catstr = TRACKED_NEW char[catsize + 1]; char *catstr = new char[catsize + 1];
memcpy(catstr, s_str(), GetSize()); memcpy(catstr, s_str(), GetSize());
memcpy(catstr + GetSize(), str.s_str(), str.GetSize()); memcpy(catstr + GetSize(), str.s_str(), str.GetSize());
catstr[catsize] = 0; catstr[catsize] = 0;
@ -635,7 +635,7 @@ plString &plString::operator+=(const plString &str)
plString operator+(const plString &left, const plString &right) plString operator+(const plString &left, const plString &right)
{ {
size_t catsize = left.GetSize() + right.GetSize(); size_t catsize = left.GetSize() + right.GetSize();
char *catstr = TRACKED_NEW char[catsize + 1]; char *catstr = new char[catsize + 1];
memcpy(catstr, left.s_str(), left.GetSize()); memcpy(catstr, left.s_str(), left.GetSize());
memcpy(catstr + left.GetSize(), right.s_str(), right.GetSize()); memcpy(catstr + left.GetSize(), right.s_str(), right.GetSize());
catstr[catsize] = 0; catstr[catsize] = 0;

9
Sources/Plasma/CoreLib/plString.h

@ -27,8 +27,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plString_Defined #ifndef plString_Defined
#define plString_Defined #define plString_Defined
#include "hsTypes.h" #include "HeadSpin.h"
#include "hsUtils.h"
#include <stddef.h> #include <stddef.h>
#include <vector> #include <vector>
#include <functional> #include <functional>
@ -133,7 +132,7 @@ private:
plStringBuffer<char> fUtf8Buffer; plStringBuffer<char> fUtf8Buffer;
void IConvertFromUtf8(const char *utf8, size_t size, bool steal); void IConvertFromUtf8(const char *utf8, size_t size, bool steal);
void IConvertFromUtf16(const UInt16 *utf16, size_t size); void IConvertFromUtf16(const uint16_t *utf16, size_t size);
void IConvertFromWchar(const wchar_t *wstr, size_t size); void IConvertFromWchar(const wchar_t *wstr, size_t size);
void IConvertFromIso8859_1(const char *astr, size_t size); void IConvertFromIso8859_1(const char *astr, size_t size);
@ -157,7 +156,7 @@ public:
return str; return str;
} }
static inline plString FromUtf16(const UInt16 *utf16, size_t size = kSizeAuto) static inline plString FromUtf16(const uint16_t *utf16, size_t size = kSizeAuto)
{ {
plString str; plString str;
str.IConvertFromUtf16(utf16, size); str.IConvertFromUtf16(utf16, size);
@ -183,7 +182,7 @@ public:
char CharAt(size_t position) const { return c_str()[position]; } char CharAt(size_t position) const { return c_str()[position]; }
plStringBuffer<char> ToUtf8() const { return fUtf8Buffer; } plStringBuffer<char> ToUtf8() const { return fUtf8Buffer; }
plStringBuffer<UInt16> ToUtf16() const; plStringBuffer<uint16_t> ToUtf16() const;
plStringBuffer<wchar_t> ToWchar() const; plStringBuffer<wchar_t> ToWchar() const;
plStringBuffer<char> ToIso8859_1() const; plStringBuffer<char> ToIso8859_1() const;

12
Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp

@ -256,13 +256,13 @@ int plMsgStdStringHelper::PokeBig(const char * buf, uint32_t bufsz, hsStream* st
return stream->GetPosition(); return stream->GetPosition();
} }
int plMsgStdStringHelper::Poke(const plString & stringref, hsStream* stream, const UInt32 peekOptions) int plMsgStdStringHelper::Poke(const plString & stringref, hsStream* stream, const uint32_t peekOptions)
{ {
std::string temp = stringref.c_str(); std::string temp = stringref.c_str();
return Poke(temp, stream, peekOptions); return Poke(temp, stream, peekOptions);
} }
int plMsgStdStringHelper::PokeBig(const plString & stringref, hsStream* stream, const UInt32 peekOptions) int plMsgStdStringHelper::PokeBig(const plString & stringref, hsStream* stream, const uint32_t peekOptions)
{ {
std::string temp = stringref.c_str(); std::string temp = stringref.c_str();
return PokeBig(temp, stream, peekOptions); return PokeBig(temp, stream, peekOptions);
@ -313,7 +313,7 @@ int plMsgStdStringHelper::PeekBig(std::string & stringref, hsStream* stream, co
return stream->GetPosition(); return stream->GetPosition();
} }
int plMsgStdStringHelper::Peek(plString & stringref, hsStream* stream, const UInt32 peekOptions) int plMsgStdStringHelper::Peek(plString & stringref, hsStream* stream, const uint32_t peekOptions)
{ {
std::string temp; std::string temp;
int pos = Peek(temp, stream, peekOptions); int pos = Peek(temp, stream, peekOptions);
@ -321,7 +321,7 @@ int plMsgStdStringHelper::Peek(plString & stringref, hsStream* stream, const UIn
return pos; return pos;
} }
int plMsgStdStringHelper::PeekBig(plString & stringref, hsStream* stream, const UInt32 peekOptions) int plMsgStdStringHelper::PeekBig(plString & stringref, hsStream* stream, const uint32_t peekOptions)
{ {
std::string temp; std::string temp;
int pos = PeekBig(temp, stream, peekOptions); int pos = PeekBig(temp, stream, peekOptions);
@ -399,12 +399,12 @@ int plMsgCStringHelper::Peek(char *& str, hsStream* stream, const uint32_t peekO
return stream->GetPosition(); return stream->GetPosition();
} }
int plMsgCStringHelper::Poke(const plString & str, hsStream* stream, const UInt32 peekOptions) int plMsgCStringHelper::Poke(const plString & str, hsStream* stream, const uint32_t peekOptions)
{ {
return Poke(str.c_str(), stream, peekOptions); return Poke(str.c_str(), stream, peekOptions);
} }
int plMsgCStringHelper::Peek(plString & str, hsStream* stream, const UInt32 peekOptions) int plMsgCStringHelper::Peek(plString & str, hsStream* stream, const uint32_t peekOptions)
{ {
char * temp = nil; char * temp = nil;
int pos = Peek(temp, stream, peekOptions); int pos = Peek(temp, stream, peekOptions);

Loading…
Cancel
Save