Browse Source

Rename UniChar to plUniChar to avoid conflict on OSX.

OSX defines a UniChar type as part of the OS headers.
Darryl Pogue 10 years ago committed by Darryl Pogue
parent
commit
95c52c0912
  1. 20
      Sources/Plasma/CoreLib/plString.cpp
  2. 12
      Sources/Plasma/CoreLib/plString.h
  3. 2
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

20
Sources/Plasma/CoreLib/plString.cpp

@ -168,7 +168,7 @@ void plString::IConvertFromUtf16(const uint16_t *utf16, size_t size)
while (sp < utf16 + size) { while (sp < utf16 + size) {
if (*sp >= 0xD800 && *sp <= 0xDFFF) { if (*sp >= 0xD800 && *sp <= 0xDFFF) {
// Surrogate pair // Surrogate pair
UniChar unichar = 0x10000; plUniChar unichar = 0x10000;
if (sp + 1 >= utf16 + size) { if (sp + 1 >= utf16 + size) {
hsAssert(0, "Incomplete surrogate pair in UTF-16 data"); hsAssert(0, "Incomplete surrogate pair in UTF-16 data");
@ -209,11 +209,11 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
// 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_t *)wstr, size); IConvertFromUtf16((const uint16_t *)wstr, size);
#else #else
IConvertFromUtf32((const UniChar *)wstr, size); IConvertFromUtf32((const plUniChar *)wstr, size);
#endif #endif
} }
void plString::IConvertFromUtf32(const UniChar *ustr, size_t size) void plString::IConvertFromUtf32(const plUniChar *ustr, size_t size)
{ {
hsAssert(size == STRLEN_AUTO || size < FREAKING_BIG, "Your string is WAAAAAY too big"); hsAssert(size == STRLEN_AUTO || size < FREAKING_BIG, "Your string is WAAAAAY too big");
@ -226,7 +226,7 @@ void plString::IConvertFromUtf32(const UniChar *ustr, size_t size)
// Calculate the UTF-8 size // Calculate the UTF-8 size
size_t convlen = 0; size_t convlen = 0;
const UniChar *sp = ustr; const plUniChar *sp = ustr;
while (sp < ustr + size) { while (sp < ustr + size) {
if (*sp > 0x10FFFF) { if (*sp > 0x10FFFF) {
hsAssert(0, "UTF-32 character out of range"); hsAssert(0, "UTF-32 character out of range");
@ -341,7 +341,7 @@ plStringBuffer<uint16_t> plString::ToUtf16() const
uint16_t *dp = ustr; uint16_t *dp = ustr;
sp = utf8; sp = utf8;
while (sp < utf8 + srcSize) { while (sp < utf8 + srcSize) {
UniChar unichar; plUniChar unichar;
if ((*sp & 0xF8) == 0xF0) { if ((*sp & 0xF8) == 0xF0) {
unichar = (*sp++ & 0x07) << 18; unichar = (*sp++ & 0x07) << 18;
unichar |= (*sp++ & 0x3F) << 12; unichar |= (*sp++ & 0x3F) << 12;
@ -408,7 +408,7 @@ plStringBuffer<char> plString::ToIso8859_1() const
char *dp = astr; char *dp = astr;
sp = utf8; sp = utf8;
while (sp < utf8 + srcSize) { while (sp < utf8 + srcSize) {
UniChar unichar; plUniChar unichar;
if ((*sp & 0xF8) == 0xF0) { if ((*sp & 0xF8) == 0xF0) {
unichar = (*sp++ & 0x07) << 18; unichar = (*sp++ & 0x07) << 18;
unichar |= (*sp++ & 0x3F) << 12; unichar |= (*sp++ & 0x3F) << 12;
@ -455,11 +455,11 @@ plUnicodeBuffer plString::GetUnicodeArray() const
} }
// And perform the actual conversion // And perform the actual conversion
UniChar *ustr = result.CreateWritableBuffer(convlen); plUniChar *ustr = result.CreateWritableBuffer(convlen);
UniChar *dp = ustr; plUniChar *dp = ustr;
sp = utf8; sp = utf8;
while (sp < utf8 + srcSize) { while (sp < utf8 + srcSize) {
UniChar unichar; plUniChar unichar;
if ((*sp & 0xF8) == 0xF0) { if ((*sp & 0xF8) == 0xF0) {
unichar = (*sp++ & 0x07) << 18; unichar = (*sp++ & 0x07) << 18;
unichar |= (*sp++ & 0x3F) << 12; unichar |= (*sp++ & 0x3F) << 12;
@ -942,7 +942,7 @@ plStringStream &plStringStream::operator<<(double num)
return operator<<(buffer); return operator<<(buffer);
} }
size_t ustrlen(const UniChar *ustr) size_t ustrlen(const plUniChar *ustr)
{ {
size_t length = 0; size_t length = 0;
for ( ; *ustr++; ++length) for ( ; *ustr++; ++length)

12
Sources/Plasma/CoreLib/plString.h

@ -47,7 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <vector> #include <vector>
/** Single Unicode character code unit */ /** Single Unicode character code unit */
typedef unsigned int UniChar; typedef unsigned int plUniChar;
#define SSO_CHARS (16) #define SSO_CHARS (16)
#define STRING_STACK_SIZE (256) #define STRING_STACK_SIZE (256)
@ -227,7 +227,7 @@ public:
}; };
/** A plStringBuffer for storing fully-expanded Unicode data */ /** A plStringBuffer for storing fully-expanded Unicode data */
typedef plStringBuffer<UniChar> plUnicodeBuffer; typedef plStringBuffer<plUniChar> plUnicodeBuffer;
/** Unicode-capable and (mostly) binary safe string class. /** Unicode-capable and (mostly) binary safe string class.
* plString stores SSO-optimized or reference counted strings (automatically * plString stores SSO-optimized or reference counted strings (automatically
@ -251,7 +251,7 @@ private:
void IConvertFromUtf8(const char *utf8, size_t size); void IConvertFromUtf8(const char *utf8, size_t size);
void IConvertFromUtf16(const uint16_t *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 IConvertFromUtf32(const UniChar *ustr, size_t size); void IConvertFromUtf32(const plUniChar *ustr, size_t size);
void IConvertFromIso8859_1(const char *astr, size_t size); void IConvertFromIso8859_1(const char *astr, size_t size);
public: public:
@ -357,7 +357,7 @@ public:
} }
/** Create a new plString object from the UTF-32 formatted data in \a utf32. */ /** Create a new plString object from the UTF-32 formatted data in \a utf32. */
static inline plString FromUtf32(const UniChar *utf32, size_t size = STRLEN_AUTO) static inline plString FromUtf32(const plUniChar *utf32, size_t size = STRLEN_AUTO)
{ {
plString str; plString str;
str.IConvertFromUtf32(utf32, size); str.IConvertFromUtf32(utf32, size);
@ -799,7 +799,7 @@ private:
bool ICanHasHeap() const { return fBufSize > STRING_STACK_SIZE; } bool ICanHasHeap() const { return fBufSize > STRING_STACK_SIZE; }
}; };
/** \p strlen implementation for UniChar based C-style string buffers. */ /** \p strlen implementation for plUniChar based C-style string buffers. */
size_t ustrlen(const UniChar *ustr); size_t ustrlen(const plUniChar *ustr);
#endif //plString_Defined #endif //plString_Defined

2
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

@ -54,7 +54,7 @@ plString PyString_AsStringEx(PyObject* obj)
#if (Py_UNICODE_SIZE == 2) #if (Py_UNICODE_SIZE == 2)
return plString::FromUtf16(reinterpret_cast<const uint16_t *>(PyUnicode_AsUnicode(obj))); return plString::FromUtf16(reinterpret_cast<const uint16_t *>(PyUnicode_AsUnicode(obj)));
#elif (Py_UNICODE_SIZE == 4) #elif (Py_UNICODE_SIZE == 4)
return plString::FromUtf32(reinterpret_cast<const UniChar *>(PyUnicode_AsUnicode(obj))); return plString::FromUtf32(reinterpret_cast<const plUniChar *>(PyUnicode_AsUnicode(obj)));
#else #else
# error "Py_UNICODE is an unexpected size" # error "Py_UNICODE is an unexpected size"
#endif #endif

Loading…
Cancel
Save