#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#ifdef _WIN32
+#define __BYTE_ORDER 0
+#define __LITTLE_ENDIAN 0
+#define __BIG_ENDIAN 1
+#elif defined(__MACH__) && defined(__APPLE__)
+#include <machine/endian.h>
+#elif defined(__FreeBSD__)
+#include <sys/endian.h>
+#else
+#include <endian.h>
+#endif
#ifdef USTRING_CPP0X
# include <utility>
case EUTFE_UTF32_LE:
COPY_ARRAY(BOM_ENCODE_UTF32_LE, BOM_ENCODE_UTF32_LEN);
break;
+ case EUTFE_NONE:
+ // TODO sapier: fixed warning only,
+ // don't know if something needs to be done here
+ break;
}
return ret;
_set(c);
return *this;
}
-
+
//! Increments the value by 1.
//! \return Myself.
_ustring16_iterator_access& operator++()
return unicode::toUTF32(a[pos], a[pos + 1]);
}
}
-
+
//! Sets a uchar32_t at our current position.
void _set(uchar32_t c)
{
//! Moves the iterator to the end of the string.
void toEnd()
{
- const uchar16_t* a = ref->c_str();
pos = ref->size_raw();
}
typedef typename _Base::const_pointer const_pointer;
typedef typename _Base::const_reference const_reference;
+
typedef typename _Base::value_type value_type;
typedef typename _Base::difference_type difference_type;
typedef typename _Base::distance_type distance_type;
typedef access pointer;
typedef access reference;
-
+
using _Base::pos;
using _Base::ref;
ustring16()
: array(0), allocated(1), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const ustring16<TAlloc>& other)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const string<B, A>& other)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const std::basic_string<B, A, Alloc>& other)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(Itr first, Itr last)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const char* const c)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const char* const c, u32 length)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const uchar8_t* const c)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const char c)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const uchar8_t* const c, u32 length)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const uchar16_t* const c)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const uchar16_t* const c, u32 length)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const uchar32_t* const c)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const uchar32_t* const c, u32 length)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const wchar_t* const c)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
ustring16(const wchar_t* const c, u32 length)
: array(0), allocated(0), used(0)
{
-#if __BIG_ENDIAN__
+#if __BYTE_ORDER == __BIG_ENDIAN
encoding = unicode::EUTFE_UTF16_BE;
#else
encoding = unicode::EUTFE_UTF16_LE;
}
#endif
-
+
//! Appends a number to this ustring16.
//! \param c Number to append.
//! \return A reference to our current string.
if (endian != unicode::EUTFEE_NATIVE && getEndianness() != endian)
{
for (u32 i = 0; i <= used; ++i)
- *ptr++ = unicode::swapEndian16(*ptr);
+ ptr[i] = unicode::swapEndian16(ptr[i]);
}
ret.set_used(used + (addBOM ? unicode::BOM_UTF16_LEN : 0));
ret.push_back(0);
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const short left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const unsigned short left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const int left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const unsigned int left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const long left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const unsigned long left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const float left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}
template <typename TAlloc>
inline ustring16<TAlloc> operator+(const double left, const ustring16<TAlloc>& right)
{
- ustring16<TAlloc> ret(core::stringc(left));
+ ustring16<TAlloc> ret((core::stringc(left)));
ret += right;
return ret;
}