/*
Basic Unicode string class for Irrlicht.
Copyright (c) 2009-2011 John Norman
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
The original version of this class can be located at:
http://irrlicht.suckerfreegames.com/
John Norman
john@suckerfreegames.com
*/
#pragma once
#if (__cplusplus > 199711L) || (_MSC_VER >= 1600) || defined(__GXX_EXPERIMENTAL_CXX0X__)
# define USTRING_CPP0X
# if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)))
# define USTRING_CPP0X_NEWLITERALS
# endif
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstddef>
#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__) || defined(__DragonFly__)
#include <sys/endian.h>
#else
#include <endian.h>
#endif
#ifdef USTRING_CPP0X
# include <utility>
#endif
#ifndef USTRING_NO_STL
# include <string>
# include <iterator>
# include <ostream>
#endif
#include "irrTypes.h"
#include "irrAllocator.h"
#include "irrArray.h"
#include "irrMath.h"
#include "irrString.h"
#include "path.h"
//! UTF-16 surrogate start values.
static const irr::u16 UTF16_HI_SURROGATE = 0xD800;
static const irr::u16 UTF16_LO_SURROGATE = 0xDC00;
//! Is a UTF-16 code point a surrogate?
#define UTF16_IS_SURROGATE(c) (((c) & 0xF800) == 0xD800)
#define UTF16_IS_SURROGATE_HI(c) (((c) & 0xFC00) == 0xD800)
#define UTF16_IS_SURROGATE_LO(c) (((c) & 0xFC00) == 0xDC00)
namespace irr
{
// Define our character types.
#ifdef USTRING_CPP0X_NEWLITERALS // C++0x
typedef char32_t uchar32_t;
typedef char16_t uchar16_t;
typedef char uchar8_t;
#else
typedef u32 uchar32_t;
typedef u16 uchar16_t;
typedef u8 uchar8_t;
#endif
namespace core
{
namespace unicode
{
//! The unicode replacement character. Used to replace invalid characters.
const irr::u16 UTF_REPLACEMENT_CHARACTER = 0xFFFD;
//! Convert a UTF-16 surrogate pair into a UTF-32 character.
//! \param high The high value of the pair.
//! \param low The low value of the pair.
//! \return The UTF-32 character expressed by the surrogate pair.
inline uchar32_t toUTF32(uchar16_t high, uchar16_t low)
{
// Convert the surrogate pair into a single UTF-32 character.
|