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 '.' ' '`) diff --git a/src/cs_char.h b/src/cs_char.h index ff49f8a..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 @@ -60,84 +60,98 @@ class CsChar #endif } - CsChar(char32_t c) + /* UTF-8 characters - Available only with C++20 */ +#ifdef __cpp_char8_t + constexpr CsChar(char8_t c) noexcept : m_char(c) { } +#endif - CsChar(int c) + /* UTF-16 characters - as specified at http://eel.is/c++draft/lex.ccon#4 */ + constexpr CsChar(char16_t c) noexcept + : m_char(c) + { + } + + constexpr CsChar(char32_t c) noexcept : m_char(c) { } - bool operator!=(const CsChar &other) const; - bool operator==(const CsChar &other) const; + constexpr CsChar(int c) noexcept + : m_char(c) + { + } - 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; - CsChar &operator=(char c) &; - CsChar &operator=(char32_t c) &; - CsChar &operator=(CsChar c) &; + 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; - uint32_t unicode() const; + constexpr CsChar &operator=(char c) & noexcept; + constexpr CsChar &operator=(char32_t c) & noexcept; + constexpr CsChar &operator=(CsChar c) & noexcept; + + 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; } @@ -155,4 +169,4 @@ namespace std { }; } -#endif \ No newline at end of file +#endif 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('𝅘𝅥𝅮');