From 40fc27154fe754181934dc7ee31375e6bdfb33fc Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 23 Oct 2018 12:23:58 +0800 Subject: *merge from minimal --- src/libjin/Common/Data.h | 34 --------- src/libjin/Common/Object.cpp | 32 --------- src/libjin/Common/Object.h | 49 ------------- src/libjin/Common/Singleton.hpp | 38 ---------- src/libjin/Common/StringMap.hpp | 143 ------------------------------------- src/libjin/Common/Subsystem.hpp | 43 ----------- src/libjin/Common/data.h | 34 --------- src/libjin/Common/je_array.hpp | 123 +++++++++++++++++++++++++++++++ src/libjin/Common/je_common.h | 6 ++ src/libjin/Common/je_exception.cpp | 0 src/libjin/Common/je_exception.h | 22 ++++++ src/libjin/Common/je_noncopyable.h | 24 +++++++ src/libjin/Common/je_object.h | 16 +++++ src/libjin/Common/je_pool.hpp | 11 +++ src/libjin/Common/je_singleton.hpp | 80 +++++++++++++++++++++ src/libjin/Common/je_stringmap.hpp | 143 +++++++++++++++++++++++++++++++++++++ src/libjin/Common/je_subsystem.hpp | 78 ++++++++++++++++++++ src/libjin/Common/je_temporary.h | 31 ++++++++ src/libjin/Common/je_types.h | 23 ++++++ src/libjin/Common/je_utf8.cpp | 42 +++++++++++ src/libjin/Common/je_utf8.h | 34 +++++++++ src/libjin/Common/utf8.cpp | 42 ----------- src/libjin/Common/utf8.h | 31 -------- 23 files changed, 633 insertions(+), 446 deletions(-) delete mode 100644 src/libjin/Common/Data.h delete mode 100644 src/libjin/Common/Object.cpp delete mode 100644 src/libjin/Common/Object.h delete mode 100644 src/libjin/Common/Singleton.hpp delete mode 100644 src/libjin/Common/StringMap.hpp delete mode 100644 src/libjin/Common/Subsystem.hpp delete mode 100644 src/libjin/Common/data.h create mode 100644 src/libjin/Common/je_array.hpp create mode 100644 src/libjin/Common/je_common.h create mode 100644 src/libjin/Common/je_exception.cpp create mode 100644 src/libjin/Common/je_exception.h create mode 100644 src/libjin/Common/je_noncopyable.h create mode 100644 src/libjin/Common/je_object.h create mode 100644 src/libjin/Common/je_pool.hpp create mode 100644 src/libjin/Common/je_singleton.hpp create mode 100644 src/libjin/Common/je_stringmap.hpp create mode 100644 src/libjin/Common/je_subsystem.hpp create mode 100644 src/libjin/Common/je_temporary.h create mode 100644 src/libjin/Common/je_types.h create mode 100644 src/libjin/Common/je_utf8.cpp create mode 100644 src/libjin/Common/je_utf8.h delete mode 100644 src/libjin/Common/utf8.cpp delete mode 100644 src/libjin/Common/utf8.h (limited to 'src/libjin/Common') diff --git a/src/libjin/Common/Data.h b/src/libjin/Common/Data.h deleted file mode 100644 index 4b0f1ba..0000000 --- a/src/libjin/Common/Data.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __JIN_COMMON_DATA_H -#define __JIN_COMMON_DATA_H - - - -namespace jin -{ - - class DataBuffer - { - public: - DataBuffer(int n) - : len(n) - { - buffer = new char[len]; - memset(buffer, 0, len); - } - ~DataBuffer() - { - delete[] buffer; - } - char* operator&() - { - return buffer; - } - - private: - char* buffer; - int len; - }; - -} // jin - -#endif \ No newline at end of file diff --git a/src/libjin/Common/Object.cpp b/src/libjin/Common/Object.cpp deleted file mode 100644 index 6c3b667..0000000 --- a/src/libjin/Common/Object.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// LOVE -#include "Object.h" - -namespace jin -{ - - Object::Object() - : count(1) - { - } - - Object::~Object() - { - } - - int Object::getReferenceCount() const - { - return count; - } - - void Object::retain() - { - ++count; - } - - void Object::release() - { - if (--count <= 0) - delete this; - } - -} // love diff --git a/src/libjin/Common/Object.h b/src/libjin/Common/Object.h deleted file mode 100644 index 9ac1b5a..0000000 --- a/src/libjin/Common/Object.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __JIN_COMMON_OBJECT_H -#define __JIN_COMMON_OBJECT_H - -namespace jin -{ - - class Object - { - private: - - // The reference count. - int count; - - public: - - /** - * Constructor. Sets reference count to one. - **/ - Object(); - - /** - * Destructor. - **/ - virtual ~Object() = 0; - - /** - * Gets the reference count of this Object. - * @returns The reference count. - **/ - int getReferenceCount() const; - - /** - * Retains the Object, i.e. increases the - * reference count by one. - **/ - void retain(); - - /** - * Releases one reference to the Object, i.e. decrements the - * reference count by one, and potentially deletes the Object - * if there are no more references. - **/ - void release(); - - }; // Object - -} - -#endif \ No newline at end of file diff --git a/src/libjin/Common/Singleton.hpp b/src/libjin/Common/Singleton.hpp deleted file mode 100644 index 48cd5bc..0000000 --- a/src/libjin/Common/Singleton.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __JIN_SINGLETON_H -#define __JIN_SINGLETON_H - -namespace jin -{ - - template - class Singleton - { - public: - static T* get() - { - if (_instance == nullptr) - _instance = new T; - return _instance; - } - static void destroy() - { - delete _instance; - _instance = nullptr; - } - protected: - Singleton() {}; - virtual ~Singleton() {}; - static T* _instance; - private: - Singleton(const Singleton&); - Singleton& operator = (const Singleton&); - }; - - template T* Singleton::_instance = nullptr; - -#define SINGLETON(T) \ - friend Singleton - -} // jin - -#endif // __JIN_SINGLETON_H \ No newline at end of file diff --git a/src/libjin/Common/StringMap.hpp b/src/libjin/Common/StringMap.hpp deleted file mode 100644 index bebd94d..0000000 --- a/src/libjin/Common/StringMap.hpp +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef __JIN_COMMON_SREINGMAP_H -#define __JIN_COMMON_SREINGMAP_H - -namespace jin -{ - - template - class StringMap - { - private: - - struct Record - { - const char * key; - T value; - bool set; - Record() : set(false) {} - }; - - const static unsigned MAX = SIZE * 2; - - Record records[MAX]; - const char * reverse[SIZE]; - - public: - - struct Entry - { - const char * key; - T value; - }; - - StringMap(Entry * entries, unsigned num) - { - - for (unsigned i = 0; i < SIZE; ++i) - reverse[i] = 0; - - unsigned n = num / sizeof(Entry); - - for (unsigned i = 0; i < n; ++i) - { - add(entries[i].key, entries[i].value); - } - } - - bool streq(const char * a, const char * b) - { - while (*a != 0 && *b != 0) - { - if (*a != *b) - return false; - ++a; - ++b; - } - - return (*a == 0 && *b == 0); - } - - bool find(const char * key, T & t) - { - //unsigned str_hash = djb2(key); - - for (unsigned i = 0; i < MAX; ++i) - { - //unsigned str_i = (str_hash + i) % MAX; //this isn't used, is this intentional? - - if (records[i].set && streq(records[i].key, key)) - { - t = records[i].value; - return true; - } - } - - return false; - } - - bool find(T key, const char *& str) - { - unsigned index = (unsigned)key; - - if (index >= SIZE) - return false; - - if (reverse[index] != 0) - { - str = reverse[index]; - return true; - } - else - { - return false; - } - } - - bool add(const char * key, T value) - { - unsigned str_hash = djb2(key); - bool inserted = false; - - for (unsigned i = 0; i < MAX; ++i) - { - unsigned str_i = (str_hash + i) % MAX; - - if (!records[str_i].set) - { - inserted = true; - records[str_i].set = true; - records[str_i].key = key; - records[str_i].value = value; - break; - } - } - - unsigned index = (unsigned)value; - - if (index >= SIZE) - { - printf("\nConstant %s out of bounds with %i!\n", key, index); - return false; - } - - reverse[index] = key; - - return inserted; - } - - unsigned djb2(const char * key) - { - unsigned hash = 5381; - int c; - - while ((c = *key++)) - hash = ((hash << 5) + hash) + c; - - return hash; - } - - }; // StringMap - -} - -#endif \ No newline at end of file diff --git a/src/libjin/Common/Subsystem.hpp b/src/libjin/Common/Subsystem.hpp deleted file mode 100644 index 1374ad1..0000000 --- a/src/libjin/Common/Subsystem.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __JIN_COMMON_SUBSYSTEM_H -#define __JIN_COMMON_SUBSYSTEM_H - -#include "singleton.hpp" -#include "../utils/macros.h" - -namespace jin -{ - - template - class Subsystem : public Singleton - { - public: - struct Setting {}; - typedef Setting SettingBase; - - bool init(const SettingBase* setting = nullptr) - { - static bool success = initSystem(setting); - return success; - } - - void quit() - { - CALLONCE(quitSystem()); - Singleton::destroy(); - } - - protected: - - Subsystem() {}; - virtual ~Subsystem() {}; - - SINGLETON(System); - - /*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0; - /*onlyonce*/ virtual void quitSystem() = 0; - - }; - -} // jin - -#endif \ No newline at end of file diff --git a/src/libjin/Common/data.h b/src/libjin/Common/data.h deleted file mode 100644 index 4b0f1ba..0000000 --- a/src/libjin/Common/data.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __JIN_COMMON_DATA_H -#define __JIN_COMMON_DATA_H - - - -namespace jin -{ - - class DataBuffer - { - public: - DataBuffer(int n) - : len(n) - { - buffer = new char[len]; - memset(buffer, 0, len); - } - ~DataBuffer() - { - delete[] buffer; - } - char* operator&() - { - return buffer; - } - - private: - char* buffer; - int len; - }; - -} // jin - -#endif \ No newline at end of file diff --git a/src/libjin/Common/je_array.hpp b/src/libjin/Common/je_array.hpp new file mode 100644 index 0000000..361f1f0 --- /dev/null +++ b/src/libjin/Common/je_array.hpp @@ -0,0 +1,123 @@ +#ifndef __JE_COMMON_ARRAY_H +#define __JE_COMMON_ARRAY_H + +namespace JinEngine +{ + + /// + /// A array created on heap. + /// + template + class Array + { + public: + /// + /// Array constructor. + /// + Array() + : length(0) + , data(nullptr) + { + } + + /// + /// Array constructor. + /// + /// @param l Length of array. + /// + Array(int l) + { + length = l; + data = new T[l]; + } + + /// + /// Array destructor. + /// + ~Array() + { + delete[] data; + length = 0; + } + + /// + /// Get address of data. + /// + /// @return Address of data. + /// + T* operator &() + { + return data; + } + + /// + /// Get specific element of array. + /// + /// @return Element of array. + /// + T& operator[](int index) + { + return data[index]; + } + + /// + /// Bind data with given data. + /// + /// @param data Data pointer. + /// @param length Length of data. + /// + void bind(T* data, int length) + { + if (data != nullptr) + delete data; + this->data = data; + this->length = length; + } + + /// + /// Add an element. + /// + /// @param v Value of element. + /// + void add(T value) + { + int len = length + 1; + T* d = new T[len]; + memcpy(d, data, size()); + d[length] = value; + bind(d, len); + } + + /// + /// Get size of data in byte. + /// + /// @return Size of data in byte. + /// + int size() + { + return sizeof(T) * length; + } + + /// + /// Get length of data. + /// + /// @return Count of data. + /// + int count() + { + return length; + } + + private: + // Disable new and delete. + void* operator new(size_t t); + void operator delete(void* ptr); + + T * data; + unsigned int length; + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_common.h b/src/libjin/Common/je_common.h new file mode 100644 index 0000000..0dfa79a --- /dev/null +++ b/src/libjin/Common/je_common.h @@ -0,0 +1,6 @@ +#ifndef __JE_COMMON_H +#define __JE_COMMON_H + +#include "je_array.hpp" + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_exception.cpp b/src/libjin/Common/je_exception.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libjin/Common/je_exception.h b/src/libjin/Common/je_exception.h new file mode 100644 index 0000000..7c66af8 --- /dev/null +++ b/src/libjin/Common/je_exception.h @@ -0,0 +1,22 @@ +#ifndef __JE_EXCEPTION_H +#define __JE_EXCEPTION_H + +#include + +namespace JinEngine +{ + + /// + /// Built-in exception class. + /// + class JinException : public std::exception + { + public: + JinException(); + const char* what() const throw(); + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_noncopyable.h b/src/libjin/Common/je_noncopyable.h new file mode 100644 index 0000000..89a3e68 --- /dev/null +++ b/src/libjin/Common/je_noncopyable.h @@ -0,0 +1,24 @@ +#ifndef __JE_NONCOPYABLE_H +#define __JE_NONCOPYABLE_H + +namespace JinEngine +{ + + /// + /// Class inherites this could not be copied. + /// + class Noncopyable + { + public: + Noncopyable(void) { } + virtual ~Noncopyable(void) { } + + private: + Noncopyable(const Noncopyable& other); + Noncopyable& operator=(const Noncopyable& other); + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h new file mode 100644 index 0000000..c256879 --- /dev/null +++ b/src/libjin/Common/je_object.h @@ -0,0 +1,16 @@ +#ifndef __JE_OBJECT_H +#define __JE_OBJECT_H + +namespace JinEngine +{ + + /// + /// Base class of all objects in Jin. + /// + class Object + { + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_pool.hpp b/src/libjin/Common/je_pool.hpp new file mode 100644 index 0000000..1107fd5 --- /dev/null +++ b/src/libjin/Common/je_pool.hpp @@ -0,0 +1,11 @@ +#ifndef __JE_POOL_H +#define __JE_POOL_H + +namespace JinEngine +{ + + + +} + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_singleton.hpp b/src/libjin/Common/je_singleton.hpp new file mode 100644 index 0000000..e981e7a --- /dev/null +++ b/src/libjin/Common/je_singleton.hpp @@ -0,0 +1,80 @@ +#ifndef __JE_SINGLETON_H +#define __JE_SINGLETON_H + +namespace JinEngine +{ + + /// + /// Singleton base class. + /// + template + class Singleton + { + public: + /// + /// Get singleton. + /// + /// @param Singleton instance of class. + /// + static T* get() + { + if (_instance == nullptr) + _instance = new T; + return _instance; + } + + /// + /// Destroy instance of singleton. + /// + static void destroy() + { + delete _instance; + _instance = nullptr; + } + + protected: + /// + /// Singleton constructor. + /// + Singleton() {}; + + /// + /// Singleton destructor. + /// + virtual ~Singleton() {}; + + /// + /// Singleton instance. + /// + static T* _instance; + + private: + /// + /// Singleton copy constructor. + /// + /// @param singleton Singleton of class. + /// + Singleton(const Singleton& singleton); + + /// + /// Singleton assignment. + /// + /// @param singleton Singleton of class. + /// + Singleton& operator = (const Singleton& singleton); + + }; + + /// + /// Singleton instance. + /// + template T* Singleton::_instance = nullptr; + + /// + /// Singleton notation. + /// + #define singleton(T) friend Singleton + +} // namespace JinEngine + +#endif // __JE_SINGLETON_H \ No newline at end of file diff --git a/src/libjin/Common/je_stringmap.hpp b/src/libjin/Common/je_stringmap.hpp new file mode 100644 index 0000000..43e3e9b --- /dev/null +++ b/src/libjin/Common/je_stringmap.hpp @@ -0,0 +1,143 @@ +#ifndef __JE_COMMON_SREINGMAP_H +#define __JE_COMMON_SREINGMAP_H + +namespace JinEngine +{ + + template + class StringMap + { + private: + + struct Record + { + const char * key; + T value; + bool set; + Record() : set(false) {} + }; + + const static unsigned MAX = SIZE * 2; + + Record records[MAX]; + const char * reverse[SIZE]; + + public: + + struct Entry + { + const char * key; + T value; + }; + + StringMap(Entry * entries, unsigned num) + { + + for (unsigned i = 0; i < SIZE; ++i) + reverse[i] = 0; + + unsigned n = num / sizeof(Entry); + + for (unsigned i = 0; i < n; ++i) + { + add(entries[i].key, entries[i].value); + } + } + + bool streq(const char * a, const char * b) + { + while (*a != 0 && *b != 0) + { + if (*a != *b) + return false; + ++a; + ++b; + } + + return (*a == 0 && *b == 0); + } + + bool find(const char * key, T & t) + { + //unsigned str_hash = djb2(key); + + for (unsigned i = 0; i < MAX; ++i) + { + //unsigned str_i = (str_hash + i) % MAX; //this isn't used, is this intentional? + + if (records[i].set && streq(records[i].key, key)) + { + t = records[i].value; + return true; + } + } + + return false; + } + + bool find(T key, const char *& str) + { + unsigned index = (unsigned)key; + + if (index >= SIZE) + return false; + + if (reverse[index] != 0) + { + str = reverse[index]; + return true; + } + else + { + return false; + } + } + + bool add(const char * key, T value) + { + unsigned str_hash = djb2(key); + bool inserted = false; + + for (unsigned i = 0; i < MAX; ++i) + { + unsigned str_i = (str_hash + i) % MAX; + + if (!records[str_i].set) + { + inserted = true; + records[str_i].set = true; + records[str_i].key = key; + records[str_i].value = value; + break; + } + } + + unsigned index = (unsigned)value; + + if (index >= SIZE) + { + printf("\nConstant %s out of bounds with %i!\n", key, index); + return false; + } + + reverse[index] = key; + + return inserted; + } + + unsigned djb2(const char * key) + { + unsigned hash = 5381; + int c; + + while ((c = *key++)) + hash = ((hash << 5) + hash) + c; + + return hash; + } + + }; // StringMap + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_subsystem.hpp b/src/libjin/Common/je_subsystem.hpp new file mode 100644 index 0000000..d8e106d --- /dev/null +++ b/src/libjin/Common/je_subsystem.hpp @@ -0,0 +1,78 @@ +#ifndef __JE_COMMON_SUBSYSTEM_H +#define __JE_COMMON_SUBSYSTEM_H + +#include "../utils/je_macros.h" + +#include "je_singleton.hpp" + +namespace JinEngine +{ + + /// + /// Subsystem class. + /// + template + class Subsystem : public Singleton + { + public: + /// + /// Subsystem setting. + /// + struct Setting + { + }; + + typedef Setting SettingBase; + + /// + /// Initialize subsystem. + /// + /// @param setting Subsystem setting. + /// @return True if initialize sucessful, otherwise return false. + /// + bool init(const SettingBase* setting = nullptr) + { + static bool success = initSystem(setting); + return success; + } + + /// + /// Quit subsystem. + /// + void quit() + { + // Call only once. + static char __dummy__ = (quitSystem(), 1); + Singleton::destroy(); + } + + protected: + singleton(System); + + /// + /// Subsystem constructor. + /// + Subsystem() {}; + + /// + /// Subsystem destructor. + /// + virtual ~Subsystem() + { + }; + + /// + /// Initializer callback. + /// + virtual bool initSystem(const Setting* setting) = 0; + + /// + /// Quit subsystem callback. + /// + virtual void quitSystem() = 0; + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_temporary.h b/src/libjin/Common/je_temporary.h new file mode 100644 index 0000000..5af8704 --- /dev/null +++ b/src/libjin/Common/je_temporary.h @@ -0,0 +1,31 @@ +#ifndef __JE_ON_STACK_H +#define __JE_ON_STACK_H + +namespace JinEngine +{ + + /// + /// Class inherites this clound only be created on stack or static zone. + /// + class Temporary + { + public: + Temporary() {}; + virtual ~Temporary() {}; +/* + protected: + void operator delete(void* t) + { + if(t != nullptr) + free(t); + } +*/ + private: + // Disable new operands. + void* operator new(size_t); + + }; + +} // namespace JinEngine + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_types.h b/src/libjin/Common/je_types.h new file mode 100644 index 0000000..446c413 --- /dev/null +++ b/src/libjin/Common/je_types.h @@ -0,0 +1,23 @@ +#ifndef __JE_TYPES_H +#define __JE_TYPES_H +#include + +namespace JinEngine +{ + + typedef int8_t int8; ///< Signed integer with a size of 8 bits. Supports values from -128 to 127 + typedef uint8_t uint8; ///< Unsigned integer with a size of 8 bits. Supports values from 0 to 255. + typedef uint8 byte; ///< Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255. + typedef int16_t int16; ///< Signed integer with a size of 16 bits. Supports values from -32768 to 32767 + typedef uint16_t uint16; ///< Unsigned integer with a size of 16 bits. Supports values from 0 to 65535. + typedef int32_t int32; ///< Signed integer with a size of 32 bits. Supports values from -2147483648 to 2147483647. + typedef uint32_t uint32; ///< Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1). + typedef int64_t int64; ///< Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1). + typedef uint64_t uint64; ///< Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1). + + typedef uint32_t uint; + typedef int32_t sint; + +} + +#endif \ No newline at end of file diff --git a/src/libjin/Common/je_utf8.cpp b/src/libjin/Common/je_utf8.cpp new file mode 100644 index 0000000..bd7ce94 --- /dev/null +++ b/src/libjin/Common/je_utf8.cpp @@ -0,0 +1,42 @@ +#include "../core/je_configuration.h" +#if jin_os == jin_os_windows + +#include "je_utf8.h" + +namespace JinEngine +{ + + std::string to_utf8(LPCWSTR wstr) + { + size_t wide_len = wcslen(wstr) + 1; + + // Get size in UTF-8. + int utf8_size = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, 0, 0, 0, 0); + + char * utf8_str = new char[utf8_size]; + + // Convert to UTF-8. + int ok = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, utf8_str, utf8_size, 0, 0); + + if (!ok) + { + delete[] utf8_str; + } + + return ok ? std::string(utf8_str) : std::string(); + } + + void replace_char(std::string & str, char find, char replace) + { + int length = str.length(); + + for (int i = 0; i +#include + +namespace JinEngine +{ + + /// + /// Convert the wide string to a UTF-8 encoded string. + /// + /// @param wstr The wide-char string. + /// @return A UTF-8 string. + /// + std::string to_utf8(LPCWSTR wstr); + + /// + /// Replace all occurences of 'find' with 'replace' in a string. + /// + /// @param str The string to modify. + /// @param find The character to match. + /// @param replace The character to replace matches. + /// + void replace_char(std::string & str, char find, char replace); + +} // namespace JinEngine + +#endif // jin_os == jin_os_windows + +#endif // __JE_COMMON_UTF8_H \ No newline at end of file diff --git a/src/libjin/Common/utf8.cpp b/src/libjin/Common/utf8.cpp deleted file mode 100644 index bef6c85..0000000 --- a/src/libjin/Common/utf8.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "../modules.h" -#if JIN_OS == JIN_WINDOWS - -#include "utf8.h" - -namespace jin -{ - - std::string to_utf8(LPCWSTR wstr) - { - size_t wide_len = wcslen(wstr) + 1; - - // Get size in UTF-8. - int utf8_size = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, 0, 0, 0, 0); - - char * utf8_str = new char[utf8_size]; - - // Convert to UTF-8. - int ok = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, utf8_str, utf8_size, 0, 0); - - if (!ok) - { - delete[] utf8_str; - } - - return ok ? std::string(utf8_str) : std::string(); - } - - void replace_char(std::string & str, char find, char replace) - { - int length = str.length(); - - for (int i = 0; i -#include - -namespace jin -{ - - /** - * Convert the wide string to a UTF-8 encoded string. - * @param wstr The wide-char string. - * @return A UTF-8 string. - **/ - std::string to_utf8(LPCWSTR wstr); - - /** - * Replace all occurences of 'find' with 'replace' in a string. - * @param str The string to modify. - * @param find The character to match. - * @param replace The character to replace matches. - **/ - void replace_char(std::string & str, char find, char replace); - -} - -#endif // JIN_OS == JIN_WINDOWS -#endif // __JIN_COMMON_UTF8_H \ No newline at end of file -- cgit v1.1-26-g67d0