From 67e4be99329cc3f3a6016cb2947ff848792b2739 Mon Sep 17 00:00:00 2001 From: Victor Bogado Date: Sat, 5 Oct 2019 12:25:02 -0700 Subject: [PATCH 1/3] CMake support --- .gitignore | 5 ++++- CMakeLists.txt | 15 +++++++++++++++ configure.ac | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 2647d1f..59c7eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ aclocal.m4 configure config.log +# Reserved for build dirs with CMAKE +[bB]uild/* + /bin/ /docs/ -/lib/ \ No newline at end of file +/lib/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a90dd22 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.14) + +project(CsString LANGUAGES CXX VERSION 1.2.1) + +add_library(cs_string INTERFACE) +target_include_directories(cs_string INTERFACE src) +target_compile_features(cs_string INTERFACE cxx_std_14) + +file(GLOB SOURCES src/*.cpp) + +add_executable(cs_string_test test/main.cpp) +target_link_libraries(cs_string_test cs_string) + +# TODO: Remove the need for this +target_compile_definitions(cs_string_test PRIVATE CS_STRING_ALLOW_UNSAFE) diff --git a/configure.ac b/configure.ac index 835cf75..10f0d32 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([cs_string], [1.2.0], [info@copperspice.com]) +AC_INIT([cs_string], [1.2.1], [info@copperspice.com]) # derive CS hex version from "@PACKAGE_VERSION@" HEX_VERSION=$(printf "0x%02x%02x%02x" `echo $PACKAGE_VERSION | tr '.' ' '`) From bbfc6b9d7513f01d5853dbb9f333537ec260690a Mon Sep 17 00:00:00 2001 From: Victor Bogado Date: Sat, 5 Oct 2019 12:56:51 -0700 Subject: [PATCH 2/3] Add support for CsChar to be built from unicode chars. * UTF8 ``uchar8_t`` is available only for C++20 --- src/cs_char.h | 14 ++++++++++++++ test/main.cpp | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cs_char.h b/src/cs_char.h index ff49f8a..af6a391 100644 --- a/src/cs_char.h +++ b/src/cs_char.h @@ -60,6 +60,20 @@ class CsChar #endif } + /* UTF-8 characters - Available only with C++20 */ +#ifdef __cpp_char8_t + CsChar(char8_t c) + : m_char(c) + { + } +#endif + + /* UTF-16 characters - as specified at http://eel.is/c++draft/lex.ccon#4 */ + CsChar(char16_t c) + : m_char(c) + { + } + CsChar(char32_t c) : m_char(c) { diff --git a/test/main.cpp b/test/main.cpp index f30c4bf..308dc57 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -93,20 +93,20 @@ void test_2() // CsChar internationalization test // unicode 00 42, data type char - CsString::CsChar c0 = 'B'; + CsString::CsChar c0 = u'B'; // unicode 00 BF, data type maybe char or int, compile will return the value - CsString::CsChar c127 = '¿'; + CsString::CsChar c127 = u'¿'; CsString::CsChar u127 = UCHAR('¿'); // unicode 21 B4, data type int or a compile error, not safe - CsString::CsChar c256 = '↴'; + CsString::CsChar c256 = u'↴'; // unicode 21 B4, data type char32_t, guaranteed to be the proper unicode value CsString::CsChar u256 = UCHAR('↴'); // unicode 01 D1 60, data type int or a compile error, not safe - CsString::CsChar cX = '𝅘𝅥𝅮'; + CsString::CsChar cX = U'𝅘𝅥𝅮'; // unicode 01 D1 60, data type char32_t, guaranteed to be the proper unicode value CsString::CsChar uX = UCHAR('𝅘𝅥𝅮'); From c5490d252d805e268dfced0e59aad1a85d30b8d5 Mon Sep 17 00:00:00 2001 From: Victor Bogado Date: Sat, 5 Oct 2019 17:10:09 -0700 Subject: [PATCH 3/3] Make CsChar constexpr. --- src/cs_char.h | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cs_char.h b/src/cs_char.h index af6a391..2dd5ae6 100644 --- a/src/cs_char.h +++ b/src/cs_char.h @@ -45,14 +45,14 @@ class CsBasicString; class CsChar { public: - CsChar() + constexpr CsChar() noexcept : m_char(0) { } template - CsChar(char c) + constexpr CsChar(char c) noexcept : m_char(static_cast(c)) { #ifndef CS_STRING_ALLOW_UNSAFE @@ -62,96 +62,96 @@ class CsChar /* UTF-8 characters - Available only with C++20 */ #ifdef __cpp_char8_t - CsChar(char8_t c) + constexpr CsChar(char8_t c) noexcept : m_char(c) { } #endif /* UTF-16 characters - as specified at http://eel.is/c++draft/lex.ccon#4 */ - CsChar(char16_t c) + constexpr CsChar(char16_t c) noexcept : m_char(c) { } - CsChar(char32_t c) + constexpr CsChar(char32_t c) noexcept : m_char(c) { } - CsChar(int c) + constexpr CsChar(int c) noexcept : m_char(c) { } - bool operator!=(const CsChar &other) const; - bool operator==(const CsChar &other) const; + constexpr bool operator!=(const CsChar &other) const noexcept; + constexpr bool operator==(const CsChar &other) const noexcept; - bool operator<(const CsChar &other) const; - bool operator<=(const CsChar &other) const; - bool operator>(const CsChar &other) const; - bool operator>=(const CsChar &other) const; + constexpr bool operator<(const CsChar &other) const noexcept; + constexpr bool operator<=(const CsChar &other) const noexcept; + constexpr bool operator>(const CsChar &other) const noexcept; + constexpr bool operator>=(const CsChar &other) const noexcept; - CsChar &operator=(char c) &; - CsChar &operator=(char32_t c) &; - CsChar &operator=(CsChar c) &; + constexpr CsChar &operator=(char c) & noexcept; + constexpr CsChar &operator=(char32_t c) & noexcept; + constexpr CsChar &operator=(CsChar c) & noexcept; - uint32_t unicode() const; + constexpr uint32_t unicode() const noexcept; private: uint32_t m_char; }; // comparisons -inline bool CsChar::operator!=(const CsChar &other) const +inline constexpr bool CsChar::operator!=(const CsChar &other) const noexcept { return m_char != other.m_char; } -inline bool CsChar::operator==(const CsChar &other) const +inline constexpr bool CsChar::operator==(const CsChar &other) const noexcept { return m_char == other.m_char; } -inline bool CsChar::operator<(const CsChar &other) const +inline constexpr bool CsChar::operator<(const CsChar &other) const noexcept { return m_char < other.m_char; } -inline bool CsChar::operator<=(const CsChar &other) const +inline constexpr bool CsChar::operator<=(const CsChar &other) const noexcept { return m_char <= other.m_char; } -inline bool CsChar::operator>(const CsChar &other) const +inline constexpr bool CsChar::operator>(const CsChar &other) const noexcept { return m_char > other.m_char; } -inline bool CsChar::operator>=(const CsChar &other) const +inline constexpr bool CsChar::operator>=(const CsChar &other) const noexcept { return m_char >= other.m_char; } -inline CsChar &CsChar::operator=(char c) & +inline constexpr CsChar &CsChar::operator=(char c) & noexcept { m_char = c; return *this; } -inline CsChar &CsChar::operator=(char32_t c) & +inline constexpr CsChar &CsChar::operator=(char32_t c) & noexcept { m_char = c; return *this; } -inline CsChar &CsChar::operator=(CsChar c) & +inline constexpr CsChar &CsChar::operator=(CsChar c) & noexcept { m_char = c.m_char; return *this; } -inline uint32_t CsChar::unicode() const +inline constexpr uint32_t CsChar::unicode() const noexcept { return m_char; } @@ -169,4 +169,4 @@ namespace std { }; } -#endif \ No newline at end of file +#endif