From 4389a15e0f0e1e0197c7a5460b6a03452a563976 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 30 Aug 2021 22:18:43 +0200 Subject: [PATCH] Remove unused locale-like code, utf8 functions and headers --- include/IrrCompileConfig.h | 48 ---- include/SMeshBufferLightMap.h | 7 - include/SMeshBufferTangents.h | 7 - include/SParticle.h | 56 ----- include/SVertexIndex.h | 53 ----- include/SceneParameters.h | 103 -------- include/coreutil.h | 6 +- include/fast_atof.h | 13 +- include/irrString.h | 39 +-- include/irrlicht.h | 3 - source/Irrlicht/CMakeLists.txt | 1 - source/Irrlicht/CSceneManager.cpp | 2 - source/Irrlicht/Irrlicht.cpp | 1 - source/Irrlicht/utf8.cpp | 380 ------------------------------ 14 files changed, 5 insertions(+), 714 deletions(-) delete mode 100644 include/SMeshBufferLightMap.h delete mode 100644 include/SMeshBufferTangents.h delete mode 100644 include/SParticle.h delete mode 100644 source/Irrlicht/utf8.cpp diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 1b98e35c..e0550fac 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -348,54 +348,6 @@ the engine will no longer read .png images. */ #undef _IRR_COMPILE_WITH_LIBPNG_ #endif -//! Define _IRR_D3D_NO_SHADER_DEBUGGING to disable shader debugging in D3D9 -/** If _IRR_D3D_NO_SHADER_DEBUGGING is undefined in IrrCompileConfig.h, -it is possible to debug all D3D9 shaders in VisualStudio. All shaders -(which have been generated in memory or read from archives for example) will be emitted -into a temporary file at runtime for this purpose. To debug your shaders, choose -Debug->Direct3D->StartWithDirect3DDebugging in Visual Studio, and for every shader a -file named 'irr_dbg_shader_%%.vsh' or 'irr_dbg_shader_%%.psh' will be created. Drag'n'drop -the file you want to debug into visual studio. That's it. You can now set breakpoints and -watch registers, variables etc. This works with ASM, HLSL, and both with pixel and vertex shaders. -Note that the engine will run in D3D REF for this, which is a lot slower than HAL. */ -#define _IRR_D3D_NO_SHADER_DEBUGGING -#ifdef NO_IRR_D3D_NO_SHADER_DEBUGGING -#undef _IRR_D3D_NO_SHADER_DEBUGGING -#endif - -//! Define _IRR_D3D_USE_LEGACY_HLSL_COMPILER to enable the old HLSL compiler in recent DX SDKs -/** This enables support for ps_1_x shaders for recent DX SDKs. Otherwise, support -for this shader model is not available anymore in SDKs after Oct2006. You need to -distribute the OCT2006_d3dx9_31_x86.cab or OCT2006_d3dx9_31_x64.cab though, in order -to provide the user with the proper DLL. That's why it's disabled by default. */ -//#define _IRR_D3D_USE_LEGACY_HLSL_COMPILER -#ifdef NO_IRR_D3D_USE_LEGACY_HLSL_COMPILER -#undef _IRR_D3D_USE_LEGACY_HLSL_COMPILER -#endif - -//! Define _IRR_USE_NVIDIA_PERFHUD_ to opt-in to using the nVidia PerHUD tool -/** Enable, by opting-in, to use the nVidia PerfHUD performance analysis driver -tool . */ -#undef _IRR_USE_NVIDIA_PERFHUD_ - -//! Define one of the three setting for Burning's Video Software Rasterizer -/** So if we were marketing guys we could say Irrlicht has 4 Software-Rasterizers. - In a Nutshell: - All Burnings Rasterizers use 32 Bit Backbuffer, 32Bit Texture & 32 Bit Z or WBuffer, - 16 Bit/32 Bit can be adjusted on a global flag. - - BURNINGVIDEO_RENDERER_BEAUTIFUL - 32 Bit + Vertexcolor + Lighting + Per Pixel Perspective Correct + SubPixel/SubTexel Correct + - Bilinear Texturefiltering + WBuffer - - BURNINGVIDEO_RENDERER_FAST - 32 Bit + Per Pixel Perspective Correct + SubPixel/SubTexel Correct + WBuffer + - Bilinear Dithering TextureFiltering + WBuffer - - BURNINGVIDEO_RENDERER_ULTRA_FAST - 16Bit + SubPixel/SubTexel Correct + ZBuffer -*/ - //! Uncomment the following line if you want to ignore the deprecated warnings //#define IGNORE_DEPRECATED_WARNING diff --git a/include/SMeshBufferLightMap.h b/include/SMeshBufferLightMap.h deleted file mode 100644 index 03b441f3..00000000 --- a/include/SMeshBufferLightMap.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -// replaced by template -#include "CMeshBuffer.h" - diff --git a/include/SMeshBufferTangents.h b/include/SMeshBufferTangents.h deleted file mode 100644 index 03b441f3..00000000 --- a/include/SMeshBufferTangents.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -// replaced by template -#include "CMeshBuffer.h" - diff --git a/include/SParticle.h b/include/SParticle.h deleted file mode 100644 index d1507a12..00000000 --- a/include/SParticle.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __S_PARTICLE_H_INCLUDED__ -#define __S_PARTICLE_H_INCLUDED__ - -#include "vector3d.h" -#include "dimension2d.h" -#include "SColor.h" - -namespace irr -{ -namespace scene -{ - //! Struct for holding particle data - struct SParticle - { - //! Position of the particle - core::vector3df pos; - - //! Direction and speed of the particle - core::vector3df vector; - - //! Start life time of the particle - u32 startTime; - - //! End life time of the particle - u32 endTime; - - //! Current color of the particle - video::SColor color; - - //! Original color of the particle. - /** That's the color of the particle it had when it was emitted. */ - video::SColor startColor; - - //! Original direction and speed of the particle. - /** The direction and speed the particle had when it was emitted. */ - core::vector3df startVector; - - //! Scale of the particle. - /** The current scale of the particle. */ - core::dimension2df size; - - //! Original scale of the particle. - /** The scale of the particle when it was emitted. */ - core::dimension2df startSize; - }; - - -} // end namespace scene -} // end namespace irr - -#endif - diff --git a/include/SVertexIndex.h b/include/SVertexIndex.h index d6837dc2..5ea41f0d 100644 --- a/include/SVertexIndex.h +++ b/include/SVertexIndex.h @@ -19,59 +19,6 @@ enum E_INDEX_TYPE }; -/* -//! vertex index used by the Irrlicht engine. -template -struct SSpecificVertexIndex -{ - T Index; - - //! default constructor - SSpecificVertexIndex() {} - - //! constructor - SSpecificVertexIndex(u32 _index) :Index(_index) {} - - bool operator==(const SSpecificVertexIndex& other) const - { - return (Index == other.Index); - } - - bool operator!=(const SSpecificVertexIndex& other) const - { - return (Index != other.Index); - } - - bool operator<(const SSpecificVertexIndex& other) const - { - return (Index < other.Index); - } - - SSpecificVertexIndex operator+(const u32& other) const - { - return SSpecificVertexIndex(Index + other); - } - - operator const u32() const - { - return (const u32)Index; - } - - E_INDEX_TYPE getType() const - { - if (sizeof(T)==sizeof(u16)) - return video::EIT_16BIT; - return video::EIT_32BIT; - } - -}; - -//typedef SSpecificVertexIndex SVertexIndex; - -typedef u32 SVertexIndex; -*/ - - } // end namespace video } // end namespace irr diff --git a/include/SceneParameters.h b/include/SceneParameters.h index 6e2aaced..88e2a6de 100644 --- a/include/SceneParameters.h +++ b/include/SceneParameters.h @@ -31,96 +31,6 @@ namespace scene **/ const c8* const ALLOW_ZWRITE_ON_TRANSPARENT = "Allow_ZWrite_On_Transparent"; - //! Deprecated, use IMeshLoader::getMeshTextureLoader()->setTexturePath instead. - /** Was used for changing the texture path of the built-in csm loader like this: - \code - SceneManager->getParameters()->setAttribute(scene::CSM_TEXTURE_PATH, "path/to/your/textures"); - \endcode - **/ - const c8* const CSM_TEXTURE_PATH = "CSM_TexturePath"; - - //! Deprecated, use IMeshLoader::getMeshTextureLoader()->setTexturePath instead. - /** Was used for changing the texture path of the built-in lmts loader like this: - \code - SceneManager->getParameters()->setAttribute(scene::LMTS_TEXTURE_PATH, "path/to/your/textures"); - \endcode - **/ - const c8* const LMTS_TEXTURE_PATH = "LMTS_TexturePath"; - - //! Deprecated, use IMeshLoader::getMeshTextureLoader()->setTexturePath instead. - /** Was used for changing the texture path of the built-in MY3D loader like this: - \code - SceneManager->getParameters()->setAttribute(scene::MY3D_TEXTURE_PATH, "path/to/your/textures"); - \endcode - **/ - const c8* const MY3D_TEXTURE_PATH = "MY3D_TexturePath"; - - //! Name of the parameter specifying the COLLADA mesh loading mode - /** - Specifies if the COLLADA loader should create instances of the models, lights and - cameras when loading COLLADA meshes. By default, this is set to false. If this is - set to true, the ISceneManager::getMesh() method will only return a pointer to a - dummy mesh and create instances of all meshes and lights and cameras in the collada - file by itself. Example: - \code - SceneManager->getParameters()->setAttribute(scene::COLLADA_CREATE_SCENE_INSTANCES, true); - \endcode - */ - const c8* const COLLADA_CREATE_SCENE_INSTANCES = "COLLADA_CreateSceneInstances"; - - //! Deprecated, use IMeshLoader::getMeshTextureLoader()->setTexturePath instead. - /** This path is prefixed to the file names defined in the Deled file when loading - textures. This allows to alter the paths for a specific project setting. - Use it like this: - \code - SceneManager->getStringParameters()->setAttribute(scene::DMF_TEXTURE_PATH, "path/to/your/textures"); - \endcode - **/ - const c8* const DMF_TEXTURE_PATH = "DMF_TexturePath"; - - //! Name of the parameter for preserving DMF textures dir structure with built-in DMF loader. - /** If this parameter is set to true, the texture directory defined in the Deled file - is ignored, and only the texture name is used to find the proper file. Otherwise, the - texture path is also used, which allows to use a nicer media layout. - Use it like this: - \code - //this way you won't use this setting (default) - SceneManager->getParameters()->setAttribute(scene::DMF_IGNORE_MATERIALS_DIRS, false); - \endcode - \code - //this way you'll use this setting - SceneManager->getParameters()->setAttribute(scene::DMF_IGNORE_MATERIALS_DIRS, true); - \endcode - **/ - const c8* const DMF_IGNORE_MATERIALS_DIRS = "DMF_IgnoreMaterialsDir"; - - //! Name of the parameter for setting reference value of alpha in transparent materials. - /** Use it like this: - \code - //this way you'll set alpha ref to 0.1 - SceneManager->getParameters()->setAttribute(scene::DMF_ALPHA_CHANNEL_REF, 0.1); - \endcode - **/ - const c8* const DMF_ALPHA_CHANNEL_REF = "DMF_AlphaRef"; - - //! Name of the parameter for choose to flip or not tga files. - /** Use it like this: - \code - //this way you'll choose to flip alpha textures - SceneManager->getParameters()->setAttribute(scene::DMF_FLIP_ALPHA_TEXTURES, true); - \endcode - **/ - const c8* const DMF_FLIP_ALPHA_TEXTURES = "DMF_FlipAlpha"; - - - //! Deprecated, use IMeshLoader::getMeshTextureLoader()->setTexturePath instead. - /** Was used for changing the texture path of the built-in obj loader like this: - \code - SceneManager->getParameters()->setAttribute(scene::OBJ_TEXTURE_PATH, "path/to/your/textures"); - \endcode - **/ - const c8* const OBJ_TEXTURE_PATH = "OBJ_TexturePath"; - //! Flag to avoid loading group structures in .obj files /** Use it like this: \code @@ -147,19 +57,6 @@ namespace scene **/ const c8* const B3D_LOADER_IGNORE_MIPMAP_FLAG = "B3D_IgnoreMipmapFlag"; - //! Deprecated, use IMeshLoader::getMeshTextureLoader()->setTexturePath instead. - /** Was used for changing the texture path of the built-in b3d loader like this: - \code - SceneManager->getParameters()->setAttribute(scene::B3D_TEXTURE_PATH, "path/to/your/textures"); - \endcode - **/ - const c8* const B3D_TEXTURE_PATH = "B3D_TexturePath"; - - //! Flag set as parameter when the scene manager is used as editor - /** In this way special animators like deletion animators can be stopped from - deleting scene nodes for example */ - const c8* const IRR_SCENE_MANAGER_IS_EDITOR = "IRR_Editor"; - //! Name of the parameter for setting the length of debug normals. /** Use it like this: \code diff --git a/include/coreutil.h b/include/coreutil.h index b4d5e19f..b5c387c9 100644 --- a/include/coreutil.h +++ b/include/coreutil.h @@ -194,9 +194,9 @@ static inline io::path mergeFilename(const io::path& path, const io::path& filen //! some standard function ( to remove dependencies ) -inline s32 isdigit(s32 c) { return c >= '0' && c <= '9'; } -inline s32 isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; } -inline s32 isupper(s32 c) { return c >= 'A' && c <= 'Z'; } +inline bool isdigit(s32 c) { return c >= '0' && c <= '9'; } +inline bool isspace(s32 c) { return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; } +inline bool isupper(s32 c) { return c >= 'A' && c <= 'Z'; } } // end namespace core diff --git a/include/fast_atof.h b/include/fast_atof.h index bb1077fe..eea6ff1d 100644 --- a/include/fast_atof.h +++ b/include/fast_atof.h @@ -12,17 +12,6 @@ namespace irr { namespace core { - //! Selection of characters which count as decimal point in fast_atof - //! By default Irrlicht considers "." as the decimal point in numbers. - //! But sometimes you might run into situations where floats were written in - //! a local format with another decimal point like ",". - //! Best solution is usually to fix those cases by converting the input. - //! But if you don't have that choice you can set this to ".,". - //! WARNING: This is not thread-safe, so don't change while there's a chance - //! of another thread using fast_atof functions at the same time. - // TODO: This should probably also be used in irr::core::string, but - // the float-to-string code used there has to be rewritten first. - IRRLICHT_API extern irr::core::stringc LOCALE_DECIMAL_POINTS; #define IRR_ATOF_TABLE_SIZE 17 // we write [IRR_ATOF_TABLE_SIZE] here instead of [] to work around a swig bug @@ -328,7 +317,7 @@ inline const char* fast_atof_move(const char* in, f32& result) f32 value = strtof10(in, &in); - if ( LOCALE_DECIMAL_POINTS.findFirst(*in) >= 0 ) + if ( *in == '.' ) { const char* afterDecimal = ++in; const f32 decimal = strtof10(in, &afterDecimal); diff --git a/include/irrString.h b/include/irrString.h index a871c24c..3178c396 100644 --- a/include/irrString.h +++ b/include/irrString.h @@ -38,29 +38,11 @@ template > class string; static size_t multibyteToWString(string& destination, const char* source, u32 sourceSize); static size_t wStringToMultibyte(string& destination, const wchar_t* source, u32 sourceSize); -inline s32 isdigit(s32 c); - -enum eLocaleID -{ - IRR_LOCALE_ANSI = 0, - IRR_LOCALE_GERMAN = 1 -}; - -static eLocaleID locale_current = IRR_LOCALE_ANSI; -static inline void locale_set ( eLocaleID id ) -{ - locale_current = id; -} +inline bool isdigit(s32 c); //! Returns a character converted to lower case static inline u32 locale_lower ( u32 x ) { - switch ( locale_current ) - { - case IRR_LOCALE_GERMAN: - case IRR_LOCALE_ANSI: - break; - } // ansi return x >= 'A' && x <= 'Z' ? x + 0x20 : x; } @@ -68,29 +50,10 @@ static inline u32 locale_lower ( u32 x ) //! Returns a character converted to upper case static inline u32 locale_upper ( u32 x ) { - switch ( locale_current ) - { - case IRR_LOCALE_GERMAN: - case IRR_LOCALE_ANSI: - break; - } - // ansi return x >= 'a' && x <= 'z' ? x + ( 'A' - 'a' ) : x; } -//! Convert this utf-8-encoded string to the platform's wchar. -/** The resulting string is always NULL-terminated and well-formed. -\param len The size of the output buffer in bytes. -*/ -IRRLICHT_API void utf8ToWchar(const char *in, wchar_t *out, const u64 len); - -//! Convert this wchar string to utf-8. -/** The resulting string is always NULL-terminated and well-formed. -\param len The size of the output buffer in bytes. -*/ -IRRLICHT_API void wcharToUtf8(const wchar_t *in, char *out, const u64 len); - template class string diff --git a/include/irrlicht.h b/include/irrlicht.h index 0ed16bca..eb86766d 100644 --- a/include/irrlicht.h +++ b/include/irrlicht.h @@ -155,9 +155,6 @@ #include "SMaterial.h" #include "SMesh.h" #include "SMeshBuffer.h" -#include "SMeshBufferLightMap.h" -#include "SMeshBufferTangents.h" -#include "SParticle.h" #include "SSharedMeshBuffer.h" #include "SSkinMeshBuffer.h" #include "SVertexIndex.h" diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index d4cd3848..0c8033c9 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -207,7 +207,6 @@ add_library(IRROTHEROBJ OBJECT os.cpp leakHunter.cpp CProfiler.cpp - utf8.cpp ) if(ANDROID) diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index 2371a14a..849b4e33 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -50,8 +50,6 @@ #include "CSceneCollisionManager.h" -#include - namespace irr { namespace scene diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index c816aaec..0745c5ed 100644 --- a/source/Irrlicht/Irrlicht.cpp +++ b/source/Irrlicht/Irrlicht.cpp @@ -127,7 +127,6 @@ namespace irr namespace core { const matrix4 IdentityMatrix(matrix4::EM4CONST_IDENTITY); - irr::core::stringc LOCALE_DECIMAL_POINTS("."); } namespace video diff --git a/source/Irrlicht/utf8.cpp b/source/Irrlicht/utf8.cpp deleted file mode 100644 index 5ba06d9a..00000000 --- a/source/Irrlicht/utf8.cpp +++ /dev/null @@ -1,380 +0,0 @@ -// Copyright (C) 2014 Lauri Kasanen -// This file is part of the "Irrlicht Engine". The UTF-8 functions are from physfs, -// under the zlib license, reproduced below. - -#include "irrTypes.h" -#include "irrString.h" - -namespace irr -{ -namespace core -{ - -/* - Copyright (c) 2001-2011 Ryan C. Gordon and others. - - This software is provided 'as-is', without any express or implied warranty. - In no event will the authors be held liable for any damages arising from - the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software in a - product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. - - Ryan C. Gordon -*/ - -/* - * From rfc3629, the UTF-8 spec: - * http://www.ietf.org/rfc/rfc3629.txt - * - * Char. number range | UTF-8 octet sequence - * (hexadecimal) | (binary) - * --------------------+--------------------------------------------- - * 0000 0000-0000 007F | 0xxxxxxx - * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx - * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx - * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - */ - - -/* - * This may not be the best value, but it's one that isn't represented - * in Unicode (0x10FFFF is the largest codepoint value). We return this - * value from utf8codepoint() if there's bogus bits in the - * stream. utf8codepoint() will turn this value into something - * reasonable (like a question mark), for text that wants to try to recover, - * whereas utf8valid() will use the value to determine if a string has bad - * bits. - */ -#define UNICODE_BOGUS_CHAR_VALUE 0xFFFFFFFF - -/* - * This is the codepoint we currently return when there was bogus bits in a - * UTF-8 string. May not fly in Asian locales? - */ -#define UNICODE_BOGUS_CHAR_CODEPOINT '?' - -static u32 utf8codepoint(const char **_str) -{ - const char *str = *_str; - u32 retval = 0; - u32 octet = (u32) ((u8) *str); - u32 octet2, octet3, octet4; - - if (octet == 0) /* null terminator, end of string. */ - return 0; - - else if (octet < 128) /* one octet char: 0 to 127 */ - { - (*_str)++; /* skip to next possible start of codepoint. */ - return(octet); - } /* else if */ - - else if ((octet > 127) && (octet < 192)) /* bad (starts with 10xxxxxx). */ - { - /* - * Apparently each of these is supposed to be flagged as a bogus - * char, instead of just resyncing to the next valid codepoint. - */ - (*_str)++; /* skip to next possible start of codepoint. */ - return UNICODE_BOGUS_CHAR_VALUE; - } /* else if */ - - else if (octet < 224) /* two octets */ - { - octet -= (128+64); - octet2 = (u32) ((u8) *(++str)); - if ((octet2 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - *_str += 2; /* skip to next possible start of codepoint. */ - retval = ((octet << 6) | (octet2 - 128)); - if ((retval >= 0x80) && (retval <= 0x7FF)) - return retval; - } /* else if */ - - else if (octet < 240) /* three octets */ - { - octet -= (128+64+32); - octet2 = (u32) ((u8) *(++str)); - if ((octet2 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet3 = (u32) ((u8) *(++str)); - if ((octet3 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - *_str += 3; /* skip to next possible start of codepoint. */ - retval = ( ((octet << 12)) | ((octet2-128) << 6) | ((octet3-128)) ); - - /* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */ - switch (retval) - { - case 0xD800: - case 0xDB7F: - case 0xDB80: - case 0xDBFF: - case 0xDC00: - case 0xDF80: - case 0xDFFF: - return UNICODE_BOGUS_CHAR_VALUE; - } /* switch */ - - /* 0xFFFE and 0xFFFF are illegal, too, so we check them at the edge. */ - if ((retval >= 0x800) && (retval <= 0xFFFD)) - return retval; - } /* else if */ - - else if (octet < 248) /* four octets */ - { - octet -= (128+64+32+16); - octet2 = (u32) ((u8) *(++str)); - if ((octet2 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet3 = (u32) ((u8) *(++str)); - if ((octet3 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet4 = (u32) ((u8) *(++str)); - if ((octet4 & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - *_str += 4; /* skip to next possible start of codepoint. */ - retval = ( ((octet << 18)) | ((octet2 - 128) << 12) | - ((octet3 - 128) << 6) | ((octet4 - 128)) ); - if ((retval >= 0x10000) && (retval <= 0x10FFFF)) - return retval; - } /* else if */ - - /* - * Five and six octet sequences became illegal in rfc3629. - * We throw the codepoint away, but parse them to make sure we move - * ahead the right number of bytes and don't overflow the buffer. - */ - - else if (octet < 252) /* five octets */ - { - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - *_str += 5; /* skip to next possible start of codepoint. */ - return UNICODE_BOGUS_CHAR_VALUE; - } /* else if */ - - else /* six octets */ - { - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - octet = (u32) ((u8) *(++str)); - if ((octet & (128+64)) != 128) /* Format isn't 10xxxxxx? */ - return UNICODE_BOGUS_CHAR_VALUE; - - *_str += 6; /* skip to next possible start of codepoint. */ - return UNICODE_BOGUS_CHAR_VALUE; - } /* else if */ - - return UNICODE_BOGUS_CHAR_VALUE; -} /* utf8codepoint */ - - -static void PHYSFS_utf8ToUcs4(const char *src, u32 *dst, u64 len) -{ - len -= sizeof (u32); /* save room for null char. */ - while (len >= sizeof (u32)) - { - u32 cp = utf8codepoint(&src); - if (cp == 0) - break; - else if (cp == UNICODE_BOGUS_CHAR_VALUE) - cp = UNICODE_BOGUS_CHAR_CODEPOINT; - *(dst++) = cp; - len -= sizeof (u32); - } /* while */ - - *dst = 0; -} /* PHYSFS_utf8ToUcs4 */ - - -static void PHYSFS_utf8ToUcs2(const char *src, u16 *dst, u64 len) -{ - len -= sizeof (u16); /* save room for null char. */ - while (len >= sizeof (u16)) - { - u32 cp = utf8codepoint(&src); - if (cp == 0) - break; - else if (cp == UNICODE_BOGUS_CHAR_VALUE) - cp = UNICODE_BOGUS_CHAR_CODEPOINT; - - /* !!! BLUESKY: UTF-16 surrogates? */ - if (cp > 0xFFFF) - cp = UNICODE_BOGUS_CHAR_CODEPOINT; - - *(dst++) = cp; - len -= sizeof (u16); - } /* while */ - - *dst = 0; -} /* PHYSFS_utf8ToUcs2 */ - -static void utf8fromcodepoint(u32 cp, char **_dst, u64 *_len) -{ - char *dst = *_dst; - u64 len = *_len; - - if (len == 0) - return; - - if (cp > 0x10FFFF) - cp = UNICODE_BOGUS_CHAR_CODEPOINT; - else if ((cp == 0xFFFE) || (cp == 0xFFFF)) /* illegal values. */ - cp = UNICODE_BOGUS_CHAR_CODEPOINT; - else - { - /* There are seven "UTF-16 surrogates" that are illegal in UTF-8. */ - switch (cp) - { - case 0xD800: - case 0xDB7F: - case 0xDB80: - case 0xDBFF: - case 0xDC00: - case 0xDF80: - case 0xDFFF: - cp = UNICODE_BOGUS_CHAR_CODEPOINT; - } /* switch */ - } /* else */ - - /* Do the encoding... */ - if (cp < 0x80) - { - *(dst++) = (char) cp; - len--; - } /* if */ - - else if (cp < 0x800) - { - if (len < 2) - len = 0; - else - { - *(dst++) = (char) ((cp >> 6) | 128 | 64); - *(dst++) = (char) (cp & 0x3F) | 128; - len -= 2; - } /* else */ - } /* else if */ - - else if (cp < 0x10000) - { - if (len < 3) - len = 0; - else - { - *(dst++) = (char) ((cp >> 12) | 128 | 64 | 32); - *(dst++) = (char) ((cp >> 6) & 0x3F) | 128; - *(dst++) = (char) (cp & 0x3F) | 128; - len -= 3; - } /* else */ - } /* else if */ - - else - { - if (len < 4) - len = 0; - else - { - *(dst++) = (char) ((cp >> 18) | 128 | 64 | 32 | 16); - *(dst++) = (char) ((cp >> 12) & 0x3F) | 128; - *(dst++) = (char) ((cp >> 6) & 0x3F) | 128; - *(dst++) = (char) (cp & 0x3F) | 128; - len -= 4; - } /* else if */ - } /* else */ - - *_dst = dst; - *_len = len; -} /* utf8fromcodepoint */ - -#define UTF8FROMTYPE(typ, src, dst, len) \ - if (len == 0) return; \ - len--; \ - while (len) \ - { \ - const u32 cp = (u32) ((typ) (*(src++))); \ - if (cp == 0) break; \ - utf8fromcodepoint(cp, &dst, &len); \ - } \ - *dst = '\0'; \ - -static void PHYSFS_utf8FromUcs4(const u32 *src, char *dst, u64 len) -{ - UTF8FROMTYPE(u32, src, dst, len); -} /* PHYSFS_utf8FromUcs4 */ - -static void PHYSFS_utf8FromUcs2(const u16 *src, char *dst, u64 len) -{ - UTF8FROMTYPE(u64, src, dst, len); -} /* PHYSFS_utf8FromUcs4 */ - -#undef UTF8FROMTYPE - -void utf8ToWchar(const char *in, wchar_t *out, const u64 len) -{ -#ifdef _WIN32 - PHYSFS_utf8ToUcs2(in, (u16 *) out, len); -#else - PHYSFS_utf8ToUcs4(in, (u32 *) out, len); -#endif -} - -void wcharToUtf8(const wchar_t *in, char *out, const u64 len) -{ -#ifdef _WIN32 - PHYSFS_utf8FromUcs2((const u16 *) in, out, len); -#else - PHYSFS_utf8FromUcs4((const u32 *) in, out, len); -#endif -} - -} // end namespace core -} // end namespace irr -