diff --git a/include/eepp/core/allocator.hpp b/include/eepp/core/allocator.hpp index 4ac980f34..887353b37 100644 --- a/include/eepp/core/allocator.hpp +++ b/include/eepp/core/allocator.hpp @@ -7,7 +7,7 @@ namespace EE { template -class eeAllocator { +class Allocator { public: typedef T value_type; typedef T * pointer; @@ -17,13 +17,13 @@ class eeAllocator { typedef ptrdiff_t difference_type; typedef size_t size_type; - eeAllocator() { + Allocator() { } - eeAllocator( const eeAllocator& ) { + Allocator( const Allocator& ) { } - virtual ~eeAllocator() { + virtual ~Allocator() { } T * allocate( size_t cnt, typename std::allocator::const_pointer ptr = 0 ) { @@ -59,18 +59,18 @@ class eeAllocator { return &x; } - eeAllocator& operator=(const eeAllocator&) { return *this; } + Allocator& operator=(const Allocator&) { return *this; } template struct rebind { - typedef eeAllocator other; + typedef Allocator other; }; template - eeAllocator( const eeAllocator& ) {} + Allocator( const Allocator& ) {} template - eeAllocator& operator=(const eeAllocator&) { return *this; } + Allocator& operator=(const Allocator&) { return *this; } protected: }; diff --git a/include/eepp/core/memorymanager.hpp b/include/eepp/core/memorymanager.hpp index 2341fb70f..3dda9dd37 100644 --- a/include/eepp/core/memorymanager.hpp +++ b/include/eepp/core/memorymanager.hpp @@ -10,9 +10,9 @@ namespace EE { -class EE_API cAllocatedPointer { +class EE_API AllocatedPointer { public: - cAllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ); + AllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ); std::string mFile; int mLine; @@ -20,14 +20,14 @@ class EE_API cAllocatedPointer { void * mData; }; -typedef std::map tAllocatedPointerMap; -typedef tAllocatedPointerMap::iterator tAllocatedPointerMapIt; +typedef std::map AllocatedPointerMap; +typedef AllocatedPointerMap::iterator AllocatedPointerMapIt; class EE_API MemoryManager { public: - static void * AddPointer( const cAllocatedPointer& aAllocatedPointer ); + static void * AddPointer( const AllocatedPointer& aAllocatedPointer ); - static void * AddPointerInPlace( void * Place, const cAllocatedPointer& aAllocatedPointer ); + static void * AddPointerInPlace( void * Place, const AllocatedPointer& aAllocatedPointer ); static bool RemovePointer( void * Data ); @@ -59,21 +59,21 @@ class EE_API MemoryManager { static size_t GetTotalMemoryUsage(); - static const cAllocatedPointer& GetBiggestAllocation(); + static const AllocatedPointer& GetBiggestAllocation(); }; #ifdef EE_MEMORY_MANAGER #define eeNew( classType, constructor ) \ - ( classType *)EE::MemoryManager::AddPointer( EE::cAllocatedPointer( new classType constructor ,__FILE__,__LINE__, sizeof(classType) ) ) + ( classType *)EE::MemoryManager::AddPointer( EE::AllocatedPointer( new classType constructor ,__FILE__,__LINE__, sizeof(classType) ) ) #define eeNewInPlace( place, classType, constructor ) \ - ( classType *)EE::MemoryManager::AddPointerInPlace( place, EE::cAllocatedPointer( new place classType constructor ,__FILE__,__LINE__, sizeof(classType) ) ) + ( classType *)EE::MemoryManager::AddPointerInPlace( place, EE::AllocatedPointer( new place classType constructor ,__FILE__,__LINE__, sizeof(classType) ) ) #define eeNewArray( classType, amount ) \ - ( classType *) EE::MemoryManager::AddPointer( EE::cAllocatedPointer( new classType [ amount ], __FILE__, __LINE__, amount * sizeof( classType ) ) ) + ( classType *) EE::MemoryManager::AddPointer( EE::AllocatedPointer( new classType [ amount ], __FILE__, __LINE__, amount * sizeof( classType ) ) ) #define eeMalloc(amount) \ - EE::MemoryManager::AddPointer( EE::cAllocatedPointer( EE::MemoryManager::Allocate( amount ), __FILE__, __LINE__, amount ) ) + EE::MemoryManager::AddPointer( EE::AllocatedPointer( EE::MemoryManager::Allocate( amount ), __FILE__, __LINE__, amount ) ) #define eeDelete( data ){ \ if( EE::MemoryManager::RemovePointer( EE::MemoryManager::Delete( data ) ) == false ) printf( "Deleting at '%s' %d\n", __FILE__, __LINE__ ); \ diff --git a/include/eepp/core/stlcontainers.hpp b/include/eepp/core/stlcontainers.hpp index c0e1c3f80..00221f567 100644 --- a/include/eepp/core/stlcontainers.hpp +++ b/include/eepp/core/stlcontainers.hpp @@ -8,7 +8,7 @@ namespace EE { template > - struct eeStack { + struct Stack { #ifdef EE_MEMORY_MANAGER typedef typename std::stack type; #else @@ -17,7 +17,7 @@ namespace EE { }; template > - struct eeDeque { + struct Deque { #ifdef EE_MEMORY_MANAGER typedef typename std::deque type; #else @@ -26,7 +26,7 @@ namespace EE { }; template > - struct eeVector { + struct Vector { #ifdef EE_MEMORY_MANAGER typedef typename std::vector type; #else @@ -35,7 +35,7 @@ namespace EE { }; template > - struct eeList { + struct List { #ifdef EE_MEMORY_MANAGER typedef typename std::list type; #else @@ -44,7 +44,7 @@ namespace EE { }; template , typename A = eeAllocator > - struct eeSet { + struct Set { #ifdef EE_MEMORY_MANAGER typedef typename std::set type; #else @@ -53,7 +53,7 @@ namespace EE { }; template , typename A = eeAllocator< std::pair > > - struct eeMap { + struct Map { #ifdef EE_MEMORY_MANAGER typedef typename std::map type; #else @@ -62,7 +62,7 @@ namespace EE { }; template , typename A = eeAllocator< std::pair > > - struct eeMultimap { + struct Multimap { #ifdef EE_MEMORY_MANAGER typedef typename std::multimap type; #else diff --git a/include/eepp/core/utf.hpp b/include/eepp/core/utf.hpp index 428357485..f5eccfb39 100644 --- a/include/eepp/core/utf.hpp +++ b/include/eepp/core/utf.hpp @@ -11,12 +11,12 @@ // 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. +// 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. +// and must not be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. // @@ -48,204 +48,204 @@ class Utf; template <> class Utf<8> { public : - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-8 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-8 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-8 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-8 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-8 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-8. - /// - /// \param input Codepoint to encode as UTF-8 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out Encode(Uint32 input, Out output, Uint8 replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-8 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-8. + /// + /// \param input Codepoint to encode as UTF-8 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out Encode(Uint32 input, Out output, Uint8 replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-8 character - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In Next(In begin, In end); + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-8 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Next(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-8 sequence - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element, thus the - /// total size can be different from (begin - end). - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static std::size_t Count(In begin, In end); + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-8 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static std::size_t Count(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-8 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-8 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromLatin1(In begin, In end, Out output); + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); #ifndef EE_NO_WIDECHAR - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); #endif - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-8 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the EE::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf8(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-8 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the EE::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf8(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf16(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf16(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf32(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf32(In begin, In end, Out output); }; //////////////////////////////////////////////////////////// @@ -257,204 +257,204 @@ class Utf<16> { public : - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-16 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-16 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-16 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-16 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-16 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-16. - /// - /// \param input Codepoint to encode as UTF-16 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out Encode(Uint32 input, Out output, Uint16 replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-16 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-16. + /// + /// \param input Codepoint to encode as UTF-16 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out Encode(Uint32 input, Out output, Uint16 replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-16 character - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In Next(In begin, In end); + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-16 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Next(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-16 sequence - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element, thus the - /// total size can be different from (begin - end). - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static std::size_t Count(In begin, In end); + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-16 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static std::size_t Count(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-16 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-16 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromLatin1(In begin, In end, Out output); + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); #ifndef EE_NO_WIDECHAR - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); #endif - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf8(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf8(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-16 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the EE::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf16(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-16 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the EE::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf16(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf32(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf32(In begin, In end, Out output); }; //////////////////////////////////////////////////////////// @@ -466,272 +466,272 @@ class Utf<32> { public : - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-32 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// For UTF-32, the character value is the same as the codepoint. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-32 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-32 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// For UTF-32, the character value is the same as the codepoint. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-32 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-32. - /// For UTF-32, the codepoint is the same as the character value. - /// - /// \param input Codepoint to encode as UTF-32 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out Encode(Uint32 input, Out output, Uint32 replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-32. + /// For UTF-32, the codepoint is the same as the character value. + /// + /// \param input Codepoint to encode as UTF-32 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out Encode(Uint32 input, Out output, Uint32 replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-32 character - /// - /// This function is trivial for UTF-32, which can store - /// every character in a single storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In Next(In begin, In end); + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-32 character + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Next(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-32 sequence - /// - /// This function is trivial for UTF-32, which can store - /// every character in a single storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static std::size_t Count(In begin, In end); + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-32 sequence + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static std::size_t Count(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-32 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-32 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out FromLatin1(In begin, In end, Out output); + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-32 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); #ifndef EE_NO_WIDECHAR - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-32 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); #endif - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf8(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf8(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf16(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf16(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-32 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the EE::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out ToUtf32(In begin, In end, Out output); + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-32 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the EE::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf32(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Decode a single ANSI character to UTF-32 - /// - /// This function does not exist in other specializations - /// of EE::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param input Input ANSI character - /// \param locale Locale to use for conversion - /// - /// \return Converted character - /// - //////////////////////////////////////////////////////////// - template - static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale()); + //////////////////////////////////////////////////////////// + /// \brief Decode a single ANSI character to UTF-32 + /// + /// This function does not exist in other specializations + /// of EE::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input ANSI character + /// \param locale Locale to use for conversion + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template + static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale()); - //////////////////////////////////////////////////////////// - /// \brief Decode a single wide character to UTF-32 - /// - /// This function does not exist in other specializations - /// of EE::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param input Input wide character - /// - /// \return Converted character - /// - //////////////////////////////////////////////////////////// - template - static Uint32 DecodeWide(In input); + //////////////////////////////////////////////////////////// + /// \brief Decode a single wide character to UTF-32 + /// + /// This function does not exist in other specializations + /// of EE::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input wide character + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template + static Uint32 DecodeWide(In input); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character to ANSI - /// - /// This function does not exist in other specializations - /// of EE::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param codepoint Iterator pointing to the beginning of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to ANSI + /// + /// This function does not exist in other specializations + /// of EE::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); #ifndef EE_NO_WIDECHAR - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character to wide - /// - /// This function does not exist in other specializations - /// of EE::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param codepoint Iterator pointing to the beginning of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to wide + /// + /// This function does not exist in other specializations + /// of EE::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); #endif }; diff --git a/include/eepp/core/utf.inl b/include/eepp/core/utf.inl index 55bd4d370..6ede2def5 100644 --- a/include/eepp/core/utf.inl +++ b/include/eepp/core/utf.inl @@ -8,664 +8,664 @@ template In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement) { - // Some useful precomputed data - static const int trailing[256] = - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 - }; - static const Uint32 offsets[6] = - { - 0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080 - }; + // Some useful precomputed data + static const int trailing[256] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 + }; + static const Uint32 offsets[6] = + { + 0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080 + }; - // Decode the character - int trailingBytes = trailing[static_cast(*begin)]; - if (begin + trailingBytes < end) - { - output = 0; - switch (trailingBytes) - { - case 5 : output += static_cast(*begin++); output <<= 6; - case 4 : output += static_cast(*begin++); output <<= 6; - case 3 : output += static_cast(*begin++); output <<= 6; - case 2 : output += static_cast(*begin++); output <<= 6; - case 1 : output += static_cast(*begin++); output <<= 6; - case 0 : output += static_cast(*begin++); - } - output -= offsets[trailingBytes]; - } - else - { - // Incomplete character - begin = end; - output = replacement; - } + // Decode the character + int trailingBytes = trailing[static_cast(*begin)]; + if (begin + trailingBytes < end) + { + output = 0; + switch (trailingBytes) + { + case 5 : output += static_cast(*begin++); output <<= 6; + case 4 : output += static_cast(*begin++); output <<= 6; + case 3 : output += static_cast(*begin++); output <<= 6; + case 2 : output += static_cast(*begin++); output <<= 6; + case 1 : output += static_cast(*begin++); output <<= 6; + case 0 : output += static_cast(*begin++); + } + output -= offsets[trailingBytes]; + } + else + { + // Incomplete character + begin = end; + output = replacement; + } - return begin; + return begin; } template Out Utf<8>::Encode(Uint32 input, Out output, Uint8 replacement) { - // Some useful precomputed data - static const Uint8 firstBytes[7] = - { - 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC - }; + // Some useful precomputed data + static const Uint8 firstBytes[7] = + { + 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC + }; - // Encode the character - if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF))) - { - // Invalid character - if (replacement) - *output++ = replacement; - } - else - { - // Valid character + // Encode the character + if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF))) + { + // Invalid character + if (replacement) + *output++ = replacement; + } + else + { + // Valid character - // Get the number of bytes to write - int bytesToWrite = 1; - if (input < 0x80) bytesToWrite = 1; - else if (input < 0x800) bytesToWrite = 2; - else if (input < 0x10000) bytesToWrite = 3; - else if (input <= 0x0010FFFF) bytesToWrite = 4; + // Get the number of bytes to write + int bytesToWrite = 1; + if (input < 0x80) bytesToWrite = 1; + else if (input < 0x800) bytesToWrite = 2; + else if (input < 0x10000) bytesToWrite = 3; + else if (input <= 0x0010FFFF) bytesToWrite = 4; - // Extract the bytes to write - Uint8 bytes[4]; - switch (bytesToWrite) - { - case 4 : bytes[3] = static_cast((input | 0x80) & 0xBF); input >>= 6; - case 3 : bytes[2] = static_cast((input | 0x80) & 0xBF); input >>= 6; - case 2 : bytes[1] = static_cast((input | 0x80) & 0xBF); input >>= 6; - case 1 : bytes[0] = static_cast (input | firstBytes[bytesToWrite]); - } + // Extract the bytes to write + Uint8 bytes[4]; + switch (bytesToWrite) + { + case 4 : bytes[3] = static_cast((input | 0x80) & 0xBF); input >>= 6; + case 3 : bytes[2] = static_cast((input | 0x80) & 0xBF); input >>= 6; + case 2 : bytes[1] = static_cast((input | 0x80) & 0xBF); input >>= 6; + case 1 : bytes[0] = static_cast (input | firstBytes[bytesToWrite]); + } - // Add them to the output - const Uint8* currentByte = bytes; - switch (bytesToWrite) - { - case 4 : *output++ = *currentByte++; - case 3 : *output++ = *currentByte++; - case 2 : *output++ = *currentByte++; - case 1 : *output++ = *currentByte++; - } - } + // Add them to the output + const Uint8* currentByte = bytes; + switch (bytesToWrite) + { + case 4 : *output++ = *currentByte++; + case 3 : *output++ = *currentByte++; + case 2 : *output++ = *currentByte++; + case 1 : *output++ = *currentByte++; + } + } - return output; + return output; } template In Utf<8>::Next(In begin, In end) { - Uint32 codepoint; - return Decode(begin, end, codepoint); + Uint32 codepoint; + return Decode(begin, end, codepoint); } template std::size_t Utf<8>::Count(In begin, In end) { - std::size_t length = 0; - while (begin < end) - { - begin = Next(begin, end); - ++length; - } + std::size_t length = 0; + while (begin < end) + { + begin = Next(begin, end); + ++length; + } - return length; + return length; } template Out Utf<8>::FromAnsi(In begin, In end, Out output, const std::locale& locale) { - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); - output = Encode(codepoint, output); - } + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); + output = Encode(codepoint, output); + } - return output; + return output; } template Out Utf<8>::FromWide(In begin, In end, Out output) { - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeWide(*begin++); - output = Encode(codepoint, output); - } + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeWide(*begin++); + output = Encode(codepoint, output); + } - return output; + return output; } template Out Utf<8>::FromLatin1(In begin, In end, Out output) { - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - output = Encode(*begin++, output); + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + output = Encode(*begin++, output); - return output; + return output; } template Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); + } - return output; + return output; } #ifndef EE_NO_WIDECHAR template Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeWide(codepoint, output, replacement); - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeWide(codepoint, output, replacement); + } - return output; + return output; } #endif template Out Utf<8>::ToLatin1(In begin, In end, Out output, char replacement) { - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - *output++ = codepoint < 256 ? static_cast(codepoint) : replacement; - } + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint < 256 ? static_cast(codepoint) : replacement; + } - return output; + return output; } template Out Utf<8>::ToUtf8(In begin, In end, Out output) { - while (begin < end) - *output++ = *begin++; + while (begin < end) + *output++ = *begin++; - return output; + return output; } template Out Utf<8>::ToUtf16(In begin, In end, Out output) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<16>::Encode(codepoint, output); - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<16>::Encode(codepoint, output); + } - return output; + return output; } template Out Utf<8>::ToUtf32(In begin, In end, Out output) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - *output++ = codepoint; - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint; + } - return output; + return output; } template In Utf<16>::Decode(In begin, In end, Uint32& output, Uint32 replacement) { - Uint16 first = *begin++; + Uint16 first = *begin++; - // If it's a surrogate pair, first convert to a single UTF-32 character - if ((first >= 0xD800) && (first <= 0xDBFF)) - { - if (begin < end) - { - Uint32 second = *begin++; - if ((second >= 0xDC00) && (second <= 0xDFFF)) - { - // The second element is valid: convert the two elements to a UTF-32 character - output = static_cast(((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000); - } - else - { - // Invalid character - output = replacement; - } - } - else - { - // Invalid character - begin = end; - output = replacement; - } - } - else - { - // We can make a direct copy - output = first; - } + // If it's a surrogate pair, first convert to a single UTF-32 character + if ((first >= 0xD800) && (first <= 0xDBFF)) + { + if (begin < end) + { + Uint32 second = *begin++; + if ((second >= 0xDC00) && (second <= 0xDFFF)) + { + // The second element is valid: convert the two elements to a UTF-32 character + output = static_cast(((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000); + } + else + { + // Invalid character + output = replacement; + } + } + else + { + // Invalid character + begin = end; + output = replacement; + } + } + else + { + // We can make a direct copy + output = first; + } - return begin; + return begin; } template Out Utf<16>::Encode(Uint32 input, Out output, Uint16 replacement) { - if (input < 0xFFFF) - { - // The character can be copied directly, we just need to check if it's in the valid range - if ((input >= 0xD800) && (input <= 0xDFFF)) - { - // Invalid character (this range is reserved) - if (replacement) - *output++ = replacement; - } - else - { - // Valid character directly convertible to a single UTF-16 character - *output++ = static_cast(input); - } - } - else if (input > 0x0010FFFF) - { - // Invalid character (greater than the maximum unicode value) - if (replacement) - *output++ = replacement; - } - else - { - // The input character will be converted to two UTF-16 elements - input -= 0x0010000; - *output++ = static_cast((input >> 10) + 0xD800); - *output++ = static_cast((input & 0x3FFUL) + 0xDC00); - } + if (input < 0xFFFF) + { + // The character can be copied directly, we just need to check if it's in the valid range + if ((input >= 0xD800) && (input <= 0xDFFF)) + { + // Invalid character (this range is reserved) + if (replacement) + *output++ = replacement; + } + else + { + // Valid character directly convertible to a single UTF-16 character + *output++ = static_cast(input); + } + } + else if (input > 0x0010FFFF) + { + // Invalid character (greater than the maximum unicode value) + if (replacement) + *output++ = replacement; + } + else + { + // The input character will be converted to two UTF-16 elements + input -= 0x0010000; + *output++ = static_cast((input >> 10) + 0xD800); + *output++ = static_cast((input & 0x3FFUL) + 0xDC00); + } - return output; + return output; } template In Utf<16>::Next(In begin, In end) { - Uint32 codepoint; - return Decode(begin, end, codepoint); + Uint32 codepoint; + return Decode(begin, end, codepoint); } template std::size_t Utf<16>::Count(In begin, In end) { - std::size_t length = 0; - while (begin < end) - { - begin = Next(begin, end); - ++length; - } + std::size_t length = 0; + while (begin < end) + { + begin = Next(begin, end); + ++length; + } - return length; + return length; } template Out Utf<16>::FromAnsi(In begin, In end, Out output, const std::locale& locale) { - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); - output = Encode(codepoint, output); - } + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); + output = Encode(codepoint, output); + } - return output; + return output; } template Out Utf<16>::FromWide(In begin, In end, Out output) { - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeWide(*begin++); - output = Encode(codepoint, output); - } + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeWide(*begin++); + output = Encode(codepoint, output); + } - return output; + return output; } template Out Utf<16>::FromLatin1(In begin, In end, Out output) { - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - *output++ = *begin++; + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + *output++ = *begin++; - return output; + return output; } template Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); + } - return output; + return output; } #ifndef EE_NO_WIDECHAR template Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeWide(codepoint, output, replacement); - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeWide(codepoint, output, replacement); + } - return output; + return output; } #endif template Out Utf<16>::ToLatin1(In begin, In end, Out output, char replacement) { - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - { - *output++ = *begin < 256 ? static_cast(*begin) : replacement; - begin++; - } + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + *output++ = *begin < 256 ? static_cast(*begin) : replacement; + begin++; + } - return output; + return output; } template Out Utf<16>::ToUtf8(In begin, In end, Out output) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<8>::Encode(codepoint, output); - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<8>::Encode(codepoint, output); + } - return output; + return output; } template Out Utf<16>::ToUtf16(In begin, In end, Out output) { - while (begin < end) - *output++ = *begin++; + while (begin < end) + *output++ = *begin++; - return output; + return output; } template Out Utf<16>::ToUtf32(In begin, In end, Out output) { - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - *output++ = codepoint; - } + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint; + } - return output; + return output; } template In Utf<32>::Decode(In begin, In end, Uint32& output, Uint32) { - output = *begin++; - return begin; + output = *begin++; + return begin; } template Out Utf<32>::Encode(Uint32 input, Out output, Uint32 replacement) { - *output++ = input; - return output; + *output++ = input; + return output; } template In Utf<32>::Next(In begin, In end) { - return ++begin; + return ++begin; } template std::size_t Utf<32>::Count(In begin, In end) { - return begin - end; + return begin - end; } template Out Utf<32>::FromAnsi(In begin, In end, Out output, const std::locale& locale) { - while (begin < end) - *output++ = DecodeAnsi(*begin++, locale); + while (begin < end) + *output++ = DecodeAnsi(*begin++, locale); - return output; + return output; } template Out Utf<32>::FromWide(In begin, In end, Out output) { - while (begin < end) - *output++ = DecodeWide(*begin++); + while (begin < end) + *output++ = DecodeWide(*begin++); - return output; + return output; } template Out Utf<32>::FromLatin1(In begin, In end, Out output) { - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - *output++ = *begin++; + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + *output++ = *begin++; - return output; + return output; } template Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) { - while (begin < end) - output = EncodeAnsi(*begin++, output, replacement, locale); + while (begin < end) + output = EncodeAnsi(*begin++, output, replacement, locale); - return output; + return output; } #ifndef EE_NO_WIDECHAR template Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement) { - while (begin < end) - output = EncodeWide(*begin++, output, replacement); + while (begin < end) + output = EncodeWide(*begin++, output, replacement); - return output; + return output; } #endif template Out Utf<32>::ToLatin1(In begin, In end, Out output, char replacement) { - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - { - *output++ = *begin < 256 ? static_cast(*begin) : replacement; - begin++; - } + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + *output++ = *begin < 256 ? static_cast(*begin) : replacement; + begin++; + } - return output; + return output; } template Out Utf<32>::ToUtf8(In begin, In end, Out output) { - while (begin < end) - output = Utf<8>::Encode(*begin++, output); + while (begin < end) + output = Utf<8>::Encode(*begin++, output); - return output; + return output; } template Out Utf<32>::ToUtf16(In begin, In end, Out output) { - while (begin < end) - output = Utf<16>::Encode(*begin++, output); + while (begin < end) + output = Utf<16>::Encode(*begin++, output); - return output; + return output; } template Out Utf<32>::ToUtf32(In begin, In end, Out output) { - while (begin < end) - *output++ = *begin++; + while (begin < end) + *output++ = *begin++; - return output; + return output; } template Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale) { - // On Windows, gcc's standard library (glibc++) has almost - // no support for Unicode stuff. As a consequence, in this - // context we can only use the default locale and ignore - // the one passed as parameter. + // On Windows, gcc's standard library (glibc++) has almost + // no support for Unicode stuff. As a consequence, in this + // context we can only use the default locale and ignore + // the one passed as parameter. - #if EE_PLATFORM == EE_PLATFORM_WIN && /* if Windows ... */ \ - (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ - !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ + #if EE_PLATFORM == EE_PLATFORM_WIN && /* if Windows ... */ \ + (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ + !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ - wchar_t character = 0; - mbtowc(&character, &input, 1); - return static_cast(character); + wchar_t character = 0; + mbtowc(&character, &input, 1); + return static_cast(character); - #else - // Get the facet of the locale which deals with character conversion + #else + // Get the facet of the locale which deals with character conversion #ifndef EE_NO_WIDECHAR - const std::ctype& facet = std::use_facet< std::ctype >(locale); + const std::ctype& facet = std::use_facet< std::ctype >(locale); #else const std::ctype& facet = std::use_facet< std::ctype >(locale); #endif - // Use the facet to convert each character of the input string - return static_cast(facet.widen(input)); + // Use the facet to convert each character of the input string + return static_cast(facet.widen(input)); - #endif + #endif } template Uint32 Utf<32>::DecodeWide(In input) { - // The encoding of wide characters is not well defined and is left to the system; - // however we can safely assume that it is UCS-2 on Windows and - // UCS-4 on Unix systems. - // In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4, - // and UCS-4 *is* UTF-32). + // The encoding of wide characters is not well defined and is left to the system; + // however we can safely assume that it is UCS-2 on Windows and + // UCS-4 on Unix systems. + // In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4, + // and UCS-4 *is* UTF-32). - return input; + return input; } template Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale) { - // On Windows, gcc's standard library (glibc++) has almost - // no support for Unicode stuff. As a consequence, in this - // context we can only use the default locale and ignore - // the one passed as parameter. + // On Windows, gcc's standard library (glibc++) has almost + // no support for Unicode stuff. As a consequence, in this + // context we can only use the default locale and ignore + // the one passed as parameter. - #if EE_PLATFORM == EE_PLATFORM_WIN && /* if Windows ... */ \ - (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ - !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ + #if EE_PLATFORM == EE_PLATFORM_WIN && /* if Windows ... */ \ + (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ + !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ - char character = 0; - if (wctomb(&character, static_cast(codepoint)) >= 0) - *output++ = character; - else if (replacement) - *output++ = replacement; + char character = 0; + if (wctomb(&character, static_cast(codepoint)) >= 0) + *output++ = character; + else if (replacement) + *output++ = replacement; - return output; + return output; - #else - // Get the facet of the locale which deals with character conversion + #else + // Get the facet of the locale which deals with character conversion #ifndef EE_NO_WIDECHAR - const std::ctype& facet = std::use_facet< std::ctype >(locale); - #else - const std::ctype& facet = std::use_facet< std::ctype >(locale); - #endif + const std::ctype& facet = std::use_facet< std::ctype >(locale); + #else + const std::ctype& facet = std::use_facet< std::ctype >(locale); + #endif - // Use the facet to convert each character of the input string - *output++ = facet.narrow(static_cast(codepoint), replacement); + // Use the facet to convert each character of the input string + *output++ = facet.narrow(static_cast(codepoint), replacement); - return output; + return output; - #endif + #endif } #ifndef EE_NO_WIDECHAR template Out Utf<32>::EncodeWide(Uint32 codepoint, Out output, wchar_t replacement) { - // The encoding of wide characters is not well defined and is left to the system; - // however we can safely assume that it is UCS-2 on Windows and - // UCS-4 on Unix systems. - // For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4). - // For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32). + // The encoding of wide characters is not well defined and is left to the system; + // however we can safely assume that it is UCS-2 on Windows and + // UCS-4 on Unix systems. + // For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4). + // For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32). - switch (sizeof(wchar_t)) - { - case 4: - { - *output++ = static_cast(codepoint); - break; - } + switch (sizeof(wchar_t)) + { + case 4: + { + *output++ = static_cast(codepoint); + break; + } - default: - { - if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) - { - *output++ = static_cast(codepoint); - } - else if (replacement) - { - *output++ = replacement; - } - break; - } - } + default: + { + if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) + { + *output++ = static_cast(codepoint); + } + else if (replacement) + { + *output++ = replacement; + } + break; + } + } - return output; + return output; } #endif diff --git a/src/eepp/core/memorymanager.cpp b/src/eepp/core/memorymanager.cpp index 65ab1d61c..9181a9e4c 100644 --- a/src/eepp/core/memorymanager.cpp +++ b/src/eepp/core/memorymanager.cpp @@ -11,21 +11,21 @@ using namespace EE::System; namespace EE { -static tAllocatedPointerMap sMapPointers; +static AllocatedPointerMap sMapPointers; static size_t sTotalMemoryUsage = 0; static size_t sPeakMemoryUsage = 0; -static cAllocatedPointer sBiggestAllocation = cAllocatedPointer( NULL, "", 0, 0 ); +static AllocatedPointer sBiggestAllocation = AllocatedPointer( NULL, "", 0, 0 ); static cMutex sAllocMutex; -cAllocatedPointer::cAllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ) { +AllocatedPointer::AllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ) { mData = Data; mFile = File; mLine = Line; mMemory = Memory; } -void * MemoryManager::AddPointerInPlace( void * Place, const cAllocatedPointer& aAllocatedPointer ) { - tAllocatedPointerMapIt it = sMapPointers.find( Place ); +void * MemoryManager::AddPointerInPlace( void * Place, const AllocatedPointer& aAllocatedPointer ) { + AllocatedPointerMapIt it = sMapPointers.find( Place ); if ( it != sMapPointers.end() ) { RemovePointer( Place ); @@ -34,10 +34,10 @@ void * MemoryManager::AddPointerInPlace( void * Place, const cAllocatedPointer& return AddPointer( aAllocatedPointer ); } -void * MemoryManager::AddPointer( const cAllocatedPointer& aAllocatedPointer ) { +void * MemoryManager::AddPointer( const AllocatedPointer& aAllocatedPointer ) { cLock l( sAllocMutex ); - sMapPointers.insert( tAllocatedPointerMap::value_type( aAllocatedPointer.mData, aAllocatedPointer ) ); + sMapPointers.insert( AllocatedPointerMap::value_type( aAllocatedPointer.mData, aAllocatedPointer ) ); sTotalMemoryUsage += aAllocatedPointer.mMemory; @@ -55,7 +55,7 @@ void * MemoryManager::AddPointer( const cAllocatedPointer& aAllocatedPointer ) { bool MemoryManager::RemovePointer( void * Data ) { cLock l( sAllocMutex ); - tAllocatedPointerMapIt it = sMapPointers.find( Data ); + AllocatedPointerMapIt it = sMapPointers.find( Data ); if ( it == sMapPointers.end() ) { eePRINTL( "Trying to delete pointer %p created that does not exist!", Data ); @@ -78,7 +78,7 @@ size_t MemoryManager::GetTotalMemoryUsage() { return sTotalMemoryUsage; } -const cAllocatedPointer& MemoryManager::GetBiggestAllocation() { +const AllocatedPointer& MemoryManager::GetBiggestAllocation() { return sBiggestAllocation; } @@ -102,10 +102,10 @@ void MemoryManager::ShowResults() { //Get max length of file name int lMax =0; - tAllocatedPointerMapIt it = sMapPointers.begin(); + AllocatedPointerMapIt it = sMapPointers.begin(); for( ; it != sMapPointers.end(); ++it ){ - cAllocatedPointer &ap = it->second; + AllocatedPointer &ap = it->second; if( (int)ap.mFile.length() > lMax ) lMax = (int)ap.mFile.length(); @@ -123,7 +123,7 @@ void MemoryManager::ShowResults() { it = sMapPointers.begin(); for( ; it != sMapPointers.end(); ++it ) { - cAllocatedPointer &ap = it->second; + AllocatedPointer &ap = it->second; eePRINT( "| %p\t %s", ap.mData, ap.mFile.c_str() );