mirror of
https://github.com/nemtrif/utfcpp.git
synced 2025-04-21 04:28:54 +00:00
Compare commits
No commits in common. "master" and "v4.0.5" have entirely different histories.
4 changed files with 14 additions and 26 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
cmake_minimum_required (VERSION 3.14...3.27)
|
||||
project (utf8cpp
|
||||
VERSION 4.0.6
|
||||
VERSION 4.0.4
|
||||
LANGUAGES CXX
|
||||
DESCRIPTION "C++ portable library for working with utf-8 encoding")
|
||||
|
||||
|
|
|
@ -43,14 +43,9 @@ DEALINGS IN THE SOFTWARE.
|
|||
#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later
|
||||
#define UTF_CPP_OVERRIDE override
|
||||
#define UTF_CPP_NOEXCEPT noexcept
|
||||
#define UTF_CPP_STATIC_ASSERT(condition) static_assert(condition, "UTFCPP static assert");
|
||||
#else // C++ 98/03
|
||||
#define UTF_CPP_OVERRIDE
|
||||
#define UTF_CPP_NOEXCEPT throw()
|
||||
// Simulate static_assert:
|
||||
template <bool Condition> struct StaticAssert {static void assert() {int static_assert_impl[(Condition ? 1 : -1)];} };
|
||||
template <> struct StaticAssert<true> {static void assert() {}};
|
||||
#define UTF_CPP_STATIC_ASSERT(condition) StaticAssert<condition>::assert();
|
||||
#endif // C++ 11 or later
|
||||
|
||||
|
||||
|
@ -220,7 +215,7 @@ namespace internal
|
|||
|
||||
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||
|
||||
code_point = static_cast<utfchar32_t>(code_point + ((*it) & 0x3f));
|
||||
code_point += (*it) & 0x3f;
|
||||
|
||||
return UTF8_OK;
|
||||
}
|
||||
|
@ -239,11 +234,11 @@ namespace internal
|
|||
|
||||
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||
|
||||
code_point = static_cast<utfchar32_t>(code_point + ((utf8::internal::mask8(*it) << 6) & 0xfff));
|
||||
code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
|
||||
|
||||
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||
|
||||
code_point = static_cast<utfchar32_t>(code_point + ((*it) & 0x3f));
|
||||
code_point += (*it) & 0x3f;
|
||||
|
||||
return UTF8_OK;
|
||||
}
|
||||
|
@ -313,10 +308,6 @@ namespace internal
|
|||
template <typename word_iterator>
|
||||
utf_error validate_next16(word_iterator& it, word_iterator end, utfchar32_t& code_point)
|
||||
{
|
||||
// Make sure the iterator dereferences a large enough type
|
||||
typedef typename std::iterator_traits<word_iterator>::value_type word_type;
|
||||
UTF_CPP_STATIC_ASSERT(sizeof(word_type) >= sizeof(utfchar16_t));
|
||||
// Check the edge case:
|
||||
if (it == end)
|
||||
return NOT_ENOUGH_ROOM;
|
||||
// Save the original value of it so we can go back in case of failure
|
||||
|
@ -336,7 +327,7 @@ namespace internal
|
|||
else if (is_lead_surrogate(first_word)) {
|
||||
const utfchar16_t second_word = *it++;
|
||||
if (is_trail_surrogate(second_word)) {
|
||||
code_point = static_cast<utfchar32_t>(first_word << 10) + second_word + SURROGATE_OFFSET;
|
||||
code_point = (first_word << 10) + second_word + SURROGATE_OFFSET;
|
||||
return UTF8_OK;
|
||||
} else
|
||||
err = INCOMPLETE_SEQUENCE;
|
||||
|
@ -404,7 +395,6 @@ namespace internal
|
|||
// the word_type.
|
||||
template <typename word_iterator, typename word_type>
|
||||
word_iterator append16(utfchar32_t cp, word_iterator result) {
|
||||
UTF_CPP_STATIC_ASSERT(sizeof(word_type) >= sizeof(utfchar16_t));
|
||||
if (is_in_bmp(cp))
|
||||
*(result++) = static_cast<word_type>(cp);
|
||||
else {
|
||||
|
|
|
@ -115,15 +115,15 @@ namespace utf8
|
|||
++it;
|
||||
cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
|
||||
++it;
|
||||
cp = static_cast<utfchar32_t>(cp + ((*it) & 0x3f));
|
||||
cp += (*it) & 0x3f;
|
||||
break;
|
||||
case 4:
|
||||
++it;
|
||||
cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
|
||||
++it;
|
||||
cp = static_cast<utfchar32_t>(cp + ((utf8::internal::mask8(*it) << 6) & 0xfff));
|
||||
cp += (utf8::internal::mask8(*it) << 6) & 0xfff;
|
||||
++it;
|
||||
cp = static_cast<utfchar32_t>(cp + ((*it) & 0x3f));
|
||||
cp += (*it) & 0x3f;
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
|
|
|
@ -6,14 +6,6 @@ add_library(${PROJECT_NAME} INTERFACE)
|
|||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/../source")
|
||||
|
||||
if (MSVC)
|
||||
# warning level 4
|
||||
add_compile_options(/W4)
|
||||
else()
|
||||
# additional warnings
|
||||
add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion)
|
||||
endif()
|
||||
|
||||
add_executable(negative negative.cpp)
|
||||
add_executable(cpp11 test_cpp11.cpp)
|
||||
add_executable(cpp17 test_cpp17.cpp)
|
||||
|
@ -22,6 +14,12 @@ add_executable(apitests apitests.cpp)
|
|||
|
||||
add_executable(noexceptionstests noexceptionstests.cpp)
|
||||
|
||||
|
||||
|
||||
target_compile_options(${PROJECT_NAME} INTERFACE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/W4>
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Wconversion>)
|
||||
|
||||
target_compile_options(noexceptionstests PUBLIC -fno-exceptions)
|
||||
|
||||
set_target_properties(negative apitests noexceptionstests
|
||||
|
|
Loading…
Add table
Reference in a new issue