Mercurial > code
changeset 548:f48bb09bccc7
Misc: huge cleanup, switch to spaces
line wrap: on
line diff
--- a/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -31,18 +31,18 @@ find_package(Doxygen) if (DOXYGEN_FOUND) - configure_file( - ${CMAKE_SOURCE_DIR}/cmake/Doxyfile.in - ${CMAKE_BINARY_DIR}/Doxyfile - ) + configure_file( + ${CMAKE_SOURCE_DIR}/cmake/Doxyfile.in + ${CMAKE_BINARY_DIR}/Doxyfile + ) - add_custom_target( - doxygen ALL - COMMENT "Generating doxygen documentation" - COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - VERBATIM - ) + add_custom_target( + doxygen ALL + COMMENT "Generating doxygen documentation" + COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + VERBATIM + ) endif () add_subdirectory(modules/base64)
--- a/README.md Wed Jun 15 11:59:17 2016 +0200 +++ b/README.md Wed Jun 15 13:13:26 2016 +0200 @@ -6,11 +6,11 @@ The following status are defined: -- **Frozen**, the module will not changed and only have bugfixes, -- **Stable**, the module is stable but may still change a little bit, -- **Testing**, the module is being tested and may change, -- **Experimental**, the module is new and completely experimental or unstable, -- **New**, the module is completely new. + - **Frozen**, the module will not changed and only have bugfixes, + - **Stable**, the module is stable but may still change a little bit, + - **Testing**, the module is being tested and may change, + - **Experimental**, the module is new and completely experimental or unstable, + - **New**, the module is completely new. | Module | Status | Tests quality | |---------------|--------------|---------------|
--- a/cmake/CodeDefineModule.cmake Wed Jun 15 11:59:17 2016 +0200 +++ b/cmake/CodeDefineModule.cmake Wed Jun 15 13:13:26 2016 +0200 @@ -21,11 +21,11 @@ # ------------------------------------------------------------------- # # code_define_module( -# NAME lowercase name -# SOURCES source files -# LIBRARIES (Optional) libraries -# INCLUDES (Optional) include directories -# FLAGS (Optional) flags +# NAME lowercase name +# SOURCES source files +# LIBRARIES (Optional) libraries +# INCLUDES (Optional) include directories +# FLAGS (Optional) flags # ) # # Create a test for the given module. @@ -38,45 +38,45 @@ include(CMakeParseArguments) function(code_define_module) - set(oneValueArgs NAME) - set(multiValueArgs SOURCES LIBRARIES INCLUDES FLAGS) + set(oneValueArgs NAME) + set(multiValueArgs SOURCES LIBRARIES INCLUDES FLAGS) - cmake_parse_arguments(MOD "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(MOD "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - if (NOT MOD_NAME) - message(FATAL_ERROR "Argument NAME is not set") - endif () + if (NOT MOD_NAME) + message(FATAL_ERROR "Argument NAME is not set") + endif () - # Create the option for enabling the test. - string(TOUPPER ${MOD_NAME} optionname) - option(WITH_${optionname} "Enable ${MOD_NAME}" On) + # Create the option for enabling the test. + string(TOUPPER ${MOD_NAME} optionname) + option(WITH_${optionname} "Enable ${MOD_NAME}" On) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp AND WITH_${optionname}) - # Create test executable. - add_executable(test-${MOD_NAME} ${MOD_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp) - set_target_properties( - test-${MOD_NAME} - PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR} - ) - target_compile_definitions(test-${MOD_NAME} PRIVATE ${MOD_FLAGS}) - target_include_directories( - test-${MOD_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${MOD_INCLUDES} - ) - target_link_libraries(test-${MOD_NAME} gtest ${MOD_LIBRARIES}) + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp AND WITH_${optionname}) + # Create test executable. + add_executable(test-${MOD_NAME} ${MOD_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp) + set_target_properties( + test-${MOD_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR} + ) + target_compile_definitions(test-${MOD_NAME} PRIVATE ${MOD_FLAGS}) + target_include_directories( + test-${MOD_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${MOD_INCLUDES} + ) + target_link_libraries(test-${MOD_NAME} gtest ${MOD_LIBRARIES}) - # Register the test. - add_test( - NAME ${MOD_NAME} - COMMAND test-${MOD_NAME} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - endif () + # Register the test. + add_test( + NAME ${MOD_NAME} + COMMAND test-${MOD_NAME} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + endif () endfunction()
--- a/extern/gtest/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/extern/gtest/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -21,13 +21,13 @@ add_library(gtest src/gtest-all.cc) target_include_directories( - gtest - PUBLIC - ${GoogleTest_SOURCE_DIR}/include - PRIVATE - ${GoogleTest_SOURCE_DIR} + gtest + PUBLIC + ${GoogleTest_SOURCE_DIR}/include + PRIVATE + ${GoogleTest_SOURCE_DIR} ) if (NOT WIN32) - target_link_libraries(gtest -pthread) + target_link_libraries(gtest -pthread) endif ()
--- a/modules/base64/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/base64/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -17,6 +17,6 @@ # code_define_module( - NAME base64 - SOURCES base64.hpp -) \ No newline at end of file + NAME base64 + SOURCES base64.hpp +)
--- a/modules/base64/base64.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/base64/base64.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -45,9 +45,9 @@ * * ```` * try { - * std::string text = base64::decode(msg); + * std::string text = base64::decode(msg); * } catch (const std::exception &ex) { - * std::cerr << ex.what() << std::endl; + * std::cerr << ex.what() << std::endl; * } * ```` */ @@ -70,7 +70,7 @@ */ inline bool isBase64(char ch) noexcept { - return std::isalnum(ch) != 0 || ch == '+' || ch == '/'; + return std::isalnum(ch) != 0 || ch == '+' || ch == '/'; } /** @@ -81,7 +81,7 @@ */ inline bool isValid(char ch) noexcept { - return isBase64(ch) || ch == '='; + return isBase64(ch) || ch == '='; } /** @@ -93,11 +93,11 @@ */ inline char lookup(unsigned char value) noexcept { - static const char *table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + static const char *table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - assert(value < 64); + assert(value < 64); - return table[value]; + return table[value]; } /** @@ -112,16 +112,16 @@ */ inline unsigned char rlookup(char ch) noexcept { - assert(isBase64(ch)); + assert(isBase64(ch)); - if (ch >= '0' && ch <= '9') - return static_cast<unsigned char>(ch + 4); - if (ch >= 'A' && ch <= 'Z') - return static_cast<unsigned char>(ch - 65); - if (ch >= 'a' && ch <= 'z') - return static_cast<unsigned char>(ch - 71); + if (ch >= '0' && ch <= '9') + return static_cast<unsigned char>(ch + 4); + if (ch >= 'A' && ch <= 'Z') + return static_cast<unsigned char>(ch - 65); + if (ch >= 'a' && ch <= 'z') + return static_cast<unsigned char>(ch - 71); - return (ch == '+') ? 62U : 63U; + return (ch == '+') ? 62U : 63U; } /** @@ -139,20 +139,20 @@ template <typename InputIt, typename OutputIt> OutputIt encode(InputIt input, InputIt end, OutputIt output) { - while (input != end) { - char inputbuf[3] = { 0, 0, 0 }; - int count; + while (input != end) { + char inputbuf[3] = { 0, 0, 0 }; + int count; - for (count = 0; count < 3 && input != end; ++count) - inputbuf[count] = *input++; + for (count = 0; count < 3 && input != end; ++count) + inputbuf[count] = *input++; - *output++ = lookup(inputbuf[0] >> 2 & 0x3f); - *output++ = lookup((inputbuf[0] << 4 & 0x3f) | (inputbuf[1] >> 4 & 0x0f)); - *output++ = (count < 2) ? '=' : lookup((inputbuf[1] << 2 & 0x3c) | (inputbuf[2] >> 6 & 0x03)); - *output++ = (count < 3) ? '=' : lookup(inputbuf[2] & 0x3f); - } + *output++ = lookup(inputbuf[0] >> 2 & 0x3f); + *output++ = lookup((inputbuf[0] << 4 & 0x3f) | (inputbuf[1] >> 4 & 0x0f)); + *output++ = (count < 2) ? '=' : lookup((inputbuf[1] << 2 & 0x3c) | (inputbuf[2] >> 6 & 0x03)); + *output++ = (count < 3) ? '=' : lookup(inputbuf[2] & 0x3f); + } - return output; + return output; } /** @@ -171,37 +171,37 @@ template <typename InputIt, typename OutputIt> OutputIt decode(InputIt input, InputIt end, OutputIt output) { - while (input != end) { - char inputbuf[4] = { -1, -1, -1, -1 }; - int count; + while (input != end) { + char inputbuf[4] = { -1, -1, -1, -1 }; + int count; - for (count = 0; count < 4 && input != end; ++count) { - // Check if the character is valid and get its value. - if ((*input == '=' && count <= 1) || !isValid(*input)) - throw std::invalid_argument("invalid base64 string"); - if (isBase64(*input)) - inputbuf[count] = static_cast<char>(rlookup(*input)); + for (count = 0; count < 4 && input != end; ++count) { + // Check if the character is valid and get its value. + if ((*input == '=' && count <= 1) || !isValid(*input)) + throw std::invalid_argument("invalid base64 string"); + if (isBase64(*input)) + inputbuf[count] = static_cast<char>(rlookup(*input)); - input++; - } + input++; + } - if (count != 4) - throw std::invalid_argument("truncated string"); + if (count != 4) + throw std::invalid_argument("truncated string"); - *output++ = static_cast<char>(((inputbuf[0] << 2) & 0xfc) | ((inputbuf[1] >> 4) & 0x03)); + *output++ = static_cast<char>(((inputbuf[0] << 2) & 0xfc) | ((inputbuf[1] >> 4) & 0x03)); - if (inputbuf[2] != -1) - *output++ = static_cast<char>(((inputbuf[1] << 4) & 0xf0) | ((inputbuf[2] >> 2) & 0x0f)); - if (inputbuf[3] != -1) { - // "XY=Z" is not allowed. - if (inputbuf[2] == -1) - throw std::invalid_argument("invalid base64 string"); + if (inputbuf[2] != -1) + *output++ = static_cast<char>(((inputbuf[1] << 4) & 0xf0) | ((inputbuf[2] >> 2) & 0x0f)); + if (inputbuf[3] != -1) { + // "XY=Z" is not allowed. + if (inputbuf[2] == -1) + throw std::invalid_argument("invalid base64 string"); - *output++ = static_cast<char>(((inputbuf[2] << 6) & 0xc0) | (inputbuf[3] & 0x3f)); - } - } + *output++ = static_cast<char>(((inputbuf[2] << 6) & 0xc0) | (inputbuf[3] & 0x3f)); + } + } - return output; + return output; } /** @@ -212,11 +212,11 @@ */ inline std::string encode(const std::string &input) { - std::string result; + std::string result; - encode(input.begin(), input.end(), std::back_inserter(result)); + encode(input.begin(), input.end(), std::back_inserter(result)); - return result; + return result; } /** @@ -228,11 +228,11 @@ */ inline std::string decode(const std::string &input) { - std::string result; + std::string result; - decode(input.begin(), input.end(), std::back_inserter(result)); + decode(input.begin(), input.end(), std::back_inserter(result)); - return result; + return result; } } // !base64
--- a/modules/base64/doc/mainpage.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/base64/doc/mainpage.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -18,9 +18,9 @@ * * int main(void) * { - * base64::encode("Hello World!"); + * base64::encode("Hello World!"); * - * return 0; + * return 0; * } * ```` */
--- a/modules/base64/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/base64/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -22,192 +22,192 @@ TEST(Lookup, lookup) { - ASSERT_EQ('A', base64::lookup(0b000000)); - ASSERT_EQ('B', base64::lookup(0b000001)); - ASSERT_EQ('C', base64::lookup(0b000010)); - ASSERT_EQ('D', base64::lookup(0b000011)); - ASSERT_EQ('E', base64::lookup(0b000100)); - ASSERT_EQ('F', base64::lookup(0b000101)); - ASSERT_EQ('G', base64::lookup(0b000110)); - ASSERT_EQ('H', base64::lookup(0b000111)); - ASSERT_EQ('I', base64::lookup(0b001000)); - ASSERT_EQ('J', base64::lookup(0b001001)); - ASSERT_EQ('K', base64::lookup(0b001010)); - ASSERT_EQ('L', base64::lookup(0b001011)); - ASSERT_EQ('M', base64::lookup(0b001100)); - ASSERT_EQ('N', base64::lookup(0b001101)); - ASSERT_EQ('O', base64::lookup(0b001110)); - ASSERT_EQ('P', base64::lookup(0b001111)); - ASSERT_EQ('Q', base64::lookup(0b010000)); - ASSERT_EQ('R', base64::lookup(0b010001)); - ASSERT_EQ('S', base64::lookup(0b010010)); - ASSERT_EQ('T', base64::lookup(0b010011)); - ASSERT_EQ('U', base64::lookup(0b010100)); - ASSERT_EQ('V', base64::lookup(0b010101)); - ASSERT_EQ('W', base64::lookup(0b010110)); - ASSERT_EQ('X', base64::lookup(0b010111)); - ASSERT_EQ('Y', base64::lookup(0b011000)); - ASSERT_EQ('Z', base64::lookup(0b011001)); - ASSERT_EQ('a', base64::lookup(0b011010)); - ASSERT_EQ('b', base64::lookup(0b011011)); - ASSERT_EQ('c', base64::lookup(0b011100)); - ASSERT_EQ('d', base64::lookup(0b011101)); - ASSERT_EQ('e', base64::lookup(0b011110)); - ASSERT_EQ('f', base64::lookup(0b011111)); - ASSERT_EQ('g', base64::lookup(0b100000)); - ASSERT_EQ('h', base64::lookup(0b100001)); - ASSERT_EQ('i', base64::lookup(0b100010)); - ASSERT_EQ('j', base64::lookup(0b100011)); - ASSERT_EQ('k', base64::lookup(0b100100)); - ASSERT_EQ('l', base64::lookup(0b100101)); - ASSERT_EQ('m', base64::lookup(0b100110)); - ASSERT_EQ('n', base64::lookup(0b100111)); - ASSERT_EQ('o', base64::lookup(0b101000)); - ASSERT_EQ('p', base64::lookup(0b101001)); - ASSERT_EQ('q', base64::lookup(0b101010)); - ASSERT_EQ('r', base64::lookup(0b101011)); - ASSERT_EQ('s', base64::lookup(0b101100)); - ASSERT_EQ('t', base64::lookup(0b101101)); - ASSERT_EQ('u', base64::lookup(0b101110)); - ASSERT_EQ('v', base64::lookup(0b101111)); - ASSERT_EQ('w', base64::lookup(0b110000)); - ASSERT_EQ('x', base64::lookup(0b110001)); - ASSERT_EQ('y', base64::lookup(0b110010)); - ASSERT_EQ('z', base64::lookup(0b110011)); - ASSERT_EQ('0', base64::lookup(0b110100)); - ASSERT_EQ('1', base64::lookup(0b110101)); - ASSERT_EQ('2', base64::lookup(0b110110)); - ASSERT_EQ('3', base64::lookup(0b110111)); - ASSERT_EQ('4', base64::lookup(0b111000)); - ASSERT_EQ('5', base64::lookup(0b111001)); - ASSERT_EQ('6', base64::lookup(0b111010)); - ASSERT_EQ('7', base64::lookup(0b111011)); - ASSERT_EQ('8', base64::lookup(0b111100)); - ASSERT_EQ('9', base64::lookup(0b111101)); - ASSERT_EQ('+', base64::lookup(0b111110)); - ASSERT_EQ('/', base64::lookup(0b111111)); + ASSERT_EQ('A', base64::lookup(0b000000)); + ASSERT_EQ('B', base64::lookup(0b000001)); + ASSERT_EQ('C', base64::lookup(0b000010)); + ASSERT_EQ('D', base64::lookup(0b000011)); + ASSERT_EQ('E', base64::lookup(0b000100)); + ASSERT_EQ('F', base64::lookup(0b000101)); + ASSERT_EQ('G', base64::lookup(0b000110)); + ASSERT_EQ('H', base64::lookup(0b000111)); + ASSERT_EQ('I', base64::lookup(0b001000)); + ASSERT_EQ('J', base64::lookup(0b001001)); + ASSERT_EQ('K', base64::lookup(0b001010)); + ASSERT_EQ('L', base64::lookup(0b001011)); + ASSERT_EQ('M', base64::lookup(0b001100)); + ASSERT_EQ('N', base64::lookup(0b001101)); + ASSERT_EQ('O', base64::lookup(0b001110)); + ASSERT_EQ('P', base64::lookup(0b001111)); + ASSERT_EQ('Q', base64::lookup(0b010000)); + ASSERT_EQ('R', base64::lookup(0b010001)); + ASSERT_EQ('S', base64::lookup(0b010010)); + ASSERT_EQ('T', base64::lookup(0b010011)); + ASSERT_EQ('U', base64::lookup(0b010100)); + ASSERT_EQ('V', base64::lookup(0b010101)); + ASSERT_EQ('W', base64::lookup(0b010110)); + ASSERT_EQ('X', base64::lookup(0b010111)); + ASSERT_EQ('Y', base64::lookup(0b011000)); + ASSERT_EQ('Z', base64::lookup(0b011001)); + ASSERT_EQ('a', base64::lookup(0b011010)); + ASSERT_EQ('b', base64::lookup(0b011011)); + ASSERT_EQ('c', base64::lookup(0b011100)); + ASSERT_EQ('d', base64::lookup(0b011101)); + ASSERT_EQ('e', base64::lookup(0b011110)); + ASSERT_EQ('f', base64::lookup(0b011111)); + ASSERT_EQ('g', base64::lookup(0b100000)); + ASSERT_EQ('h', base64::lookup(0b100001)); + ASSERT_EQ('i', base64::lookup(0b100010)); + ASSERT_EQ('j', base64::lookup(0b100011)); + ASSERT_EQ('k', base64::lookup(0b100100)); + ASSERT_EQ('l', base64::lookup(0b100101)); + ASSERT_EQ('m', base64::lookup(0b100110)); + ASSERT_EQ('n', base64::lookup(0b100111)); + ASSERT_EQ('o', base64::lookup(0b101000)); + ASSERT_EQ('p', base64::lookup(0b101001)); + ASSERT_EQ('q', base64::lookup(0b101010)); + ASSERT_EQ('r', base64::lookup(0b101011)); + ASSERT_EQ('s', base64::lookup(0b101100)); + ASSERT_EQ('t', base64::lookup(0b101101)); + ASSERT_EQ('u', base64::lookup(0b101110)); + ASSERT_EQ('v', base64::lookup(0b101111)); + ASSERT_EQ('w', base64::lookup(0b110000)); + ASSERT_EQ('x', base64::lookup(0b110001)); + ASSERT_EQ('y', base64::lookup(0b110010)); + ASSERT_EQ('z', base64::lookup(0b110011)); + ASSERT_EQ('0', base64::lookup(0b110100)); + ASSERT_EQ('1', base64::lookup(0b110101)); + ASSERT_EQ('2', base64::lookup(0b110110)); + ASSERT_EQ('3', base64::lookup(0b110111)); + ASSERT_EQ('4', base64::lookup(0b111000)); + ASSERT_EQ('5', base64::lookup(0b111001)); + ASSERT_EQ('6', base64::lookup(0b111010)); + ASSERT_EQ('7', base64::lookup(0b111011)); + ASSERT_EQ('8', base64::lookup(0b111100)); + ASSERT_EQ('9', base64::lookup(0b111101)); + ASSERT_EQ('+', base64::lookup(0b111110)); + ASSERT_EQ('/', base64::lookup(0b111111)); } TEST(Lookup, rlookup) { - ASSERT_EQ(0b000000U, base64::rlookup('A')); - ASSERT_EQ(0b000001U, base64::rlookup('B')); - ASSERT_EQ(0b000010U, base64::rlookup('C')); - ASSERT_EQ(0b000011U, base64::rlookup('D')); - ASSERT_EQ(0b000100U, base64::rlookup('E')); - ASSERT_EQ(0b000101U, base64::rlookup('F')); - ASSERT_EQ(0b000110U, base64::rlookup('G')); - ASSERT_EQ(0b000111U, base64::rlookup('H')); - ASSERT_EQ(0b001000U, base64::rlookup('I')); - ASSERT_EQ(0b001001U, base64::rlookup('J')); - ASSERT_EQ(0b001010U, base64::rlookup('K')); - ASSERT_EQ(0b001011U, base64::rlookup('L')); - ASSERT_EQ(0b001100U, base64::rlookup('M')); - ASSERT_EQ(0b001101U, base64::rlookup('N')); - ASSERT_EQ(0b001110U, base64::rlookup('O')); - ASSERT_EQ(0b001111U, base64::rlookup('P')); - ASSERT_EQ(0b010000U, base64::rlookup('Q')); - ASSERT_EQ(0b010001U, base64::rlookup('R')); - ASSERT_EQ(0b010010U, base64::rlookup('S')); - ASSERT_EQ(0b010011U, base64::rlookup('T')); - ASSERT_EQ(0b010100U, base64::rlookup('U')); - ASSERT_EQ(0b010101U, base64::rlookup('V')); - ASSERT_EQ(0b010110U, base64::rlookup('W')); - ASSERT_EQ(0b010111U, base64::rlookup('X')); - ASSERT_EQ(0b011000U, base64::rlookup('Y')); - ASSERT_EQ(0b011001U, base64::rlookup('Z')); - ASSERT_EQ(0b011010U, base64::rlookup('a')); - ASSERT_EQ(0b011011U, base64::rlookup('b')); - ASSERT_EQ(0b011100U, base64::rlookup('c')); - ASSERT_EQ(0b011101U, base64::rlookup('d')); - ASSERT_EQ(0b011110U, base64::rlookup('e')); - ASSERT_EQ(0b011111U, base64::rlookup('f')); - ASSERT_EQ(0b100000U, base64::rlookup('g')); - ASSERT_EQ(0b100001U, base64::rlookup('h')); - ASSERT_EQ(0b100010U, base64::rlookup('i')); - ASSERT_EQ(0b100011U, base64::rlookup('j')); - ASSERT_EQ(0b100100U, base64::rlookup('k')); - ASSERT_EQ(0b100101U, base64::rlookup('l')); - ASSERT_EQ(0b100110U, base64::rlookup('m')); - ASSERT_EQ(0b100111U, base64::rlookup('n')); - ASSERT_EQ(0b101000U, base64::rlookup('o')); - ASSERT_EQ(0b101001U, base64::rlookup('p')); - ASSERT_EQ(0b101010U, base64::rlookup('q')); - ASSERT_EQ(0b101011U, base64::rlookup('r')); - ASSERT_EQ(0b101100U, base64::rlookup('s')); - ASSERT_EQ(0b101101U, base64::rlookup('t')); - ASSERT_EQ(0b101110U, base64::rlookup('u')); - ASSERT_EQ(0b101111U, base64::rlookup('v')); - ASSERT_EQ(0b110000U, base64::rlookup('w')); - ASSERT_EQ(0b110001U, base64::rlookup('x')); - ASSERT_EQ(0b110010U, base64::rlookup('y')); - ASSERT_EQ(0b110011U, base64::rlookup('z')); - ASSERT_EQ(0b110100U, base64::rlookup('0')); - ASSERT_EQ(0b110101U, base64::rlookup('1')); - ASSERT_EQ(0b110110U, base64::rlookup('2')); - ASSERT_EQ(0b110111U, base64::rlookup('3')); - ASSERT_EQ(0b111000U, base64::rlookup('4')); - ASSERT_EQ(0b111001U, base64::rlookup('5')); - ASSERT_EQ(0b111010U, base64::rlookup('6')); - ASSERT_EQ(0b111011U, base64::rlookup('7')); - ASSERT_EQ(0b111100U, base64::rlookup('8')); - ASSERT_EQ(0b111101U, base64::rlookup('9')); - ASSERT_EQ(0b111110U, base64::rlookup('+')); - ASSERT_EQ(0b111111U, base64::rlookup('/')); + ASSERT_EQ(0b000000U, base64::rlookup('A')); + ASSERT_EQ(0b000001U, base64::rlookup('B')); + ASSERT_EQ(0b000010U, base64::rlookup('C')); + ASSERT_EQ(0b000011U, base64::rlookup('D')); + ASSERT_EQ(0b000100U, base64::rlookup('E')); + ASSERT_EQ(0b000101U, base64::rlookup('F')); + ASSERT_EQ(0b000110U, base64::rlookup('G')); + ASSERT_EQ(0b000111U, base64::rlookup('H')); + ASSERT_EQ(0b001000U, base64::rlookup('I')); + ASSERT_EQ(0b001001U, base64::rlookup('J')); + ASSERT_EQ(0b001010U, base64::rlookup('K')); + ASSERT_EQ(0b001011U, base64::rlookup('L')); + ASSERT_EQ(0b001100U, base64::rlookup('M')); + ASSERT_EQ(0b001101U, base64::rlookup('N')); + ASSERT_EQ(0b001110U, base64::rlookup('O')); + ASSERT_EQ(0b001111U, base64::rlookup('P')); + ASSERT_EQ(0b010000U, base64::rlookup('Q')); + ASSERT_EQ(0b010001U, base64::rlookup('R')); + ASSERT_EQ(0b010010U, base64::rlookup('S')); + ASSERT_EQ(0b010011U, base64::rlookup('T')); + ASSERT_EQ(0b010100U, base64::rlookup('U')); + ASSERT_EQ(0b010101U, base64::rlookup('V')); + ASSERT_EQ(0b010110U, base64::rlookup('W')); + ASSERT_EQ(0b010111U, base64::rlookup('X')); + ASSERT_EQ(0b011000U, base64::rlookup('Y')); + ASSERT_EQ(0b011001U, base64::rlookup('Z')); + ASSERT_EQ(0b011010U, base64::rlookup('a')); + ASSERT_EQ(0b011011U, base64::rlookup('b')); + ASSERT_EQ(0b011100U, base64::rlookup('c')); + ASSERT_EQ(0b011101U, base64::rlookup('d')); + ASSERT_EQ(0b011110U, base64::rlookup('e')); + ASSERT_EQ(0b011111U, base64::rlookup('f')); + ASSERT_EQ(0b100000U, base64::rlookup('g')); + ASSERT_EQ(0b100001U, base64::rlookup('h')); + ASSERT_EQ(0b100010U, base64::rlookup('i')); + ASSERT_EQ(0b100011U, base64::rlookup('j')); + ASSERT_EQ(0b100100U, base64::rlookup('k')); + ASSERT_EQ(0b100101U, base64::rlookup('l')); + ASSERT_EQ(0b100110U, base64::rlookup('m')); + ASSERT_EQ(0b100111U, base64::rlookup('n')); + ASSERT_EQ(0b101000U, base64::rlookup('o')); + ASSERT_EQ(0b101001U, base64::rlookup('p')); + ASSERT_EQ(0b101010U, base64::rlookup('q')); + ASSERT_EQ(0b101011U, base64::rlookup('r')); + ASSERT_EQ(0b101100U, base64::rlookup('s')); + ASSERT_EQ(0b101101U, base64::rlookup('t')); + ASSERT_EQ(0b101110U, base64::rlookup('u')); + ASSERT_EQ(0b101111U, base64::rlookup('v')); + ASSERT_EQ(0b110000U, base64::rlookup('w')); + ASSERT_EQ(0b110001U, base64::rlookup('x')); + ASSERT_EQ(0b110010U, base64::rlookup('y')); + ASSERT_EQ(0b110011U, base64::rlookup('z')); + ASSERT_EQ(0b110100U, base64::rlookup('0')); + ASSERT_EQ(0b110101U, base64::rlookup('1')); + ASSERT_EQ(0b110110U, base64::rlookup('2')); + ASSERT_EQ(0b110111U, base64::rlookup('3')); + ASSERT_EQ(0b111000U, base64::rlookup('4')); + ASSERT_EQ(0b111001U, base64::rlookup('5')); + ASSERT_EQ(0b111010U, base64::rlookup('6')); + ASSERT_EQ(0b111011U, base64::rlookup('7')); + ASSERT_EQ(0b111100U, base64::rlookup('8')); + ASSERT_EQ(0b111101U, base64::rlookup('9')); + ASSERT_EQ(0b111110U, base64::rlookup('+')); + ASSERT_EQ(0b111111U, base64::rlookup('/')); } TEST(Encode, basic) { - ASSERT_EQ("YQ==", base64::encode("a")); - ASSERT_EQ("YWI=", base64::encode("ab")); - ASSERT_EQ("YWJj", base64::encode("abc")); - ASSERT_EQ("aGVsbG8=", base64::encode("hello")); - ASSERT_EQ("dGhpcyBpcyBhIGxvbmcgc2VudGVuY2U=", base64::encode("this is a long sentence")); + ASSERT_EQ("YQ==", base64::encode("a")); + ASSERT_EQ("YWI=", base64::encode("ab")); + ASSERT_EQ("YWJj", base64::encode("abc")); + ASSERT_EQ("aGVsbG8=", base64::encode("hello")); + ASSERT_EQ("dGhpcyBpcyBhIGxvbmcgc2VudGVuY2U=", base64::encode("this is a long sentence")); } TEST(Decode, basic) { - ASSERT_EQ("a", base64::decode("YQ==")); - ASSERT_EQ("ab", base64::decode("YWI=")); - ASSERT_EQ("abc", base64::decode("YWJj")); - ASSERT_EQ("hello", base64::decode("aGVsbG8=")); - ASSERT_EQ("this is a long sentence", base64::decode("dGhpcyBpcyBhIGxvbmcgc2VudGVuY2U=")); - ASSERT_EQ("Welcome to our server dude", base64::decode("V2VsY29tZSB0byBvdXIgc2VydmVyIGR1ZGU=")); + ASSERT_EQ("a", base64::decode("YQ==")); + ASSERT_EQ("ab", base64::decode("YWI=")); + ASSERT_EQ("abc", base64::decode("YWJj")); + ASSERT_EQ("hello", base64::decode("aGVsbG8=")); + ASSERT_EQ("this is a long sentence", base64::decode("dGhpcyBpcyBhIGxvbmcgc2VudGVuY2U=")); + ASSERT_EQ("Welcome to our server dude", base64::decode("V2VsY29tZSB0byBvdXIgc2VydmVyIGR1ZGU=")); } TEST(Failure, truncated) { - ASSERT_THROW(base64::decode("YW="), std::invalid_argument); + ASSERT_THROW(base64::decode("YW="), std::invalid_argument); } TEST(Failure, invalid) { - ASSERT_THROW(base64::decode("?!"), std::invalid_argument); + ASSERT_THROW(base64::decode("?!"), std::invalid_argument); } TEST(Failure, wrong1) { - ASSERT_THROW(base64::decode("=ABC"), std::invalid_argument); + ASSERT_THROW(base64::decode("=ABC"), std::invalid_argument); } TEST(Failure, wrong2) { - ASSERT_THROW(base64::decode("A=BC"), std::invalid_argument); + ASSERT_THROW(base64::decode("A=BC"), std::invalid_argument); } TEST(Failure, wrong3) { - ASSERT_THROW(base64::decode("==BC"), std::invalid_argument); + ASSERT_THROW(base64::decode("==BC"), std::invalid_argument); } TEST(Failure, wrong4) { - ASSERT_THROW(base64::decode("AB=C"), std::invalid_argument); + ASSERT_THROW(base64::decode("AB=C"), std::invalid_argument); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/converter/converter.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/converter/converter.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -30,63 +30,61 @@ #include "converter.h" struct Deleter { - void operator()(iconv_t desc) - { - iconv_close(desc); - } + void operator()(iconv_t desc) + { + iconv_close(desc); + } }; using Iconv = std::unique_ptr<std::remove_pointer<iconv_t>::type, Deleter>; -std::string Converter::convert(const char *from, - const char *to, - const std::string &input) +std::string Converter::convert(const char *from, const char *to, const std::string &input) { - // No conversion if from and to are identical - if (std::strcmp(from, to) == 0) - return input; + // No conversion if from and to are identical + if (std::strcmp(from, to) == 0) + return input; - // Try to open the conversion descriptor - auto cd = iconv_open(to, from); + // Try to open the conversion descriptor + auto cd = iconv_open(to, from); + + if (cd == (iconv_t)-1) + throw std::invalid_argument(std::strerror(errno)); - if (cd == (iconv_t)-1) - throw std::invalid_argument(std::strerror(errno)); + Iconv cv(cd); + std::size_t insize(input.size()); + std::size_t outsize(insize); + std::vector<char> result(insize + 1); - Iconv cv(cd); - std::size_t insize(input.size()); - std::size_t outsize(insize); - std::vector<char> result(insize + 1); + auto *b = &input[0]; + auto *p = &result[0]; - auto *b = &input[0]; - auto *p = &result[0]; - - while (insize > 0) { - /* Convert */ - auto r = iconv(cv.get(), &b, &insize, &p, &outsize); + while (insize > 0) { + /* Convert */ + auto r = iconv(cv.get(), &b, &insize, &p, &outsize); - if (r == (size_t)-1) { - switch (errno) { - case EBADF: - case EILSEQ: - case EINVAL: - throw std::invalid_argument(std::strerror(errno)); - case E2BIG: - /* - * Here, we need to reallocate more data because the output - * string may need more space. - * - * We use 16 as an optimistic value. - */ + if (r == (size_t)-1) { + switch (errno) { + case EBADF: + case EILSEQ: + case EINVAL: + throw std::invalid_argument(std::strerror(errno)); + case E2BIG: + /* + * Here, we need to reallocate more data because the output + * string may need more space. + * + * We use 16 as an optimistic value. + */ - result.reserve(result.size() + 16 + 1); - p = &result[result.size()]; - outsize += 16; - default: - break; - } - } + result.reserve(result.size() + 16 + 1); + p = &result[result.size()]; + outsize += 16; + default: + break; + } + } - } + } - return std::string(&result[0], (p - &result[0])); + return std::string(&result[0], (p - &result[0])); }
--- a/modules/converter/converter.h Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/converter/converter.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* - * Converter.h -- iconv based converter + * converter.h -- iconv based converter * - * Copyright (c) 2013-2015 David Demelier <markand@malikania.fr> + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,34 +16,31 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef _CONVERTER_H_ -#define _CONVERTER_H_ +#ifndef CONVERTER_H +#define CONVERTER_H /** - * @file Converter.h - * @brief Converter using libiconv + * \file converter.h + * \brief Converter using libiconv. */ #include <string> /** - * @class Converter - * @brief Convert string between different encodings + * \brief Convert string between different encodings */ class Converter { public: - /** - * Convert the string into a different encoding. - * - * @param from the from encoding - * @param to the destination encoding - * @param input the string to convert - * @return the converted string - * @throw std::invalid_argument on invalid sequence - */ - static std::string convert(const char *from, - const char *to, - const std::string &input); + /** + * Convert the string into a different encoding. + * + * \param from the from encoding + * \param to the destination encoding + * \param input the string to convert + * \return the converted string + * \throw std::invalid_argument on invalid sequence + */ + static std::string convert(const char *from, const char *to, const std::string &input); }; -#endif // !_CONVERTER_H_ +#endif // !CONVERTER_H
--- a/modules/date/date.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/date/date.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -20,31 +20,31 @@ Date::Date() { - m_timestamp = time(nullptr); + m_timestamp = time(nullptr); } Date::Date(time_t timestamp) { - m_timestamp = timestamp; + m_timestamp = timestamp; } std::string Date::format(const std::string &format) { - char buffer[512]; - struct tm *tm; + char buffer[512]; + struct tm *tm; - tm = localtime(&m_timestamp); - strftime(buffer, sizeof (buffer), format.c_str(), tm); + tm = localtime(&m_timestamp); + strftime(buffer, sizeof (buffer), format.c_str(), tm); - return std::string(buffer); + return std::string(buffer); } bool operator==(const Date &d1, const Date &d2) { - return d1.timestamp() == d2.timestamp(); + return d1.timestamp() == d2.timestamp(); } bool operator<=(const Date &d1, const Date &d2) { - return d1.timestamp() <= d2.timestamp(); + return d1.timestamp() <= d2.timestamp(); }
--- a/modules/date/date.h Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/date/date.h Wed Jun 15 13:13:26 2016 +0200 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef _DATE_H_ -#define _DATE_H_ +#ifndef DATE_HPP +#define DATE_HPP /** - * @file date.h - * @brief Basic date management. + * \file date.h + * \brief Basic date management. */ #include <cstdint> @@ -29,62 +29,62 @@ #include <string> /** - * @class Date - * @brief Basic date class and format. + * \class Date + * \brief Basic date class and format. */ class Date { private: - time_t m_timestamp; + time_t m_timestamp; public: - /** - * Default constructor to the current date. - */ - Date(); + /** + * Default constructor to the current date. + */ + Date(); - /** - * Date with specific timestamp. - * - * @param timestamp the timestamp - */ - Date(time_t timestamp); + /** + * Date with specific timestamp. + * + * \param timestamp the timestamp + */ + Date(time_t timestamp); - /** - * Get the timestamp. - * - * @return the timestamp - */ - inline time_t timestamp() const noexcept - { - return m_timestamp; - } + /** + * Get the timestamp. + * + * \return the timestamp + */ + inline time_t timestamp() const noexcept + { + return m_timestamp; + } - /** - * Format the current that in the specified format, - * see strftime(3) for patterns. - * - * @param format the format - * @return the date formated - */ - std::string format(const std::string &format); + /** + * Format the current that in the specified format, + * see strftime(3) for patterns. + * + * \param format the format + * \return the date formated + */ + std::string format(const std::string &format); }; /** * Check is two dates are identical. * - * @param d1 the first date - * @param d2 the second date - * @return true if same + * \param d1 the first date + * \param d2 the second date + * \return true if same */ bool operator==(const Date &d1, const Date &d2); /** * Check is a date is less or equal the second date. * - * @param d1 the first date - * @param d2 the second date - * @return true if d1 <= d2 + * \param d1 the first date + * \param d2 the second date + * \return true if d1 <= d2 */ bool operator<=(const Date &d1, const Date &d2); -#endif // !_DATE_H_ +#endif // !DATE_HPP
--- a/modules/dynlib/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/dynlib/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -20,10 +20,10 @@ target_include_directories(dynlib-plugin PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) code_define_module( - NAME dynlib - SOURCES dynlib.hpp - LIBRARIES $<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:dl> - FLAGS PLUGIN=\"$<TARGET_FILE:dynlib-plugin>\" + NAME dynlib + SOURCES dynlib.hpp + LIBRARIES $<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:dl> + FLAGS PLUGIN=\"$<TARGET_FILE:dynlib-plugin>\" ) add_dependencies(test-dynlib dynlib-plugin)
--- a/modules/dynlib/doc/mainpage.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/dynlib/doc/mainpage.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -29,16 +29,16 @@ * * int main() * { - * try { - * Dynlib library("./plugin.so"); + * try { + * Dynlib library("./plugin.so"); * - * HelloFunc hello = library.sym<HelloFunc>("say_hello"); - * hello("Test"); - * } catch (const std::exception &error) { - * std::cerr << error.what() << std::endl; - * } + * HelloFunc hello = library.sym<HelloFunc>("say_hello"); + * hello("Test"); + * } catch (const std::exception &error) { + * std::cerr << error.what() << std::endl; + * } * - * return 0; + * return 0; * } * ```` * @@ -57,7 +57,7 @@ * * DYNLIB_EXPORT void say_hello() * { - * std::cout << "Hello from the plugin!" << std::endl; + * std::cout << "Hello from the plugin!" << std::endl; * } * ```` */
--- a/modules/dynlib/dynlib.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/dynlib/dynlib.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -115,16 +115,16 @@ * * int main() * { - * try { - * Dynlib dso("./plugin" DYNLIB_SUFFIX); + * try { + * Dynlib dso("./plugin" DYNLIB_SUFFIX); * - * dso.sym<PluginLoad>("plugin_load")(); - * dso.sym<PluginUnload>("plugin_unload")(); - * } catch (const std::exception &ex) { - * std::cerr << ex.what() << std::endl; - * } + * dso.sym<PluginLoad>("plugin_load")(); + * dso.sym<PluginUnload>("plugin_unload")(); + * } catch (const std::exception &ex) { + * std::cerr << ex.what() << std::endl; + * } * - * return 0; + * return 0; * } * ```` * @@ -156,7 +156,7 @@ * \endcode */ #if defined(_WIN32) -# define DYNLIB_EXPORT __declspec(dllexport) +# define DYNLIB_EXPORT __declspec(dllexport) #else # define DYNLIB_EXPORT #endif @@ -189,80 +189,80 @@ class Dynlib { private: #if defined(_WIN32) - using Handle = HMODULE; - using Sym = FARPROC; + using Handle = HMODULE; + using Sym = FARPROC; #else - using Handle = void *; - using Sym = void *; + using Handle = void *; + using Sym = void *; #endif public: - /** - * \brief Policy for symbol resolution. - */ - enum Policy { - Immediately, //!< load symbols immediately - Lazy //!< load symbols when needed - }; + /** + * \brief Policy for symbol resolution. + */ + enum Policy { + Immediately, //!< load symbols immediately + Lazy //!< load symbols when needed + }; private: - Handle m_handle; + Handle m_handle; - Dynlib(const Dynlib &) = delete; - Dynlib &operator=(const Dynlib &) = delete; + Dynlib(const Dynlib &) = delete; + Dynlib &operator=(const Dynlib &) = delete; - Dynlib(Dynlib &&) = delete; - Dynlib &operator=(Dynlib &&) = delete; + Dynlib(Dynlib &&) = delete; + Dynlib &operator=(Dynlib &&) = delete; #if defined(_WIN32) - std::string error() - { - LPSTR error = nullptr; - std::string errmsg; + std::string error() + { + LPSTR error = nullptr; + std::string errmsg; - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&error, 0, NULL); + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&error, 0, NULL); - if (error) { - errmsg = std::string(error); - LocalFree(error); - } + if (error) { + errmsg = std::string(error); + LocalFree(error); + } - return errmsg; - } + return errmsg; + } #endif public: - /** - * Constructor to load a shared module. - * - * \param path the absolute path - * \param policy the policy to load - * \throw std::runtime_error on error - */ - Dynlib(const std::string &path, Policy policy = Immediately); + /** + * Constructor to load a shared module. + * + * \param path the absolute path + * \param policy the policy to load + * \throw std::runtime_error on error + */ + Dynlib(const std::string &path, Policy policy = Immediately); - /** - * Close the library automatically. - */ - ~Dynlib(); + /** + * Close the library automatically. + */ + ~Dynlib(); - /** - * Get a symbol from the library. - * - * On some platforms the symbol must be manually exported. - * - * \param name the symbol - * \return the symbol - * \throw std::runtime_error on error - * \see DYNLIB_EXPORT - */ - template <typename T> - T sym(const std::string &name); + /** + * Get a symbol from the library. + * + * On some platforms the symbol must be manually exported. + * + * \param name the symbol + * \return the symbol + * \throw std::runtime_error on error + * \see DYNLIB_EXPORT + */ + template <typename T> + T sym(const std::string &name); }; #if defined(_WIN32) @@ -274,27 +274,27 @@ inline Dynlib::Dynlib(const std::string &path, Policy) { - m_handle = LoadLibraryA(path.c_str()); + m_handle = LoadLibraryA(path.c_str()); - if (m_handle == nullptr) - throw std::runtime_error(error()); + if (m_handle == nullptr) + throw std::runtime_error(error()); } inline Dynlib::~Dynlib() { - FreeLibrary(m_handle); - m_handle = nullptr; + FreeLibrary(m_handle); + m_handle = nullptr; } template <typename T> T Dynlib::sym(const std::string &name) { - Sym sym = GetProcAddress(m_handle, name.c_str()); + Sym sym = GetProcAddress(m_handle, name.c_str()); - if (sym == nullptr) - throw std::runtime_error(error()); + if (sym == nullptr) + throw std::runtime_error(error()); - return reinterpret_cast<T>(sym); + return reinterpret_cast<T>(sym); } #else @@ -306,27 +306,27 @@ inline Dynlib::Dynlib(const std::string &path, Policy policy) { - m_handle = dlopen(path.c_str(), policy == Immediately ? RTLD_NOW : RTLD_LAZY); + m_handle = dlopen(path.c_str(), policy == Immediately ? RTLD_NOW : RTLD_LAZY); - if (m_handle == nullptr) - throw std::runtime_error(dlerror()); + if (m_handle == nullptr) + throw std::runtime_error(dlerror()); } inline Dynlib::~Dynlib() { - dlclose(m_handle); - m_handle = nullptr; + dlclose(m_handle); + m_handle = nullptr; } template <typename T> T Dynlib::sym(const std::string &name) { - Sym sym = dlsym(m_handle, name.c_str()); + Sym sym = dlsym(m_handle, name.c_str()); - if (sym == nullptr) - throw std::runtime_error(dlerror()); + if (sym == nullptr) + throw std::runtime_error(dlerror()); - return reinterpret_cast<T>(sym); + return reinterpret_cast<T>(sym); } #endif
--- a/modules/dynlib/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/dynlib/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -26,31 +26,31 @@ TEST(Basic, initialize) { - try { - Dynlib library(PLUGIN); - Initialize init = library.sym<Initialize>("initialize"); + try { + Dynlib library(PLUGIN); + Initialize init = library.sym<Initialize>("initialize"); - std::string expected("Hello World"); - std::string result; + std::string expected("Hello World"); + std::string result; - init(result); + init(result); - ASSERT_EQ(expected, result); - } catch (const std::runtime_error &error) { - FAIL() << error.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::runtime_error &error) { + FAIL() << error.what(); + } } TEST(Basic, absent) { - Dynlib library(PLUGIN); + Dynlib library(PLUGIN); - ASSERT_THROW(library.sym<Initialize>("initialize_typo"), std::runtime_error); + ASSERT_THROW(library.sym<Initialize>("initialize_typo"), std::runtime_error); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/dynlib/test/plugin.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/dynlib/test/plugin.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -6,7 +6,7 @@ void DYNLIB_EXPORT initialize(std::string &result) { - result = "Hello World"; + result = "Hello World"; } }
--- a/modules/elapsed-timer/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/elapsed-timer/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -17,6 +17,6 @@ # code_define_module( - NAME elapsed-timer - SOURCES elapsed-timer.hpp -) \ No newline at end of file + NAME elapsed-timer + SOURCES elapsed-timer.hpp +)
--- a/modules/elapsed-timer/elapsed-timer.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/elapsed-timer/elapsed-timer.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -34,70 +34,70 @@ */ class ElapsedTimer { private: - using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; + using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; - TimePoint m_last; - bool m_paused{false}; - unsigned m_elapsed{0}; + TimePoint m_last; + bool m_paused{false}; + unsigned m_elapsed{0}; public: - /** - * Construct the elapsed timer, start counting. - */ - inline ElapsedTimer() noexcept - : m_last(std::chrono::high_resolution_clock::now()) - { - } + /** + * Construct the elapsed timer, start counting. + */ + inline ElapsedTimer() noexcept + : m_last(std::chrono::high_resolution_clock::now()) + { + } - /** - * Put the timer on pause, the already elapsed time is stored. - */ - inline void pause() noexcept - { - /* - * When we put the timer on pause, do not forget to set the already - * elapsed time. - */ - elapsed(); - m_paused = true; - } + /** + * Put the timer on pause, the already elapsed time is stored. + */ + inline void pause() noexcept + { + /* + * When we put the timer on pause, do not forget to set the already + * elapsed time. + */ + elapsed(); + m_paused = true; + } - /** - * Restart the timer, does not reset it. - */ - inline void restart() noexcept - { - m_paused = false; - m_last = std::chrono::high_resolution_clock::now(); - } + /** + * Restart the timer, does not reset it. + */ + inline void restart() noexcept + { + m_paused = false; + m_last = std::chrono::high_resolution_clock::now(); + } - /** - * Reset the timer to 0. - */ - inline void reset() noexcept - { - m_elapsed = 0; - m_last = std::chrono::high_resolution_clock::now(); - } + /** + * Reset the timer to 0. + */ + inline void reset() noexcept + { + m_elapsed = 0; + m_last = std::chrono::high_resolution_clock::now(); + } - /** - * Get the number of elapsed milliseconds. - * - * \return the milliseconds - */ - inline unsigned elapsed() noexcept - { - using std::chrono::duration_cast; - using std::chrono::high_resolution_clock; - using std::chrono::milliseconds; + /** + * Get the number of elapsed milliseconds. + * + * \return the milliseconds + */ + inline unsigned elapsed() noexcept + { + using std::chrono::duration_cast; + using std::chrono::high_resolution_clock; + using std::chrono::milliseconds; - if (!m_paused) { - m_elapsed += duration_cast<milliseconds>(high_resolution_clock::now() - m_last).count(); - m_last = high_resolution_clock::now(); - } + if (!m_paused) { + m_elapsed += duration_cast<milliseconds>(high_resolution_clock::now() - m_last).count(); + m_last = high_resolution_clock::now(); + } - return m_elapsed; - } + return m_elapsed; + } }; #endif // !ELAPSED_TIMER_HPP
--- a/modules/elapsed-timer/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/elapsed-timer/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -26,29 +26,29 @@ TEST(TestElapsedTimer, standard) { - ElapsedTimer timer; + ElapsedTimer timer; - std::this_thread::sleep_for(300ms); + std::this_thread::sleep_for(300ms); - ASSERT_GE(timer.elapsed(), 250U); - ASSERT_LE(timer.elapsed(), 350U); + ASSERT_GE(timer.elapsed(), 250U); + ASSERT_LE(timer.elapsed(), 350U); } TEST(TestElapsedTimer, reset) { - ElapsedTimer timer; + ElapsedTimer timer; - std::this_thread::sleep_for(300ms); + std::this_thread::sleep_for(300ms); - timer.reset(); + timer.reset(); - ASSERT_LE(timer.elapsed(), 100U); + ASSERT_LE(timer.elapsed(), 100U); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/fs/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/fs/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -25,8 +25,8 @@ file(WRITE ${CMAKE_BINARY_DIR}/root/level-1/file-2.txt "World") code_define_module( - NAME fs - SOURCES fs.cpp fs.hpp - LIBRARIES $<$<BOOL:${WIN32}>:shlwapi> - FLAGS DIRECTORY=\"${CMAKE_BINARY_DIR}/root/\" -) \ No newline at end of file + NAME fs + SOURCES fs.cpp fs.hpp + LIBRARIES $<$<BOOL:${WIN32}>:shlwapi> + FLAGS DIRECTORY=\"${CMAKE_BINARY_DIR}/root/\" +)
--- a/modules/fs/doc/mainpage.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/fs/doc/mainpage.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -35,14 +35,14 @@ * * int main() * { - * try { - * for (const fs::Entry &e : fs::readdir("jokes")) - * std::cout << "entry: " << e.name << std::endl; - * } catch (const std::exception &error) { - * std::cerr << error.what() << std::endl; - * } + * try { + * for (const fs::Entry &e : fs::readdir("jokes")) + * std::cout << "entry: " << e.name << std::endl; + * } catch (const std::exception &error) { + * std::cerr << error.what() << std::endl; + * } * - * return 0; + * return 0; * } * ```` * @@ -55,13 +55,13 @@ * * int main() * { - * try { - * fs::mkdir("tmp"); - * } catch (const std::exception &error) { - * std::cerr << error.what() << std::endl; - * } + * try { + * fs::mkdir("tmp"); + * } catch (const std::exception &error) { + * std::cerr << error.what() << std::endl; + * } * - * return 0; + * return 0; * } * ```` */
--- a/modules/fs/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/fs/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -24,171 +24,171 @@ TEST(Symbols, entry) { - return; + return; - FAIL() << "must not go here"; + FAIL() << "must not go here"; - fs::Entry e1, e2; + fs::Entry e1, e2; - (void)(e1 == e2); - (void)(e1 != e2); + (void)(e1 == e2); + (void)(e1 != e2); } TEST(Symbols, all) { - return; + return; - FAIL() << "must not go here"; + FAIL() << "must not go here"; - (void)fs::separator(); - (void)fs::clean(""); - (void)fs::baseName(""); - (void)fs::dirName(""); - (void)fs::stat(""); - (void)fs::exists(""); - (void)fs::isAbsolute(""); - (void)fs::isRelative(""); - (void)fs::isReadable(""); - (void)fs::isWritable(""); - (void)fs::isFile(""); - (void)fs::isDirectory(""); - (void)fs::isSymlink(""); - (void)fs::readdir(""); - (void)fs::mkdir(""); - (void)fs::rmdir(""); - (void)fs::cwd(); + (void)fs::separator(); + (void)fs::clean(""); + (void)fs::baseName(""); + (void)fs::dirName(""); + (void)fs::stat(""); + (void)fs::exists(""); + (void)fs::isAbsolute(""); + (void)fs::isRelative(""); + (void)fs::isReadable(""); + (void)fs::isWritable(""); + (void)fs::isFile(""); + (void)fs::isDirectory(""); + (void)fs::isSymlink(""); + (void)fs::readdir(""); + (void)fs::mkdir(""); + (void)fs::rmdir(""); + (void)fs::cwd(); } TEST(Filter, withDot) { - try { - bool dot(false); - bool dotdot(false); + try { + bool dot(false); + bool dotdot(false); - for (const auto &entry : fs::readdir(".", fs::Dot)) { - if (entry.name == ".") - dot = true; - if (entry.name == "..") - dotdot = true; - } + for (const auto &entry : fs::readdir(".", fs::Dot)) { + if (entry.name == ".") + dot = true; + if (entry.name == "..") + dotdot = true; + } - ASSERT_TRUE(dot); - ASSERT_FALSE(dotdot); - } catch (const std::exception &error) { - FAIL() << error.what(); - } + ASSERT_TRUE(dot); + ASSERT_FALSE(dotdot); + } catch (const std::exception &error) { + FAIL() << error.what(); + } } TEST(Filter, withDotDot) { - try { - bool dot(false); - bool dotdot(false); + try { + bool dot(false); + bool dotdot(false); - for (const auto &entry : fs::readdir(".", fs::DotDot)) { - if (entry.name == ".") - dot = true; - if (entry.name == "..") - dotdot = true; - } + for (const auto &entry : fs::readdir(".", fs::DotDot)) { + if (entry.name == ".") + dot = true; + if (entry.name == "..") + dotdot = true; + } - ASSERT_FALSE(dot); - ASSERT_TRUE(dotdot); - } catch (const std::exception &error) { - FAIL() << error.what(); - } + ASSERT_FALSE(dot); + ASSERT_TRUE(dotdot); + } catch (const std::exception &error) { + FAIL() << error.what(); + } } TEST(Filter, withBothDots) { - try { - bool dot(false); - bool dotdot(false); + try { + bool dot(false); + bool dotdot(false); - for (const auto &entry : fs::readdir(".", fs::Dot | fs::DotDot)) { - if (entry.name == ".") - dot = true; - if (entry.name == "..") - dotdot = true; - } + for (const auto &entry : fs::readdir(".", fs::Dot | fs::DotDot)) { + if (entry.name == ".") + dot = true; + if (entry.name == "..") + dotdot = true; + } - ASSERT_TRUE(dot); - ASSERT_TRUE(dotdot); - } catch (const std::exception &error) { - FAIL() << error.what(); - } + ASSERT_TRUE(dot); + ASSERT_TRUE(dotdot); + } catch (const std::exception &error) { + FAIL() << error.what(); + } } TEST(Filter, withoutDots) { - try { - bool dot(false); - bool dotdot(false); + try { + bool dot(false); + bool dotdot(false); - for (const auto &entry : fs::readdir(".")) { - if (entry.name == ".") - dot = true; - if (entry.name == "..") - dotdot = true; - } + for (const auto &entry : fs::readdir(".")) { + if (entry.name == ".") + dot = true; + if (entry.name == "..") + dotdot = true; + } - ASSERT_FALSE(dot); - ASSERT_FALSE(dotdot); - } catch (const std::exception &error) { - FAIL() << error.what(); - } + ASSERT_FALSE(dot); + ASSERT_FALSE(dotdot); + } catch (const std::exception &error) { + FAIL() << error.what(); + } } TEST(Exists, yes) { - ASSERT_TRUE(fs::exists(DIRECTORY "file-1.txt")); + ASSERT_TRUE(fs::exists(DIRECTORY "file-1.txt")); } TEST(Exists, no) { - ASSERT_FALSE(fs::exists(DIRECTORY "does not exists")); + ASSERT_FALSE(fs::exists(DIRECTORY "does not exists")); } TEST(IsFile, yes) { - ASSERT_TRUE(fs::isFile(__FILE__)); + ASSERT_TRUE(fs::isFile(__FILE__)); } TEST(IsFile, no) { - ASSERT_FALSE(fs::isFile(DIRECTORY)); + ASSERT_FALSE(fs::isFile(DIRECTORY)); } TEST(IsDirectory, yes) { - ASSERT_TRUE(fs::isDirectory(DIRECTORY)); + ASSERT_TRUE(fs::isDirectory(DIRECTORY)); } TEST(IsDirectory, no) { - ASSERT_FALSE(fs::isDirectory(__FILE__)); + ASSERT_FALSE(fs::isDirectory(__FILE__)); } TEST(RemoveDirectory, basic) { - try { - std::string path = DIRECTORY "mkdir-test"; + try { + std::string path = DIRECTORY "mkdir-test"; - fs::mkdir(path); + fs::mkdir(path); - ASSERT_TRUE(fs::isDirectory(path)); + ASSERT_TRUE(fs::isDirectory(path)); - fs::rmdir(path); + fs::rmdir(path); - ASSERT_FALSE(fs::exists(path)); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_FALSE(fs::exists(path)); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/hash/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/hash/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -19,10 +19,10 @@ find_package(OpenSSL) if (OPENSSL_FOUND) - code_define_module( - NAME hash - SOURCES hash.hpp - LIBRARIES ${OPENSSL_LIBRARIES} - INCLUDES ${OPENSSL_INCLUDE_DIR} - ) -endif () \ No newline at end of file + code_define_module( + NAME hash + SOURCES hash.hpp + LIBRARIES ${OPENSSL_LIBRARIES} + INCLUDES ${OPENSSL_INCLUDE_DIR} + ) +endif ()
--- a/modules/hash/hash.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/hash/hash.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -22,7 +22,7 @@ /** * \file hash.hpp * \brief Hash functions. - * \author David Demelier <markand@malikania.fr> + * \author David Demelier <markand\malikania.fr> */ /** @@ -64,28 +64,28 @@ template <typename Context, size_t Length, typename InputIt> inline std::string convert(InputIt it, InputIt end, Init<Context> init, Update<Context> update, Final<Context> finalize) { - unsigned char digest[Length] = { 0 }; - char hash[Length * 2 + 1]; - char buf[HASH_BUFFER_SIZE]; + unsigned char digest[Length] = { 0 }; + char hash[Length * 2 + 1]; + char buf[HASH_BUFFER_SIZE]; - Context ctx; - init(&ctx); + Context ctx; + init(&ctx); - while (it != end) { - unsigned i; + while (it != end) { + unsigned i; - for (i = 0; it != end && i < HASH_BUFFER_SIZE; ++i) - buf[i] = *it++; + for (i = 0; it != end && i < HASH_BUFFER_SIZE; ++i) + buf[i] = *it++; - update(&ctx, buf, i); - } + update(&ctx, buf, i); + } - finalize(digest, &ctx); - - for (unsigned long i = 0; i < Length; i++) - std::snprintf(&hash[i * 2], 2 + 1, "%02x", (unsigned int)digest[i]); + finalize(digest, &ctx); - return std::string(hash); + for (unsigned long i = 0; i < Length; i++) + std::snprintf(&hash[i * 2], 2 + 1, "%02x", (unsigned int)digest[i]); + + return std::string(hash); } } // !namespace @@ -99,10 +99,10 @@ * \brief The scheme to use. */ enum Scheme { - Md5, //!< MD5 - Sha1, //!< SHA-1 - Sha256, //!< SHA-256 - Sha512 //!< SHA-512 + Md5, //!< MD5 + Sha1, //!< SHA-1 + Sha256, //!< SHA-256 + Sha512 //!< SHA-512 }; /** @@ -116,28 +116,28 @@ template <typename InputIt> inline std::string toString(Scheme scheme, InputIt it, InputIt end) { - assert(scheme >= Scheme::Md5 && scheme <= Scheme::Sha512); + assert(scheme >= Scheme::Md5 && scheme <= Scheme::Sha512); - std::string result; + std::string result; - switch (scheme) { - case Scheme::Md5: - result = detail::convert<MD5_CTX, MD5_DIGEST_LENGTH>(it, end, MD5_Init, MD5_Update, MD5_Final); - break; - case Scheme::Sha1: - result = detail::convert<SHA_CTX, SHA_DIGEST_LENGTH>(it, end, SHA1_Init, SHA1_Update, SHA1_Final);; - break; - case Scheme::Sha256: - result = detail::convert<SHA256_CTX, SHA256_DIGEST_LENGTH>(it, end, SHA256_Init, SHA256_Update, SHA256_Final); - break; - case Scheme::Sha512: - result = detail::convert<SHA512_CTX, SHA512_DIGEST_LENGTH>(it, end, SHA512_Init, SHA512_Update, SHA512_Final); - break; - default: - break; - } + switch (scheme) { + case Scheme::Md5: + result = detail::convert<MD5_CTX, MD5_DIGEST_LENGTH>(it, end, MD5_Init, MD5_Update, MD5_Final); + break; + case Scheme::Sha1: + result = detail::convert<SHA_CTX, SHA_DIGEST_LENGTH>(it, end, SHA1_Init, SHA1_Update, SHA1_Final);; + break; + case Scheme::Sha256: + result = detail::convert<SHA256_CTX, SHA256_DIGEST_LENGTH>(it, end, SHA256_Init, SHA256_Update, SHA256_Final); + break; + case Scheme::Sha512: + result = detail::convert<SHA512_CTX, SHA512_DIGEST_LENGTH>(it, end, SHA512_Init, SHA512_Update, SHA512_Final); + break; + default: + break; + } - return result; + return result; } /** @@ -149,7 +149,7 @@ */ inline std::string toString(Scheme scheme, std::istream &input) { - return toString(scheme, std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()); + return toString(scheme, std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()); } /** @@ -161,7 +161,7 @@ */ inline std::string toString(Scheme scheme, const std::string &input) { - return toString(scheme, input.begin(), input.end()); + return toString(scheme, input.begin(), input.end()); } /** @@ -172,7 +172,7 @@ */ inline std::string md5(const std::string &input) { - return toString(Scheme::Md5, input); + return toString(Scheme::Md5, input); } /** @@ -183,7 +183,7 @@ */ inline std::string md5(std::istream &input) { - return toString(Scheme::Md5, input); + return toString(Scheme::Md5, input); } /** @@ -194,7 +194,7 @@ */ inline std::string sha1(const std::string &input) { - return toString(Scheme::Sha1, input); + return toString(Scheme::Sha1, input); } /** @@ -205,7 +205,7 @@ */ inline std::string sha1(std::istream &input) { - return toString(Scheme::Sha1, input); + return toString(Scheme::Sha1, input); } /** @@ -216,7 +216,7 @@ */ inline std::string sha256(const std::string &input) { - return toString(Scheme::Sha256, input); + return toString(Scheme::Sha256, input); } /** @@ -227,7 +227,7 @@ */ inline std::string sha256(std::istream &input) { - return toString(Scheme::Sha256, input); + return toString(Scheme::Sha256, input); } /** @@ -238,7 +238,7 @@ */ inline std::string sha512(const std::string &input) { - return toString(Scheme::Sha512, input); + return toString(Scheme::Sha512, input); } /** @@ -249,7 +249,7 @@ */ inline std::string sha512(std::istream &input) { - return toString(Scheme::Sha512, input); + return toString(Scheme::Sha512, input); } } // !hash
--- a/modules/hash/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/hash/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -26,39 +26,39 @@ TEST(Hash, md5) { - std::string expected = "b10a8db164e0754105b7a99be72e3fe5"; - std::string output = hash::md5("Hello World"); + std::string expected = "b10a8db164e0754105b7a99be72e3fe5"; + std::string output = hash::md5("Hello World"); - ASSERT_EQ(expected, output); + ASSERT_EQ(expected, output); } TEST(Hash, sha1) { - std::string expected = "0a4d55a8d778e5022fab701977c5d840bbc486d0"; - std::string output = hash::sha1("Hello World"); + std::string expected = "0a4d55a8d778e5022fab701977c5d840bbc486d0"; + std::string output = hash::sha1("Hello World"); - ASSERT_EQ(expected, output); + ASSERT_EQ(expected, output); } TEST(Hash, sha256) { - std::string expected = "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"; - std::string output = hash::sha256("Hello World"); + std::string expected = "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"; + std::string output = hash::sha256("Hello World"); - ASSERT_EQ(expected, output); + ASSERT_EQ(expected, output); } TEST(Hash, sha512) { - std::string expected = "2c74fd17edafd80e8447b0d46741ee243b7eb74dd2149a0ab1b9246fb30382f27e853d8585719e0e67cbda0daa8f51671064615d645ae27acb15bfb1447f459b"; - std::string output = hash::sha512("Hello World"); + std::string expected = "2c74fd17edafd80e8447b0d46741ee243b7eb74dd2149a0ab1b9246fb30382f27e853d8585719e0e67cbda0daa8f51671064615d645ae27acb15bfb1447f459b"; + std::string output = hash::sha512("Hello World"); - ASSERT_EQ(expected, output); + ASSERT_EQ(expected, output); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/ini/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/ini/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -17,8 +17,8 @@ # code_define_module( - NAME ini - SOURCES ini.cpp ini.hpp - LIBRARIES $<$<BOOL:${WIN32}>:shlwapi> - FLAGS DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}/test/configs/\" -) \ No newline at end of file + NAME ini + SOURCES ini.cpp ini.hpp + LIBRARIES $<$<BOOL:${WIN32}>:shlwapi> + FLAGS DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}/test/configs/\" +)
--- a/modules/ini/ini.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/ini/ini.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -41,278 +41,278 @@ inline bool isAbsolute(const std::string &path) noexcept { #if defined(_WIN32) - return !PathIsRelative(path.c_str()); + return !PathIsRelative(path.c_str()); #else - return path.size() > 0 && path[0] == '/'; + return path.size() > 0 && path[0] == '/'; #endif } inline bool isQuote(char c) noexcept { - return c == '\'' || c == '"'; + return c == '\'' || c == '"'; } inline bool isSpace(char c) noexcept { - /* Custom version because std::isspace includes \n as space */ - return c == ' ' || c == '\t'; + /* Custom version because std::isspace includes \n as space */ + return c == ' ' || c == '\t'; } inline bool isList(char c) noexcept { - return c == '(' || c == ')' || c == ','; + return c == '(' || c == ')' || c == ','; } inline bool isReserved(char c) noexcept { - return isList(c) || isQuote(c) || c == '[' || c == ']' || c == '@' || c == '#' || c == '='; + return isList(c) || isQuote(c) || c == '[' || c == ']' || c == '@' || c == '#' || c == '='; } void analyseLine(int &line, int &column, StreamIterator &it) noexcept { - assert(*it == '\n'); + assert(*it == '\n'); - ++ line; - ++ it; - column = 0; + ++ line; + ++ it; + column = 0; } void analyseComment(int &column, StreamIterator &it, StreamIterator end) noexcept { - assert(*it == '#'); + assert(*it == '#'); - while (it != end && *it != '\n') { - ++ column; - ++ it; - } + while (it != end && *it != '\n') { + ++ column; + ++ it; + } } void analyseSpaces(int &column, StreamIterator &it, StreamIterator end) noexcept { - assert(isSpace(*it)); + assert(isSpace(*it)); - while (it != end && isSpace(*it)) { - ++ column; - ++ it; - } + while (it != end && isSpace(*it)) { + ++ column; + ++ it; + } } void analyseList(Tokens &list, int line, int &column, StreamIterator &it) noexcept { - assert(isList(*it)); + assert(isList(*it)); - switch (*it++) { - case '(': - list.emplace_back(Token::ListBegin, line, column++); - break; - case ')': - list.emplace_back(Token::ListEnd, line, column++); - break; - case ',': - list.emplace_back(Token::Comma, line, column++); - break; - default: - break; - } + switch (*it++) { + case '(': + list.emplace_back(Token::ListBegin, line, column++); + break; + case ')': + list.emplace_back(Token::ListEnd, line, column++); + break; + case ',': + list.emplace_back(Token::Comma, line, column++); + break; + default: + break; + } } void analyseSection(Tokens &list, int &line, int &column, StreamIterator &it, StreamIterator end) { - assert(*it == '['); + assert(*it == '['); - std::string value; - int save = column; + std::string value; + int save = column; - // Read section name. - ++ it; - while (it != end && *it != ']') { - if (*it == '\n') - throw Error(line, column, "section not terminated, missing ']'"); - if (isReserved(*it)) - throw Error(line, column, "section name expected after '[', got '" + std::string(1, *it) + "'"); + // Read section name. + ++ it; + while (it != end && *it != ']') { + if (*it == '\n') + throw Error(line, column, "section not terminated, missing ']'"); + if (isReserved(*it)) + throw Error(line, column, "section name expected after '[', got '" + std::string(1, *it) + "'"); - ++ column; - value += *it++; - } + ++ column; + value += *it++; + } - if (it == end) - throw Error(line, column, "section name expected after '[', got <EOF>"); - if (value.empty()) - throw Error(line, column, "empty section name"); + if (it == end) + throw Error(line, column, "section name expected after '[', got <EOF>"); + if (value.empty()) + throw Error(line, column, "empty section name"); - // Remove ']'. - ++ it; + // Remove ']'. + ++ it; - list.emplace_back(Token::Section, line, save, std::move(value)); + list.emplace_back(Token::Section, line, save, std::move(value)); } void analyseAssign(Tokens &list, int &line, int &column, StreamIterator &it) { - assert(*it == '='); + assert(*it == '='); - list.push_back({ Token::Assign, line, column++ }); - ++ it; + list.push_back({ Token::Assign, line, column++ }); + ++ it; } void analyseQuotedWord(Tokens &list, int &line, int &column, StreamIterator &it, StreamIterator end) { - std::string value; - int save = column; - char quote = *it++; + std::string value; + int save = column; + char quote = *it++; - while (it != end && *it != quote) { - // TODO: escape sequence - ++ column; - value += *it++; - } + while (it != end && *it != quote) { + // TODO: escape sequence + ++ column; + value += *it++; + } - if (it == end) - throw Error(line, column, "undisclosed '" + std::string(1, quote) + "', got <EOF>"); + if (it == end) + throw Error(line, column, "undisclosed '" + std::string(1, quote) + "', got <EOF>"); - // Remove quote. - ++ it; + // Remove quote. + ++ it; - list.push_back({ Token::QuotedWord, line, save, std::move(value) }); + list.push_back({ Token::QuotedWord, line, save, std::move(value) }); } void analyseWord(Tokens &list, int &line, int &column, StreamIterator &it, StreamIterator end) { - assert(!isReserved(*it)); + assert(!isReserved(*it)); - std::string value; - int save = column; + std::string value; + int save = column; - while (it != end && !std::isspace(*it) && !isReserved(*it)) { - ++ column; - value += *it++; - } + while (it != end && !std::isspace(*it) && !isReserved(*it)) { + ++ column; + value += *it++; + } - list.push_back({ Token::Word, line, save, std::move(value) }); + list.push_back({ Token::Word, line, save, std::move(value) }); } void analyseInclude(Tokens &list, int &line, int &column, StreamIterator &it, StreamIterator end) { - assert(*it == '@'); + assert(*it == '@'); - std::string include; - int save = column; + std::string include; + int save = column; - // Read include. - ++ it; - while (it != end && !isSpace(*it)) { - ++ column; - include += *it++; - } + // Read include. + ++ it; + while (it != end && !isSpace(*it)) { + ++ column; + include += *it++; + } - if (include != "include") - throw Error(line, column, "expected include after '@' token"); + if (include != "include") + throw Error(line, column, "expected include after '@' token"); - list.push_back({ Token::Include, line, save }); + list.push_back({ Token::Include, line, save }); } void parseOptionValueSimple(Option &option, TokenIterator &it) { - assert(it->type() == Token::Word || it->type() == Token::QuotedWord); + assert(it->type() == Token::Word || it->type() == Token::QuotedWord); - option.push_back((it++)->value()); + option.push_back((it++)->value()); } void parseOptionValueList(Option &option, TokenIterator &it, TokenIterator end) { - assert(it->type() == Token::ListBegin); + assert(it->type() == Token::ListBegin); - TokenIterator save = it++; + TokenIterator save = it++; - while (it != end && it->type() != Token::ListEnd) { - switch (it->type()) { - case Token::Comma: - // Previous must be a word. - if (it[-1].type() != Token::Word && it[-1].type() != Token::QuotedWord) - throw Error(it->line(), it->column(), "unexpected comma after '" + it[-1].value() + "'"); + while (it != end && it->type() != Token::ListEnd) { + switch (it->type()) { + case Token::Comma: + // Previous must be a word. + if (it[-1].type() != Token::Word && it[-1].type() != Token::QuotedWord) + throw Error(it->line(), it->column(), "unexpected comma after '" + it[-1].value() + "'"); - ++ it; - break; - case Token::Word: - case Token::QuotedWord: - option.push_back((it++)->value()); - break; - default: - throw Error(it->line(), it->column(), "unexpected '" + it[-1].value() + "' in list construct"); - break; - } - } + ++ it; + break; + case Token::Word: + case Token::QuotedWord: + option.push_back((it++)->value()); + break; + default: + throw Error(it->line(), it->column(), "unexpected '" + it[-1].value() + "' in list construct"); + break; + } + } - if (it == end) - throw Error(save->line(), save->column(), "unterminated list construct"); + if (it == end) + throw Error(save->line(), save->column(), "unterminated list construct"); - // Remove ). - ++ it; + // Remove ). + ++ it; } void parseOption(Section &sc, TokenIterator &it, TokenIterator end) { - Option option(it->value()); + Option option(it->value()); - TokenIterator save = it; + TokenIterator save = it; - // No '=' or something else? - if (++it == end) - throw Error(save->line(), save->column(), "expected '=' assignment, got <EOF>"); - if (it->type() != Token::Assign) - throw Error(it->line(), it->column(), "expected '=' assignment, got " + it->value()); + // No '=' or something else? + if (++it == end) + throw Error(save->line(), save->column(), "expected '=' assignment, got <EOF>"); + if (it->type() != Token::Assign) + throw Error(it->line(), it->column(), "expected '=' assignment, got " + it->value()); - // Empty options are allowed so just test for words. - if (++it != end) { - if (it->type() == Token::Word || it->type() == Token::QuotedWord) - parseOptionValueSimple(option, it); - else if (it->type() == Token::ListBegin) - parseOptionValueList(option, it, end); - } + // Empty options are allowed so just test for words. + if (++it != end) { + if (it->type() == Token::Word || it->type() == Token::QuotedWord) + parseOptionValueSimple(option, it); + else if (it->type() == Token::ListBegin) + parseOptionValueList(option, it, end); + } - sc.push_back(std::move(option)); + sc.push_back(std::move(option)); } void parseInclude(Document &doc, const std::string &path, TokenIterator &it, TokenIterator end) { - TokenIterator save = it; + TokenIterator save = it; - if (++it == end) - throw Error(save->line(), save->column(), "expected file name after '@include' statement, got <EOF>"); - if (it->type() != Token::Word && it->type() != Token::QuotedWord) - throw Error(it->line(), it->column(), "expected file name after '@include' statement, got " + it->value()); + if (++it == end) + throw Error(save->line(), save->column(), "expected file name after '@include' statement, got <EOF>"); + if (it->type() != Token::Word && it->type() != Token::QuotedWord) + throw Error(it->line(), it->column(), "expected file name after '@include' statement, got " + it->value()); - std::string value = (it++)->value(); - std::string file; + std::string value = (it++)->value(); + std::string file; - if (!isAbsolute(value)) + if (!isAbsolute(value)) #if defined(_WIN32) - file = path + "\\" + value; + file = path + "\\" + value; #else - file = path + "/" + value; + file = path + "/" + value; #endif - else - file = value; + else + file = value; - for (const auto &sc : readFile(file)) - doc.push_back(sc); + for (const auto &sc : readFile(file)) + doc.push_back(sc); } void parseSection(Document &doc, TokenIterator &it, TokenIterator end) { - Section sc(it->value()); + Section sc(it->value()); - // Skip [section]. - ++ it; + // Skip [section]. + ++ it; - // Read until next section. - while (it != end && it->type() != Token::Section) { - if (it->type() != Token::Word) - throw Error(it->line(), it->column(), "unexpected token '" + it->value() + "' in section definition"); + // Read until next section. + while (it != end && it->type() != Token::Section) { + if (it->type() != Token::Word) + throw Error(it->line(), it->column(), "unexpected token '" + it->value() + "' in section definition"); - parseOption(sc, it, end); - } + parseOption(sc, it, end); + } - doc.push_back(std::move(sc)); + doc.push_back(std::move(sc)); } } // !namespace @@ -321,92 +321,92 @@ Tokens analyse(std::istreambuf_iterator<char> it, std::istreambuf_iterator<char> end) { - Tokens list; - int line = 1; - int column = 0; + Tokens list; + int line = 1; + int column = 0; - while (it != end) { - if (*it == '\n') - analyseLine(line, column, it); - else if (*it == '#') - analyseComment(column, it, end); - else if (*it == '[') - analyseSection(list, line, column, it, end); - else if (*it == '=') - analyseAssign(list, line, column, it); - else if (isSpace(*it)) - analyseSpaces(column, it, end); - else if (*it == '@') - analyseInclude(list, line, column, it, end); - else if (isQuote(*it)) - analyseQuotedWord(list, line, column, it, end); - else if (isList(*it)) - analyseList(list, line, column, it); - else - analyseWord(list, line, column, it, end); - } + while (it != end) { + if (*it == '\n') + analyseLine(line, column, it); + else if (*it == '#') + analyseComment(column, it, end); + else if (*it == '[') + analyseSection(list, line, column, it, end); + else if (*it == '=') + analyseAssign(list, line, column, it); + else if (isSpace(*it)) + analyseSpaces(column, it, end); + else if (*it == '@') + analyseInclude(list, line, column, it, end); + else if (isQuote(*it)) + analyseQuotedWord(list, line, column, it, end); + else if (isList(*it)) + analyseList(list, line, column, it); + else + analyseWord(list, line, column, it, end); + } - return list; + return list; } Tokens analyse(std::istream &stream) { - return analyse(std::istreambuf_iterator<char>(stream), {}); + return analyse(std::istreambuf_iterator<char>(stream), {}); } Document parse(const Tokens &tokens, const std::string &path) { - Document doc; - TokenIterator it = tokens.cbegin(); - TokenIterator end = tokens.cend(); + Document doc; + TokenIterator it = tokens.cbegin(); + TokenIterator end = tokens.cend(); - while (it != end) { - switch (it->type()) { - case Token::Include: - parseInclude(doc, path, it, end); - break; - case Token::Section: - parseSection(doc, it, end); - break; - default: - throw Error(it->line(), it->column(), "unexpected '" + it->value() + "' on root document"); - } - } + while (it != end) { + switch (it->type()) { + case Token::Include: + parseInclude(doc, path, it, end); + break; + case Token::Section: + parseSection(doc, it, end); + break; + default: + throw Error(it->line(), it->column(), "unexpected '" + it->value() + "' on root document"); + } + } - return doc; + return doc; } Document readFile(const std::string &filename) { - /* Get parent path */ - auto parent = filename; - auto pos = parent.find_last_of("/\\"); + /* Get parent path */ + auto parent = filename; + auto pos = parent.find_last_of("/\\"); - if (pos != std::string::npos) - parent.erase(pos); - else - parent = "."; + if (pos != std::string::npos) + parent.erase(pos); + else + parent = "."; - std::ifstream input(filename); + std::ifstream input(filename); - if (!input) - throw Error(0, 0, std::strerror(errno)); + if (!input) + throw Error(0, 0, std::strerror(errno)); - return parse(analyse(input), parent); + return parse(analyse(input), parent); } Document readString(const std::string &buffer) { - std::istringstream iss(buffer); + std::istringstream iss(buffer); - return parse(analyse(iss)); + return parse(analyse(iss)); } void dump(const Tokens &tokens) { - for (const Token &token: tokens) - // TODO: add better description - std::cout << token.line() << ":" << token.column() << ": " << token.value() << std::endl; + for (const Token &token: tokens) + // TODO: add better description + std::cout << token.line() << ":" << token.column() << ": " << token.value() << std::endl; } } // !ini
--- a/modules/ini/ini.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/ini/ini.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -123,54 +123,54 @@ */ class Error : public std::exception { private: - int m_line; //!< line number - int m_column; //!< line column - std::string m_message; //!< error message + int m_line; //!< line number + int m_column; //!< line column + std::string m_message; //!< error message public: - /** - * Constructor. - * - * \param line the line - * \param column the column - * \param msg the message - */ - inline Error(int line, int column, std::string msg) noexcept - : m_line(line) - , m_column(column) - , m_message(std::move(msg)) - { - } + /** + * Constructor. + * + * \param line the line + * \param column the column + * \param msg the message + */ + inline Error(int line, int column, std::string msg) noexcept + : m_line(line) + , m_column(column) + , m_message(std::move(msg)) + { + } - /** - * Get the line number. - * - * \return the line - */ - inline int line() const noexcept - { - return m_line; - } + /** + * Get the line number. + * + * \return the line + */ + inline int line() const noexcept + { + return m_line; + } - /** - * Get the column number. - * - * \return the column - */ - inline int column() const noexcept - { - return m_column; - } + /** + * Get the column number. + * + * \return the column + */ + inline int column() const noexcept + { + return m_column; + } - /** - * Return the raw error message (no line and column shown). - * - * \return the error message - */ - const char *what() const noexcept override - { - return m_message.c_str(); - } + /** + * Return the raw error message (no line and column shown). + * + * \return the error message + */ + const char *what() const noexcept override + { + return m_message.c_str(); + } }; /** @@ -183,106 +183,106 @@ */ class Token { public: - /** - * \brief Token type. - */ - enum Type { - Include, //!< include statement - Section, //!< [section] - Word, //!< word without quotes - QuotedWord, //!< word with quotes - Assign, //!< = assignment - ListBegin, //!< begin of list ( - ListEnd, //!< end of list ) - Comma //!< list separation - }; + /** + * \brief Token type. + */ + enum Type { + Include, //!< include statement + Section, //!< [section] + Word, //!< word without quotes + QuotedWord, //!< word with quotes + Assign, //!< = assignment + ListBegin, //!< begin of list ( + ListEnd, //!< end of list ) + Comma //!< list separation + }; private: - Type m_type; - int m_line; - int m_column; - std::string m_value; + Type m_type; + int m_line; + int m_column; + std::string m_value; public: - /** - * Construct a token. - * - * \param type the type - * \param line the line - * \param column the column - * \param value the value - */ - Token(Type type, int line, int column, std::string value = "") noexcept - : m_type(type) - , m_line(line) - , m_column(column) - { - switch (type) { - case Include: - m_value = "@include"; - break; - case Section: - case Word: - case QuotedWord: - m_value = value; - break; - case Assign: - m_value = "="; - break; - case ListBegin: - m_value = "("; - break; - case ListEnd: - m_value = ")"; - break; - case Comma: - m_value = ","; - break; - default: - break; - } - } + /** + * Construct a token. + * + * \param type the type + * \param line the line + * \param column the column + * \param value the value + */ + Token(Type type, int line, int column, std::string value = "") noexcept + : m_type(type) + , m_line(line) + , m_column(column) + { + switch (type) { + case Include: + m_value = "@include"; + break; + case Section: + case Word: + case QuotedWord: + m_value = value; + break; + case Assign: + m_value = "="; + break; + case ListBegin: + m_value = "("; + break; + case ListEnd: + m_value = ")"; + break; + case Comma: + m_value = ","; + break; + default: + break; + } + } - /** - * Get the type. - * - * \return the type - */ - inline Type type() const noexcept - { - return m_type; - } + /** + * Get the type. + * + * \return the type + */ + inline Type type() const noexcept + { + return m_type; + } - /** - * Get the line. - * - * \return the line - */ - inline int line() const noexcept - { - return m_line; - } + /** + * Get the line. + * + * \return the line + */ + inline int line() const noexcept + { + return m_line; + } - /** - * Get the column. - * - * \return the column - */ - inline int column() const noexcept - { - return m_column; - } + /** + * Get the column. + * + * \return the column + */ + inline int column() const noexcept + { + return m_column; + } - /** - * Get the value. For words, quoted words and section, the value is the content. Otherwise it's the - * characters parsed. - * - * \return the value - */ - inline const std::string &value() const noexcept - { - return m_value; - } + /** + * Get the value. For words, quoted words and section, the value is the content. Otherwise it's the + * characters parsed. + * + * \return the value + */ + inline const std::string &value() const noexcept + { + return m_value; + } }; /** @@ -296,72 +296,72 @@ */ class Option : public std::vector<std::string> { private: - std::string m_key; + std::string m_key; public: - /** - * Construct an empty option. - * - * \pre key must not be empty - * \param key the key - */ - inline Option(std::string key) noexcept - : std::vector<std::string>() - , m_key(std::move(key)) - { - assert(!m_key.empty()); - } + /** + * Construct an empty option. + * + * \pre key must not be empty + * \param key the key + */ + inline Option(std::string key) noexcept + : std::vector<std::string>() + , m_key(std::move(key)) + { + assert(!m_key.empty()); + } - /** - * Construct a single option. - * - * \pre key must not be empty - * \param key the key - * \param value the value - */ - inline Option(std::string key, std::string value) noexcept - : m_key(std::move(key)) - { - assert(!m_key.empty()); + /** + * Construct a single option. + * + * \pre key must not be empty + * \param key the key + * \param value the value + */ + inline Option(std::string key, std::string value) noexcept + : m_key(std::move(key)) + { + assert(!m_key.empty()); - push_back(std::move(value)); - } + push_back(std::move(value)); + } - /** - * Construct a list option. - * - * \pre key must not be empty - * \param key the key - * \param values the values - */ - inline Option(std::string key, std::vector<std::string> values) noexcept - : std::vector<std::string>(std::move(values)) - , m_key(std::move(key)) - { - assert(!m_key.empty()); - } + /** + * Construct a list option. + * + * \pre key must not be empty + * \param key the key + * \param values the values + */ + inline Option(std::string key, std::vector<std::string> values) noexcept + : std::vector<std::string>(std::move(values)) + , m_key(std::move(key)) + { + assert(!m_key.empty()); + } - /** - * Get the option key. - * - * \return the key - */ - inline const std::string &key() const noexcept - { - return m_key; - } + /** + * Get the option key. + * + * \return the key + */ + inline const std::string &key() const noexcept + { + return m_key; + } - /** - * Get the option value. - * - * \return the value - */ - inline const std::string &value() const noexcept - { - static std::string dummy; + /** + * Get the option value. + * + * \return the value + */ + inline const std::string &value() const noexcept + { + static std::string dummy; - return empty() ? dummy : (*this)[0]; - } + return empty() ? dummy : (*this)[0]; + } }; /** @@ -370,100 +370,100 @@ */ class Section : public std::vector<Option> { private: - std::string m_key; + std::string m_key; public: - /** - * Construct a section with its name. - * - * \pre key must not be empty - * \param key the key - */ - inline Section(std::string key) noexcept - : m_key(std::move(key)) - { - assert(!m_key.empty()); - } + /** + * Construct a section with its name. + * + * \pre key must not be empty + * \param key the key + */ + inline Section(std::string key) noexcept + : m_key(std::move(key)) + { + assert(!m_key.empty()); + } - /** - * Get the section key. - * - * \return the key - */ - inline const std::string &key() const noexcept - { - return m_key; - } + /** + * Get the section key. + * + * \return the key + */ + inline const std::string &key() const noexcept + { + return m_key; + } - /** - * Check if the section contains a specific option. - * - * \param key the option key - * \return true if the option exists - */ - inline bool contains(const std::string &key) const noexcept - { - return find(key) != end(); - } + /** + * Check if the section contains a specific option. + * + * \param key the option key + * \return true if the option exists + */ + inline bool contains(const std::string &key) const noexcept + { + return find(key) != end(); + } - /** - * Find an option by key and return an iterator. - * - * \param key the key - * \return the iterator or end() if not found - */ - inline iterator find(const std::string &key) noexcept - { - return std::find_if(begin(), end(), [&] (const auto &o) { - return o.key() == key; - }); - } + /** + * Find an option by key and return an iterator. + * + * \param key the key + * \return the iterator or end() if not found + */ + inline iterator find(const std::string &key) noexcept + { + return std::find_if(begin(), end(), [&] (const auto &o) { + return o.key() == key; + }); + } - /** - * Find an option by key and return an iterator. - * - * \param key the key - * \return the iterator or end() if not found - */ - inline const_iterator find(const std::string &key) const noexcept - { - return std::find_if(cbegin(), cend(), [&] (const auto &o) { - return o.key() == key; - }); - } + /** + * Find an option by key and return an iterator. + * + * \param key the key + * \return the iterator or end() if not found + */ + inline const_iterator find(const std::string &key) const noexcept + { + return std::find_if(cbegin(), cend(), [&] (const auto &o) { + return o.key() == key; + }); + } - /** - * Access an option at the specified key. - * - * \param key the key - * \return the option - * \pre contains(key) must return true - */ - inline Option &operator[](const std::string &key) - { - assert(contains(key)); + /** + * Access an option at the specified key. + * + * \param key the key + * \return the option + * \pre contains(key) must return true + */ + inline Option &operator[](const std::string &key) + { + assert(contains(key)); - return *find(key); - } + return *find(key); + } - /** - * Overloaded function. - * - * \param key the key - * \return the option - * \pre contains(key) must return true - */ - inline const Option &operator[](const std::string &key) const - { - assert(contains(key)); + /** + * Overloaded function. + * + * \param key the key + * \return the option + * \pre contains(key) must return true + */ + inline const Option &operator[](const std::string &key) const + { + assert(contains(key)); - return *find(key); - } + return *find(key); + } - /** - * Inherited operators. - */ - using std::vector<Option>::operator[]; + /** + * Inherited operators. + */ + using std::vector<Option>::operator[]; }; /** @@ -474,75 +474,75 @@ */ class Document : public std::vector<Section> { public: - /** - * Check if a document has a specific section. - * - * \param key the key - * \return true if the document contains the section - */ - inline bool contains(const std::string &key) const noexcept - { - return std::find_if(begin(), end(), [&] (const auto &sc) { return sc.key() == key; }) != end(); - } + /** + * Check if a document has a specific section. + * + * \param key the key + * \return true if the document contains the section + */ + inline bool contains(const std::string &key) const noexcept + { + return std::find_if(begin(), end(), [&] (const auto &sc) { return sc.key() == key; }) != end(); + } - /** - * Find a section by key and return an iterator. - * - * \param key the key - * \return the iterator or end() if not found - */ - inline iterator find(const std::string &key) noexcept - { - return std::find_if(begin(), end(), [&] (const auto &o) { - return o.key() == key; - }); - } + /** + * Find a section by key and return an iterator. + * + * \param key the key + * \return the iterator or end() if not found + */ + inline iterator find(const std::string &key) noexcept + { + return std::find_if(begin(), end(), [&] (const auto &o) { + return o.key() == key; + }); + } - /** - * Find a section by key and return an iterator. - * - * \param key the key - * \return the iterator or end() if not found - */ - inline const_iterator find(const std::string &key) const noexcept - { - return std::find_if(cbegin(), cend(), [&] (const auto &o) { - return o.key() == key; - }); - } + /** + * Find a section by key and return an iterator. + * + * \param key the key + * \return the iterator or end() if not found + */ + inline const_iterator find(const std::string &key) const noexcept + { + return std::find_if(cbegin(), cend(), [&] (const auto &o) { + return o.key() == key; + }); + } - /** - * Access a section at the specified key. - * - * \param key the key - * \return the section - * \pre contains(key) must return true - */ - inline Section &operator[](const std::string &key) - { - assert(contains(key)); + /** + * Access a section at the specified key. + * + * \param key the key + * \return the section + * \pre contains(key) must return true + */ + inline Section &operator[](const std::string &key) + { + assert(contains(key)); - return *find(key); - } + return *find(key); + } - /** - * Overloaded function. - * - * \param key the key - * \return the section - * \pre contains(key) must return true - */ - inline const Section &operator[](const std::string &key) const - { - assert(contains(key)); + /** + * Overloaded function. + * + * \param key the key + * \return the section + * \pre contains(key) must return true + */ + inline const Section &operator[](const std::string &key) const + { + assert(contains(key)); - return *find(key); - } + return *find(key); + } - /** - * Inherited operators. - */ - using std::vector<Section>::operator[]; + /** + * Inherited operators. + */ + using std::vector<Section>::operator[]; }; /**
--- a/modules/ini/test/configs/includes.conf Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/ini/test/configs/includes.conf Wed Jun 15 13:13:26 2016 +0200 @@ -1,5 +1,5 @@ # With some includes -@include "simple.conf" # comments also work here +@include "simple.conf" # comments also work here [standard] verbose = false
--- a/modules/ini/test/configs/multi.conf Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/ini/test/configs/multi.conf Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ [entity] -name = "Player" -version = 1.0 +name = "Player" +version = 1.0 [entity] -name = "Subwinner" -version = 2.0 \ No newline at end of file +name = "Subwinner" +version = 2.0 \ No newline at end of file
--- a/modules/ini/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/ini/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -24,60 +24,60 @@ class BasicTest : public testing::Test { protected: - ini::Document m_ini; + ini::Document m_ini; public: - BasicTest() - : m_ini(ini::readFile(DIRECTORY "simple.conf")) - { - } + BasicTest() + : m_ini(ini::readFile(DIRECTORY "simple.conf")) + { + } }; TEST_F(BasicTest, simple) { - ASSERT_EQ(1, static_cast<int>(m_ini.size())); + ASSERT_EQ(1, static_cast<int>(m_ini.size())); } TEST_F(BasicTest, operators) { - try { - ASSERT_EQ(3, static_cast<int>(m_ini[0].size())); - ASSERT_EQ("general", m_ini[0].key()); - ASSERT_EQ("general", m_ini["general"].key()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + try { + ASSERT_EQ(3, static_cast<int>(m_ini[0].size())); + ASSERT_EQ("general", m_ini[0].key()); + ASSERT_EQ("general", m_ini["general"].key()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(BasicTest, sectionOperators) { - try { - // option1=1 (indexes). - ASSERT_EQ("option1", m_ini[0][0].key()); - ASSERT_EQ("1", m_ini[0][0].value()); + try { + // option1=1 (indexes). + ASSERT_EQ("option1", m_ini[0][0].key()); + ASSERT_EQ("1", m_ini[0][0].value()); - // option1=1 (keys). - ASSERT_EQ("option1", m_ini["general"]["option1"].key()); - ASSERT_EQ("1", m_ini["general"]["option1"].value()); + // option1=1 (keys). + ASSERT_EQ("option1", m_ini["general"]["option1"].key()); + ASSERT_EQ("1", m_ini["general"]["option1"].value()); - // option2 =2 (indexes). - ASSERT_EQ("option2", m_ini[0][1].key()); - ASSERT_EQ("2", m_ini[0][1].value()); + // option2 =2 (indexes). + ASSERT_EQ("option2", m_ini[0][1].key()); + ASSERT_EQ("2", m_ini[0][1].value()); - // option2 =2 (keys). - ASSERT_EQ("option2", m_ini["general"]["option2"].key()); - ASSERT_EQ("2", m_ini["general"]["option2"].value()); + // option2 =2 (keys). + ASSERT_EQ("option2", m_ini["general"]["option2"].key()); + ASSERT_EQ("2", m_ini["general"]["option2"].value()); - // option3 = 3 (indexes). - ASSERT_EQ("option3", m_ini[0][2].key()); - ASSERT_EQ("3", m_ini[0][2].value()); + // option3 = 3 (indexes). + ASSERT_EQ("option3", m_ini[0][2].key()); + ASSERT_EQ("3", m_ini[0][2].value()); - // option3 = 3 (keys). - ASSERT_EQ("option3", m_ini["general"]["option3"].key()); - ASSERT_EQ("3", m_ini["general"]["option3"].value()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + // option3 = 3 (keys). + ASSERT_EQ("option3", m_ini["general"]["option3"].key()); + ASSERT_EQ("3", m_ini["general"]["option3"].value()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -87,14 +87,14 @@ TEST(Tokens, reserved) { - try { - ini::Document doc = ini::readFile(DIRECTORY "tokens.conf"); + try { + ini::Document doc = ini::readFile(DIRECTORY "tokens.conf"); - ASSERT_EQ("I have [brackets]", doc["tokens"]["bracket"].value()); - ASSERT_EQ("I have foo@at", doc["tokens"]["at"].value()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("I have [brackets]", doc["tokens"]["bracket"].value()); + ASSERT_EQ("I have foo@at", doc["tokens"]["at"].value()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -104,26 +104,26 @@ class MultiTest : public testing::Test { protected: - ini::Document m_ini; + ini::Document m_ini; public: - MultiTest() - : m_ini(ini::readFile(DIRECTORY "multi.conf")) - { - } + MultiTest() + : m_ini(ini::readFile(DIRECTORY "multi.conf")) + { + } }; TEST_F(MultiTest, defined) { - ASSERT_EQ(2, static_cast<int>(m_ini.size())); - ASSERT_EQ("name", m_ini[0]["name"].key()); - ASSERT_EQ("Player", m_ini[0]["name"].value()); - ASSERT_EQ("version", m_ini[0]["version"].key()); - ASSERT_EQ("1.0", m_ini[0]["version"].value()); - ASSERT_EQ("name", m_ini[1]["name"].key()); - ASSERT_EQ("Subwinner", m_ini[1]["name"].value()); - ASSERT_EQ("version", m_ini[1]["version"].key()); - ASSERT_EQ("2.0", m_ini[1]["version"].value()); + ASSERT_EQ(2, static_cast<int>(m_ini.size())); + ASSERT_EQ("name", m_ini[0]["name"].key()); + ASSERT_EQ("Player", m_ini[0]["name"].value()); + ASSERT_EQ("version", m_ini[0]["version"].key()); + ASSERT_EQ("1.0", m_ini[0]["version"].value()); + ASSERT_EQ("name", m_ini[1]["name"].key()); + ASSERT_EQ("Subwinner", m_ini[1]["name"].value()); + ASSERT_EQ("version", m_ini[1]["version"].key()); + ASSERT_EQ("2.0", m_ini[1]["version"].value()); } /* @@ -133,21 +133,21 @@ class NoValueTest : public testing::Test { protected: - ini::Document m_ini; + ini::Document m_ini; public: - NoValueTest() - : m_ini(ini::readFile(DIRECTORY "novalue.conf")) - { - } + NoValueTest() + : m_ini(ini::readFile(DIRECTORY "novalue.conf")) + { + } }; TEST_F(NoValueTest, isDefined) { - ASSERT_EQ("plugins", m_ini[0].key()); - ASSERT_EQ("", m_ini["plugins"]["histedit"].value()); - ASSERT_EQ("", m_ini["plugins"]["highlight"].value()); - ASSERT_EQ("", m_ini["plugins"]["general"].value()); + ASSERT_EQ("plugins", m_ini[0].key()); + ASSERT_EQ("", m_ini["plugins"]["histedit"].value()); + ASSERT_EQ("", m_ini["plugins"]["highlight"].value()); + ASSERT_EQ("", m_ini["plugins"]["general"].value()); } /* @@ -157,26 +157,26 @@ class IncludeTest : public testing::Test { protected: - ini::Document m_ini; + ini::Document m_ini; public: - IncludeTest() - : m_ini(ini::readFile(DIRECTORY "includes.conf")) - { - } + IncludeTest() + : m_ini(ini::readFile(DIRECTORY "includes.conf")) + { + } }; TEST_F(IncludeTest, all) { - ASSERT_EQ(2, static_cast<int>(m_ini.size())); + ASSERT_EQ(2, static_cast<int>(m_ini.size())); - // from include. - ASSERT_EQ("1", m_ini[0][0].value()); - ASSERT_EQ("2", m_ini[0][1].value()); - ASSERT_EQ("3", m_ini[0][2].value()); + // from include. + ASSERT_EQ("1", m_ini[0][0].value()); + ASSERT_EQ("2", m_ini[0][1].value()); + ASSERT_EQ("3", m_ini[0][2].value()); - // from standard. - ASSERT_EQ("false", m_ini[1][0].value()); + // from standard. + ASSERT_EQ("false", m_ini[1][0].value()); } /* @@ -186,16 +186,16 @@ TEST(Compact, test) { - try { - ini::Document doc = ini::readFile(DIRECTORY "compact.conf"); + try { + ini::Document doc = ini::readFile(DIRECTORY "compact.conf"); - ASSERT_EQ(2, static_cast<int>(doc.size())); - ASSERT_EQ("true", doc["general"]["verbose"].value()); - ASSERT_EQ("false", doc["general"]["foreground"].value()); - ASSERT_EQ("google.fr", doc["server"]["host"].value()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(2, static_cast<int>(doc.size())); + ASSERT_EQ("true", doc["general"]["verbose"].value()); + ASSERT_EQ("false", doc["general"]["foreground"].value()); + ASSERT_EQ("google.fr", doc["server"]["host"].value()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -205,11 +205,11 @@ TEST(Empty, test) { - try { - ini::Document doc = ini::readFile(DIRECTORY "empty.conf"); - } catch (const ini::Error &error) { - FAIL() << error.line() << ":" << error.column() << ": " << error.what(); - } + try { + ini::Document doc = ini::readFile(DIRECTORY "empty.conf"); + } catch (const ini::Error &error) { + FAIL() << error.line() << ":" << error.column() << ": " << error.what(); + } } /* @@ -219,16 +219,16 @@ TEST(List, test) { - try { - std::vector<std::string> rule1{"abc", "bcd"}; - std::vector<std::string> rule2{"xyz", "poi"}; - ini::Document doc = ini::readFile(DIRECTORY "lists.conf"); + try { + std::vector<std::string> rule1{"abc", "bcd"}; + std::vector<std::string> rule2{"xyz", "poi"}; + ini::Document doc = ini::readFile(DIRECTORY "lists.conf"); - ASSERT_EQ(rule1, doc[0][0]); - ASSERT_EQ(rule2, doc[1][0]); - } catch (const ini::Error &error) { - FAIL() << error.line() << ":" << error.column() << ": " << error.what(); - } + ASSERT_EQ(rule1, doc[0][0]); + ASSERT_EQ(rule2, doc[1][0]); + } catch (const ini::Error &error) { + FAIL() << error.line() << ":" << error.column() << ": " << error.what(); + } } /* @@ -238,64 +238,64 @@ TEST(Errors, nosection) { - // An option outside a section is not allowed. - try { - ini::Document doc = ini::readFile(DIRECTORY "error-nosection.conf"); + // An option outside a section is not allowed. + try { + ini::Document doc = ini::readFile(DIRECTORY "error-nosection.conf"); - FAIL() << "Failure expected, got success"; - } catch (const ini::Error &ex) { - ASSERT_EQ(3, ex.line()); - ASSERT_EQ(0, ex.column()); - } + FAIL() << "Failure expected, got success"; + } catch (const ini::Error &ex) { + ASSERT_EQ(3, ex.line()); + ASSERT_EQ(0, ex.column()); + } } TEST(Errors, badcomment) { - // Comment can't between option-key and = assigment. - try { - ini::Document doc = ini::readFile(DIRECTORY "error-badcomment.conf"); + // Comment can't between option-key and = assigment. + try { + ini::Document doc = ini::readFile(DIRECTORY "error-badcomment.conf"); - FAIL() << "Failure expected, got success"; - } catch (const ini::Error &ex) { - ASSERT_EQ(2, ex.line()); - ASSERT_EQ(0, ex.column()); - } + FAIL() << "Failure expected, got success"; + } catch (const ini::Error &ex) { + ASSERT_EQ(2, ex.line()); + ASSERT_EQ(0, ex.column()); + } } TEST(Errors, badsection) { - // Bad section naming - try { - ini::Document doc = ini::readFile(DIRECTORY "error-badsection.conf"); + // Bad section naming + try { + ini::Document doc = ini::readFile(DIRECTORY "error-badsection.conf"); - FAIL() << "Failure expected, got success"; - } catch (const ini::Error &ex) { - ASSERT_EQ(1, ex.line()); - ASSERT_EQ(0, ex.column()); - } + FAIL() << "Failure expected, got success"; + } catch (const ini::Error &ex) { + ASSERT_EQ(1, ex.line()); + ASSERT_EQ(0, ex.column()); + } } TEST(Errors, unterminatedsection) { - // Section unfinished. - try { - ini::Document doc = ini::readFile(DIRECTORY "error-unterminatedsection.conf"); + // Section unfinished. + try { + ini::Document doc = ini::readFile(DIRECTORY "error-unterminatedsection.conf"); - FAIL() << "Failure expected, got success"; - } catch (const ini::Error &ex) { - ASSERT_EQ(2, ex.line()); - ASSERT_EQ(6, ex.column()); - } + FAIL() << "Failure expected, got success"; + } catch (const ini::Error &ex) { + ASSERT_EQ(2, ex.line()); + ASSERT_EQ(6, ex.column()); + } } TEST(Errors, notFound) { - ASSERT_ANY_THROW(ini::readFile("does not exists")); + ASSERT_ANY_THROW(ini::readFile("does not exists")); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/js/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/js/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -19,7 +19,7 @@ add_subdirectory(duktape) code_define_module( - NAME js - SOURCES duktape.hpp - LIBRARIES duktape -) \ No newline at end of file + NAME js + SOURCES duktape.hpp + LIBRARIES duktape +)
--- a/modules/js/duktape.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/js/duktape.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -49,52 +49,52 @@ class StackAssert { #if !defined(NDEBUG) private: - duk_context *m_context; - unsigned m_expected; - unsigned m_begin; + duk_context *m_context; + unsigned m_expected; + unsigned m_begin; #endif public: - /** - * Create the stack checker. - * - * No-op if NDEBUG is set. - * - * \param ctx the context - * \param expected the size expected relative to the already existing values - */ - inline StackAssert(duk_context *ctx, unsigned expected = 0) noexcept + /** + * Create the stack checker. + * + * No-op if NDEBUG is set. + * + * \param ctx the context + * \param expected the size expected relative to the already existing values + */ + inline StackAssert(duk_context *ctx, unsigned expected = 0) noexcept #if !defined(NDEBUG) - : m_context(ctx) - , m_expected(expected) - , m_begin(static_cast<unsigned>(duk_get_top(ctx))) + : m_context(ctx) + , m_expected(expected) + , m_begin(static_cast<unsigned>(duk_get_top(ctx))) #endif - { + { #if defined(NDEBUG) - (void)ctx; - (void)expected; + (void)ctx; + (void)expected; #endif - } + } - /** - * Verify the expected size. - * - * No-op if NDEBUG is set. - */ - inline ~StackAssert() noexcept - { + /** + * Verify the expected size. + * + * No-op if NDEBUG is set. + */ + inline ~StackAssert() noexcept + { #if !defined(NDEBUG) - if (static_cast<unsigned>(duk_get_top(m_context)) - m_begin != m_expected) { - std::fprintf(stderr, "Corrupt stack detection in StackAssert:\n"); - std::fprintf(stderr, " Size at start: %u\n", m_begin); - std::fprintf(stderr, " Size at end: %d\n", duk_get_top(m_context)); - std::fprintf(stderr, " Expected (user): %u\n", m_expected); - std::fprintf(stderr, " Expected (adjusted): %u\n", m_expected + m_begin); - std::fprintf(stderr, " Number of stale values: %u\n", duk_get_top(m_context) - m_begin - m_expected); - std::abort(); - } + if (static_cast<unsigned>(duk_get_top(m_context)) - m_begin != m_expected) { + std::fprintf(stderr, "Corrupt stack detection in StackAssert:\n"); + std::fprintf(stderr, " Size at start: %u\n", m_begin); + std::fprintf(stderr, " Size at end: %d\n", duk_get_top(m_context)); + std::fprintf(stderr, " Expected (user): %u\n", m_expected); + std::fprintf(stderr, " Expected (adjusted): %u\n", m_expected + m_begin); + std::fprintf(stderr, " Number of stale values: %u\n", duk_get_top(m_context) - m_begin - m_expected); + std::abort(); + } #endif - } + } }; /** @@ -105,21 +105,21 @@ */ class Exception : public std::exception { public: - std::string name; //!< name of error - std::string message; //!< error message - std::string stack; //!< stack if available - std::string fileName; //!< filename if applicable - int lineNumber{0}; //!< line number if applicable + std::string name; //!< name of error + std::string message; //!< error message + std::string stack; //!< stack if available + std::string fileName; //!< filename if applicable + int lineNumber{0}; //!< line number if applicable - /** - * Get the error message. This effectively returns message field. - * - * \return the message - */ - const char *what() const noexcept override - { - return message.c_str(); - } + /** + * Get the error message. This effectively returns message field. + * + * \return the message + */ + const char *what() const noexcept override + { + return message.c_str(); + } }; /** @@ -129,54 +129,54 @@ */ class UniqueContext { private: - using Deleter = void (*)(duk_context *); - using Handle = std::unique_ptr<duk_context, Deleter>; + using Deleter = void (*)(duk_context *); + using Handle = std::unique_ptr<duk_context, Deleter>; - Handle m_handle; + Handle m_handle; - UniqueContext(const UniqueContext &) = delete; - UniqueContext &operator=(const UniqueContext &) = delete; + UniqueContext(const UniqueContext &) = delete; + UniqueContext &operator=(const UniqueContext &) = delete; public: - /** - * Create default context. - */ - inline UniqueContext() - : m_handle(duk_create_heap_default(), duk_destroy_heap) - { - } + /** + * Create default context. + */ + inline UniqueContext() + : m_handle(duk_create_heap_default(), duk_destroy_heap) + { + } - /** - * Default move constructor. - */ - UniqueContext(UniqueContext &&) noexcept = default; + /** + * Default move constructor. + */ + UniqueContext(UniqueContext &&) noexcept = default; - /** - * Convert the context to the native Duktape/C type. - * - * \return the duk_context - */ - inline operator duk_context *() noexcept - { - return m_handle.get(); - } + /** + * Convert the context to the native Duktape/C type. + * + * \return the duk_context + */ + inline operator duk_context *() noexcept + { + return m_handle.get(); + } - /** - * Convert the context to the native Duktape/C type. - * - * \return the duk_context - */ - inline operator duk_context *() const noexcept - { - return m_handle.get(); - } + /** + * Convert the context to the native Duktape/C type. + * + * \return the duk_context + */ + inline operator duk_context *() const noexcept + { + return m_handle.get(); + } - /** - * Default move assignment operator. - * - * \return this - */ - UniqueContext &operator=(UniqueContext &&) noexcept = delete; + /** + * Default move assignment operator. + * + * \return this + */ + UniqueContext &operator=(UniqueContext &&) noexcept = delete; }; /** @@ -186,43 +186,43 @@ */ class Error { private: - int m_type{DUK_ERR_ERROR}; - std::string m_message; + int m_type{DUK_ERR_ERROR}; + std::string m_message; protected: - /** - * Constructor with a type of error specified, specially designed for derived errors. - * - * \param type of error (e.g. DUK_ERR_ERROR) - * \param message the message - */ - inline Error(int type, std::string message) noexcept - : m_type(type) - , m_message(std::move(message)) - { - } + /** + * Constructor with a type of error specified, specially designed for derived errors. + * + * \param type of error (e.g. DUK_ERR_ERROR) + * \param message the message + */ + inline Error(int type, std::string message) noexcept + : m_type(type) + , m_message(std::move(message)) + { + } public: - /** - * Constructor with a message. - * - * \param message the message - */ - inline Error(std::string message) noexcept - : m_message(std::move(message)) - { - } + /** + * Constructor with a message. + * + * \param message the message + */ + inline Error(std::string message) noexcept + : m_message(std::move(message)) + { + } - /** - * Create the exception on the stack. - * - * \note the default implementation search for the global variables - * \param ctx the context - */ - virtual void raise(duk_context *ctx) const - { - duk_error(ctx, m_type, "%s", m_message.c_str()); - } + /** + * Create the exception on the stack. + * + * \note the default implementation search for the global variables + * \param ctx the context + */ + virtual void raise(duk_context *ctx) const + { + duk_error(ctx, m_type, "%s", m_message.c_str()); + } }; /** @@ -231,15 +231,15 @@ */ class EvalError : public Error { public: - /** - * Construct an EvalError. - * - * \param message the message - */ - inline EvalError(std::string message) noexcept - : Error(DUK_ERR_EVAL_ERROR, std::move(message)) - { - } + /** + * Construct an EvalError. + * + * \param message the message + */ + inline EvalError(std::string message) noexcept + : Error(DUK_ERR_EVAL_ERROR, std::move(message)) + { + } }; /** @@ -248,15 +248,15 @@ */ class RangeError : public Error { public: - /** - * Construct an RangeError. - * - * \param message the message - */ - inline RangeError(std::string message) noexcept - : Error(DUK_ERR_RANGE_ERROR, std::move(message)) - { - } + /** + * Construct an RangeError. + * + * \param message the message + */ + inline RangeError(std::string message) noexcept + : Error(DUK_ERR_RANGE_ERROR, std::move(message)) + { + } }; /** @@ -265,15 +265,15 @@ */ class ReferenceError : public Error { public: - /** - * Construct an ReferenceError. - * - * \param message the message - */ - inline ReferenceError(std::string message) noexcept - : Error(DUK_ERR_REFERENCE_ERROR, std::move(message)) - { - } + /** + * Construct an ReferenceError. + * + * \param message the message + */ + inline ReferenceError(std::string message) noexcept + : Error(DUK_ERR_REFERENCE_ERROR, std::move(message)) + { + } }; /** @@ -282,15 +282,15 @@ */ class SyntaxError : public Error { public: - /** - * Construct an SyntaxError. - * - * \param message the message - */ - inline SyntaxError(std::string message) noexcept - : Error(DUK_ERR_SYNTAX_ERROR, std::move(message)) - { - } + /** + * Construct an SyntaxError. + * + * \param message the message + */ + inline SyntaxError(std::string message) noexcept + : Error(DUK_ERR_SYNTAX_ERROR, std::move(message)) + { + } }; /** @@ -299,15 +299,15 @@ */ class TypeError : public Error { public: - /** - * Construct an TypeError. - * - * \param message the message - */ - inline TypeError(std::string message) noexcept - : Error(DUK_ERR_TYPE_ERROR, std::move(message)) - { - } + /** + * Construct an TypeError. + * + * \param message the message + */ + inline TypeError(std::string message) noexcept + : Error(DUK_ERR_TYPE_ERROR, std::move(message)) + { + } }; /** @@ -316,15 +316,15 @@ */ class URIError : public Error { public: - /** - * Construct an URIError. - * - * \param message the message - */ - inline URIError(std::string message) noexcept - : Error(DUK_ERR_URI_ERROR, std::move(message)) - { - } + /** + * Construct an URIError. + * + * \param message the message + */ + inline URIError(std::string message) noexcept + : Error(DUK_ERR_URI_ERROR, std::move(message)) + { + } }; /** @@ -337,26 +337,26 @@ */ inline Exception dukx_exception(duk_context *ctx, int index, bool pop = true) { - Exception ex; + Exception ex; - index = duk_normalize_index(ctx, index); + index = duk_normalize_index(ctx, index); - duk_get_prop_string(ctx, index, "name"); - ex.name = duk_to_string(ctx, -1); - duk_get_prop_string(ctx, index, "message"); - ex.message = duk_to_string(ctx, -1); - duk_get_prop_string(ctx, index, "fileName"); - ex.fileName = duk_to_string(ctx, -1); - duk_get_prop_string(ctx, index, "lineNumber"); - ex.lineNumber = duk_to_int(ctx, -1); - duk_get_prop_string(ctx, index, "stack"); - ex.stack = duk_to_string(ctx, -1); - duk_pop_n(ctx, 5); + duk_get_prop_string(ctx, index, "name"); + ex.name = duk_to_string(ctx, -1); + duk_get_prop_string(ctx, index, "message"); + ex.message = duk_to_string(ctx, -1); + duk_get_prop_string(ctx, index, "fileName"); + ex.fileName = duk_to_string(ctx, -1); + duk_get_prop_string(ctx, index, "lineNumber"); + ex.lineNumber = duk_to_int(ctx, -1); + duk_get_prop_string(ctx, index, "stack"); + ex.stack = duk_to_string(ctx, -1); + duk_pop_n(ctx, 5); - if (pop) - duk_remove(ctx, index); + if (pop) + duk_remove(ctx, index); - return ex; + return ex; } /** @@ -371,14 +371,14 @@ template <typename Func> void dukx_enumerate(duk_context *ctx, int index, duk_uint_t flags, duk_bool_t getvalue, Func &&func) { - duk_enum(ctx, index, flags); + duk_enum(ctx, index, flags); - while (duk_next(ctx, -1, getvalue)) { - func(ctx); - duk_pop_n(ctx, 1 + (getvalue ? 1 : 0)); - } + while (duk_next(ctx, -1, getvalue)) { + func(ctx); + duk_pop_n(ctx, 1 + (getvalue ? 1 : 0)); + } - duk_pop(ctx); + duk_pop(ctx); } /** @@ -390,7 +390,7 @@ template <typename Exception> void dukx_throw(duk_context *ctx, const Exception &ex) { - ex.raise(ctx); + ex.raise(ctx); } /** @@ -402,10 +402,10 @@ */ inline std::string dukx_get_std_string(duk_context *ctx, int index) { - duk_size_t size; - const char *text = duk_get_lstring(ctx, index, &size); + duk_size_t size; + const char *text = duk_get_lstring(ctx, index, &size); - return std::string(text, size); + return std::string(text, size); } /** @@ -417,10 +417,10 @@ */ inline std::string dukx_require_std_string(duk_context *ctx, int index) { - duk_size_t size; - const char *text = duk_require_lstring(ctx, index, &size); + duk_size_t size; + const char *text = duk_require_lstring(ctx, index, &size); - return std::string(text, size); + return std::string(text, size); } /** @@ -431,7 +431,7 @@ */ inline void dukx_push_std_string(duk_context *ctx, const std::string &str) { - duk_push_lstring(ctx, str.data(), str.length()); + duk_push_lstring(ctx, str.data(), str.length()); } /** @@ -444,18 +444,18 @@ template <typename Getter> auto dukx_get_array(duk_context *ctx, duk_idx_t index, Getter &&get) { - using T = decltype(get(ctx, 0)); + using T = decltype(get(ctx, 0)); - std::vector<T> result; - std::size_t length = duk_get_length(ctx, index); + std::vector<T> result; + std::size_t length = duk_get_length(ctx, index); - for (std::size_t i = 0; i < length; ++i) { - duk_get_prop_index(ctx, -1, i); - result.push_back(get(ctx, -1)); - duk_pop(ctx); - } + for (std::size_t i = 0; i < length; ++i) { + duk_get_prop_index(ctx, -1, i); + result.push_back(get(ctx, -1)); + duk_pop(ctx); + } - return result; + return result; } /** @@ -468,13 +468,13 @@ template <typename T, typename Pusher> void dukx_push_array(duk_context *ctx, const std::vector<T> &values, Pusher &&push) { - duk_push_array(ctx); + duk_push_array(ctx); - int i = 0; - for (auto x : values) { - push(ctx, x); - duk_put_prop_index(ctx, -2, i++); - } + int i = 0; + for (auto x : values) { + push(ctx, x); + duk_put_prop_index(ctx, -2, i++); + } } /** @@ -487,20 +487,20 @@ template <typename Getter> auto dukx_get_object(duk_context *ctx, duk_idx_t index, Getter &&get) { - using T = decltype(get(ctx, 0)); + using T = decltype(get(ctx, 0)); - std::unordered_map<std::string, T> result; + std::unordered_map<std::string, T> result; - duk_enum(ctx, index, 0); + duk_enum(ctx, index, 0); - while (duk_next(ctx, -1, true)) { - result.emplace(dukx_get_std_string(ctx, -2), get(ctx, -1)); - duk_pop_2(ctx); - } + while (duk_next(ctx, -1, true)) { + result.emplace(dukx_get_std_string(ctx, -2), get(ctx, -1)); + duk_pop_2(ctx); + } - duk_pop(ctx); + duk_pop(ctx); - return result; + return result; } /** @@ -513,12 +513,12 @@ template <typename T, typename Pusher> void dukx_push_object(duk_context *ctx, const std::unordered_map<std::string, T> &values, Pusher &&push) { - duk_push_object(ctx); + duk_push_object(ctx); - for (const auto &pair : values) { - push(ctx, pair.second); - duk_put_prop_string(ctx, -2, pair.first.c_str()); - } + for (const auto &pair : values) { + push(ctx, pair.second); + duk_put_prop_string(ctx, -2, pair.first.c_str()); + } } #endif // !DUKTAPE_HPP
--- a/modules/js/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/js/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -22,48 +22,48 @@ TEST(Push, array) { - UniqueContext ctx; + UniqueContext ctx; - std::vector<int> v{1, 2, 3}; + std::vector<int> v{1, 2, 3}; - dukx_push_array(ctx, v, duk_push_int); - ASSERT_EQ(v, dukx_get_array(ctx, -1, duk_get_int)); + dukx_push_array(ctx, v, duk_push_int); + ASSERT_EQ(v, dukx_get_array(ctx, -1, duk_get_int)); } TEST(Push, object) { - UniqueContext ctx; + UniqueContext ctx; - std::unordered_map<std::string, std::string> o{ - { "file", "foo.txt" }, - { "password", "test" } - }; + std::unordered_map<std::string, std::string> o{ + { "file", "foo.txt" }, + { "password", "test" } + }; - dukx_push_object(ctx, o, dukx_push_std_string); - ASSERT_EQ(o, dukx_get_object(ctx, -1, dukx_get_std_string)); + dukx_push_object(ctx, o, dukx_push_std_string); + ASSERT_EQ(o, dukx_get_object(ctx, -1, dukx_get_std_string)); } #if 0 TEST(Basics, enumerate) { - duk::UniqueContext context; + duk::UniqueContext context; - ASSERT_EQ(0, duk::top(context)); - duk::push(context, duk::Object{}); - duk::putProperty(context, -1, "x", 123); - duk::putProperty(context, -1, "y", 456); - ASSERT_EQ(1, duk::top(context)); - duk::enumerate(context, -1, 0, true, [] (duk::Context *ctx) { - ASSERT_EQ(DUK_TYPE_STRING, duk::type(ctx, -2)); - ASSERT_EQ(DUK_TYPE_NUMBER, duk::type(ctx, -1)); + ASSERT_EQ(0, duk::top(context)); + duk::push(context, duk::Object{}); + duk::putProperty(context, -1, "x", 123); + duk::putProperty(context, -1, "y", 456); + ASSERT_EQ(1, duk::top(context)); + duk::enumerate(context, -1, 0, true, [] (duk::Context *ctx) { + ASSERT_EQ(DUK_TYPE_STRING, duk::type(ctx, -2)); + ASSERT_EQ(DUK_TYPE_NUMBER, duk::type(ctx, -1)); - if (duk::get<std::string>(ctx, -2) == "x") - ASSERT_EQ(123, duk::get<int>(ctx, -1)); - if (duk::get<std::string>(ctx, -2) == "y") - ASSERT_EQ(456, duk::get<int>(ctx, -1)); - }); - ASSERT_EQ(1, duk::top(context)); + if (duk::get<std::string>(ctx, -2) == "x") + ASSERT_EQ(123, duk::get<int>(ctx, -1)); + if (duk::get<std::string>(ctx, -2) == "y") + ASSERT_EQ(456, duk::get<int>(ctx, -1)); + }); + ASSERT_EQ(1, duk::top(context)); } /* @@ -73,26 +73,26 @@ TEST(Exception, raise) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, DUK_ERR_ERROR, "error thrown"); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, DUK_ERR_ERROR, "error thrown"); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("Error", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("Error", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); } /* @@ -102,191 +102,191 @@ TEST(StandardExceptions, error) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::Error("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::Error("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof Error);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof Error);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("Error", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("Error", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } TEST(StandardExceptions, evalError) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::EvalError("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::EvalError("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof EvalError);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof EvalError);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("EvalError", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("EvalError", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } TEST(StandardExceptions, rangeError) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::RangeError("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::RangeError("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof RangeError);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof RangeError);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("RangeError", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("RangeError", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } TEST(StandardExceptions, referenceError) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::ReferenceError("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::ReferenceError("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof ReferenceError);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof ReferenceError);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("ReferenceError", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("ReferenceError", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } TEST(StandardExceptions, syntaxError) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::SyntaxError("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::SyntaxError("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof SyntaxError);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof SyntaxError);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("SyntaxError", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("SyntaxError", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } TEST(StandardExceptions, typeError) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::TypeError("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::TypeError("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof TypeError);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof TypeError);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("TypeError", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("TypeError", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } TEST(StandardExceptions, uriError) { - duk::UniqueContext context; + duk::UniqueContext context; - duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { - duk::raise(ctx, duk::URIError("error thrown")); + duk::putGlobal(context, "f", duk::Function{[] (duk::Context *ctx) -> duk_idx_t { + duk::raise(ctx, duk::URIError("error thrown")); - return 0; - }}); - duk::evalString(context, - "try {" - " f();" - "} catch (ex) {" - " name = ex.name;" - " message = ex.message;" - " received = true;" - " correct = (ex instanceof URIError);" - "}" - ); + return 0; + }}); + duk::evalString(context, + "try {" + " f();" + "} catch (ex) {" + " name = ex.name;" + " message = ex.message;" + " received = true;" + " correct = (ex instanceof URIError);" + "}" + ); - ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); - ASSERT_EQ("URIError", duk::getGlobal<std::string>(context, "name")); - ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); - ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "received")); + ASSERT_EQ("URIError", duk::getGlobal<std::string>(context, "name")); + ASSERT_EQ("error thrown", duk::getGlobal<std::string>(context, "message")); + ASSERT_TRUE(duk::getGlobal<bool>(context, "correct")); } #endif int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/net/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/net/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -19,11 +19,11 @@ find_package(OpenSSL) if (OPENSSL_FOUND) - code_define_module( - NAME net - SOURCES net.hpp - LIBRARIES $<$<BOOL:${WIN32}>:ws2_32> ${OPENSSL_LIBRARIES} - INCLUDES ${OPENSSL_INCLUDE_DIR} - FLAGS DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}/test/\" - ) -endif () \ No newline at end of file + code_define_module( + NAME net + SOURCES net.hpp + LIBRARIES $<$<BOOL:${WIN32}>:ws2_32> ${OPENSSL_LIBRARIES} + INCLUDES ${OPENSSL_INCLUDE_DIR} + FLAGS DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}/test/\" + ) +endif ()
--- a/modules/net/examples/blocking-accept.cpp Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * blocking-accept.cpp -- example of blocking accept - * - * Options: - * - WITH_PORT (int), the port to use (default: 16000) - * - WITH_TIMEOUT (int), number of seconds before giving up (default: 60) - * - WITH_SSL (bool), true to test with SSL (default: false) - */ - -#include <iostream> - -#include "sockets.h" - -#if !defined(WITH_PORT) -# define WITH_PORT 16000 -#endif - -#if !defined(WITH_TIMEOUT) -# define WITH_TIMEOUT 60 -#endif - -int main() -{ -#if defined(WITH_SSL) - net::SocketTls<net::address::Ip> master; - net::SocketTls<net::address::Ip> client{net::Invalid}; -#else - net::SocketTcp<net::address::Ip> master; - net::SocketTcp<net::address::Ip> client{net::Invalid}; -#endif - - net::Listener<> listener; - - try { - master.set(net::option::SockReuseAddress{true}); - master.bind(net::address::Ip{"*", WITH_PORT}); - master.listen(); - - listener.set(master.handle(), net::Condition::Readable); - listener.wait(std::chrono::seconds(WITH_TIMEOUT)); - - master.accept(client); - } catch (const net::Error &error) { - std::cerr << "error: " << error.what() << std::endl; - std::exit(1); - } - - std::cout << "Client successfully accepted!" << std::endl; - - return 0; -} -
--- a/modules/net/examples/blocking-connect.cpp Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * blocking-connect.cpp -- example of blocking connect - * - * Options: - * - WITH_HOST (string literal), the host to try (default: "malikania.fr") - * - WITH_PORT (int), the port to use (default: 80) - * - WITH_TIMEOUT (int), number of seconds before giving up (default: 30) - * - WITH_SSL (bool), true to test with SSL (default: false) - */ - -#include <iostream> - -#if !defined(WITH_HOST) -# define WITH_HOST "malikania.fr" -#endif - -#if !defined(WITH_PORT) -# define WITH_PORT 80 -#endif - -#if !defined(WITH_TIMEOUT) -# define WITH_TIMEOUT 30 -#endif - -#include "elapsed-timer.h" -#include "sockets.h" - -int main() -{ -#if defined(WITH_SSL) - net::SocketTls<net::address::Ipv4> socket; -#else - net::SocketTcp<net::address::Ipv4> socket; -#endif - - try { - std::cout << "Trying to connect to " << WITH_HOST << ":" << WITH_PORT << std::endl; - socket.connect(net::address::Ip(WITH_HOST, WITH_PORT)); - } catch (const net::Error &error) { - std::cerr << "error: " << error.what() << std::endl; - std::exit(1); - } - - std::cout << "Successfully connected!" << std::endl; - - return 0; -} -
--- a/modules/net/examples/elapsed-timer.cpp Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * elapsed-timer.cpp -- measure elapsed time - * - * Copyright (c) 2013-2015 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "elapsed-timer.h" - -using std::chrono::duration_cast; -using std::chrono::high_resolution_clock; -using std::chrono::milliseconds; - -ElapsedTimer::ElapsedTimer() noexcept -{ - m_last = high_resolution_clock::now(); -} - -void ElapsedTimer::pause() noexcept -{ - /* - * When we put the timer on pause, do not forget to set the already - * elapsed time. - */ - (void)elapsed(); - m_paused = true; -} - -void ElapsedTimer::restart() noexcept -{ - m_paused = false; - m_last = high_resolution_clock::now(); -} - -void ElapsedTimer::reset() noexcept -{ - m_elapsed = 0; - m_last = high_resolution_clock::now(); -} - -unsigned ElapsedTimer::elapsed() noexcept -{ - if (!m_paused) { - m_elapsed += duration_cast<milliseconds>(high_resolution_clock::now() - m_last).count(); - m_last = high_resolution_clock::now(); - } - - return m_elapsed; -} \ No newline at end of file
--- a/modules/net/examples/elapsed-timer.h Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * elapsed-timer.h -- measure elapsed time - * - * Copyright (c) 2013-2015 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _ELAPSED_TIMER_H_ -#define _ELAPSED_TIMER_H_ - -/** - * @file ElapsedTimer.h - * @brief Measure elapsed time - */ - -#include <chrono> - -/** - * @class ElapsedTimer - * @brief Measure elapsed time - * - * This class provides an abstraction to measure elapsed time since the - * construction of the object. - * - * It uses std::chrono::high_resolution_clock for more precision and uses - * milliseconds only. - */ -class ElapsedTimer { -public: - using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; - -private: - TimePoint m_last; - bool m_paused{false}; - unsigned m_elapsed{0}; - -public: - /** - * Construct the elapsed timer, start counting. - */ - ElapsedTimer() noexcept; - - /** - * Put the timer on pause, the already elapsed time is stored. - */ - void pause() noexcept; - - /** - * Restart the timer, does not reset it. - */ - void restart() noexcept; - - /** - * Reset the timer to 0. - */ - void reset() noexcept; - - /** - * Get the number of elapsed milliseconds. - * - * @return the milliseconds - */ - unsigned elapsed() noexcept; -}; - -#endif // !_ELAPSED_TIMER_H_
--- a/modules/net/examples/non-blocking-accept.cpp Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * non-blocking-accept.cpp -- example of total non-blocking accept - * - * Options: - * - WITH_PORT (int), the port to use (default: 16000) - * - WITH_TIMEOUT (int), number of milliseconds before giving up (default: 3000) - * - WITH_SSL (bool), true to test with SSL (default: false) - */ - -#include <iostream> - -#include "elapsed-timer.h" -#include "sockets.h" - -#if !defined(WITH_PORT) -# define WITH_PORT 16000 -#endif - -#if !defined(WITH_TIMEOUT) -# define WITH_TIMEOUT 3000 -#endif - -int main() -{ -#if defined(WITH_SSL) - net::SocketTls<net::address::Ip> master; - net::SocketTls<net::address::Ip> client{net::Invalid}; -#else - net::SocketTcp<net::address::Ip> master; - net::SocketTcp<net::address::Ip> client{net::Invalid}; -#endif - - net::Listener<> listener; - net::Condition cond; - - ElapsedTimer timer; - - // 1. Create the master socket for listening. - try { - master.set(net::option::SockReuseAddress{true}); - master.set(net::option::SockBlockMode{false}); - master.bind(net::address::Ip{"*", WITH_PORT}); - master.listen(); - - listener.set(master.handle(), net::Condition::Readable); - } catch (const net::Error &error) { - std::cerr << "error: " << error.what() << std::endl; - std::exit(1); - } - - while (!client.isOpen() && timer.elapsed() < WITH_TIMEOUT) { - try { - if (!client.isOpen()) { - // 2. Wait for a pre-accept process. - listener.wait(std::chrono::seconds(WITH_TIMEOUT)); - master.accept(client, nullptr, &cond); - client.set(net::option::SockBlockMode(false)); - listener.remove(master.handle()); - - std::cout << "Accepting new client" << std::endl; - - if (cond != net::Condition::None) { - std::cout << "Client accept state not complete" << std::endl; - listener.set(client.handle(), cond); - } - } else { - // 3. Wait for the accept process to complete. - std::cout << "Continuing accept for the client" << std::endl; - - listener.wait(std::chrono::seconds(WITH_TIMEOUT - timer.elapsed())); - client.accept(&cond); - listener.remove(client.handle()); - - if (cond != net::Condition::None) { - std::cout << "Client accept state not complete" << std::endl; - listener.set(client.handle(), cond); - } - } - } catch (const net::Error &error) { - std::cerr << error.function() << ": " << error.what() << std::endl; - std::exit(1); - } - } - - if (client.isOpen()) - std::cout << "Client successfully accepted!" << std::endl; - - return 0; -}
--- a/modules/net/examples/non-blocking-connect.cpp Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * non-blocking-connect.cpp -- example of non blocking connect - * - * Options: - * - WITH_HOST (string literal), the host to try (default: "malikania.fr") - * - WITH_PORT (int), the port to use (default: 80) - * - WITH_TIMEOUT (int), number of milliseconds before giving up (default: 3000) - * - WITH_SSL (bool), true to test with SSL (default: false) - */ - -#include <iostream> - -#if !defined(WITH_HOST) -# define WITH_HOST "malikania.fr" -#endif - -#if !defined(WITH_PORT) -# define WITH_PORT 80 -#endif - -#if !defined(WITH_TIMEOUT) -# define WITH_TIMEOUT 3000 -#endif - -#include "elapsed-timer.h" -#include "sockets.h" - -int main() -{ -#if defined(WITH_SSL) - net::SocketTls<net::address::Ip> socket; -#else - net::SocketTcp<net::address::Ip> socket; -#endif - - net::Listener<> listener; - net::Condition cond; - ElapsedTimer timer; - - // 1. Set to non-blocking. - socket.set(net::option::SockBlockMode(false)); - - try { - std::cout << "Trying to connect to " << WITH_HOST << ":" << WITH_PORT << std::endl; - - // 2. Initial connection process. - socket.connect(net::address::Ip(WITH_HOST, WITH_PORT), &cond); - - while (cond != net::Condition::None && timer.elapsed() < WITH_TIMEOUT) { - listener.remove(socket.handle()); - - // 2. Now complete by waiting for the appropriate condition. - listener.set(socket.handle(), cond); - listener.wait(std::chrono::milliseconds(WITH_TIMEOUT - timer.elapsed())); - socket.connect(&cond); - } - } catch (const net::Error &error) { - std::cerr << "error: " << error.what() << std::endl; - std::exit(1); - } - - std::cout << "Successfully connected!" << std::endl; - - return 0; -}
--- a/modules/net/examples/test.crt Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICITCCAYoCCQCGm4grkVCohjANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJG -UjEPMA0GA1UECAwGRnJhbmNlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0 -eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xNTEwMjYyMDM0NThaFw0yNTEw -MjMyMDM0NThaMFUxCzAJBgNVBAYTAkZSMQ8wDQYDVQQIDAZGcmFuY2UxITAfBgNV -BAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJbG9jYWxob3N0 -MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDp13OqVyOWyv5QWD4xr+Duw6SZ -gU7D5huzsAOcneSI6JUhf+7Ecu6BQ2JGkFn4srIVkMWGQuImETJ8JCpSQH7rk+xO -L9fTTK+TwhP2hW/Rf/b2gWedhJAS+gilqt4JNT7v2wFv+aTtRt/lpTXVSdtpLa/m -Pdy219f6MAPgODJ/7QIDAQABMA0GCSqGSIb3DQEBCwUAA4GBAJSnn/IBn1ZblfzP -rJO/lE1Jwpmx3B7+oR/e4fkZd6JR3s06umGYWr2H+TPl/5dj9x0gPokhoIL9zCGq -SxCPnOeaxjBkw7yh3Ks6m3xKxmK4aMpAtBHtwmbfQyIcgz71/lfCzbJ3WcKpn1ig -IZbByt5QSSPcFORRzJJa35eHBdfX ------END CERTIFICATE-----
--- a/modules/net/examples/test.key Wed Jun 15 11:59:17 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQDp13OqVyOWyv5QWD4xr+Duw6SZgU7D5huzsAOcneSI6JUhf+7E -cu6BQ2JGkFn4srIVkMWGQuImETJ8JCpSQH7rk+xOL9fTTK+TwhP2hW/Rf/b2gWed -hJAS+gilqt4JNT7v2wFv+aTtRt/lpTXVSdtpLa/mPdy219f6MAPgODJ/7QIDAQAB -AoGBANDt4ndQkgi56A1rOm50gVlzTg6lPPXFE/0xB5kYbcdxX0VmI7Q8KCMwTI9V -jD2rk3e3OPSjr6FpfhzyxylkXMBz2BL5NRNPowCJbiMgZOUIzlcWPKo0tgf1bZJx -YdB5U003ISGPPBjVOAjyizY7tJnaNvbpLQ0hbIAsvHPEAOnBAkEA9r3g8NQjPrvb -oIr5SMIxM8HDJ1/q+MEBSFtRFzQpmur6P64Jsu96zCyencUYTxs0L/sottrj6dPC -vjGCc6PjsQJBAPKdqK1knJv6Y95M2bnEwrymCFVdxCi7AxObStB+bg/+7mMCUqqX -j2g71bfvhYakHV7CiaYrrORChwj6vTbimv0CQGpd2IZ5LOhyW2+N+YDgFg3Vzac/ -ti+eJEto8kAqgHUELvUctZmpmypBYe9pc91GQO0ePKL3IaE/ZIhRF4d6c0ECQH9A -XiaD7PiKvjLs0A31u8ZCt4A+7BII9LYl73mntobBSbu4ji9Xyyn6qEAPa1ORZK49 -DwGPSuF2W2lESlYtSOkCQGrtczhx3IyJjk5e2Y1i/UddPKjviAysCSzcW6aVTNr9 -Y2L0sWmva2FKnkl9FDuEqxvmGr6OOkr5Ll7aWLzJri8= ------END RSA PRIVATE KEY-----
--- a/modules/net/net.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/net/net.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -877,7 +877,7 @@ inline void finish() noexcept { #if defined(_WIN32) - WSACleanup(); + WSACleanup(); #endif } @@ -888,22 +888,22 @@ inline void init() noexcept { #if defined(_WIN32) - static std::atomic<bool> initialized; - static std::mutex mutex; - - std::lock_guard<std::mutex> lock(mutex); - - if (!initialized) { - initialized = true; - - WSADATA wsa; - WSAStartup(MAKEWORD(2, 2), &wsa); - - // If NET_NO_AUTO_INIT is not set then the user must also call finish himself. + static std::atomic<bool> initialized; + static std::mutex mutex; + + std::lock_guard<std::mutex> lock(mutex); + + if (!initialized) { + initialized = true; + + WSADATA wsa; + WSAStartup(MAKEWORD(2, 2), &wsa); + + // If NET_NO_AUTO_INIT is not set then the user must also call finish himself. #if !defined(NET_NO_AUTO_INIT) - atexit(finish); + atexit(finish); #endif - } + } #endif } @@ -916,25 +916,25 @@ inline std::string error(int errn) { #if defined(_WIN32) - LPSTR str = nullptr; - std::string errmsg = "Unknown error"; - - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errn, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&str, 0, NULL); - - - if (str) { - errmsg = std::string(str); - LocalFree(str); - } - - return errmsg; + LPSTR str = nullptr; + std::string errmsg = "Unknown error"; + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errn, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&str, 0, NULL); + + + if (str) { + errmsg = std::string(str); + LocalFree(str); + } + + return errmsg; #else - return strerror(errn); + return strerror(errn); #endif } @@ -946,9 +946,9 @@ inline std::string error() { #if defined(_WIN32) - return error(WSAGetLastError()); + return error(WSAGetLastError()); #else - return error(errno); + return error(errno); #endif } @@ -964,8 +964,8 @@ * \brief Which OpenSSL method to use. */ enum Method { - Tlsv1, //!< TLS v1.2 (recommended) - Sslv3 //!< SSLv3 + Tlsv1, //!< TLS v1.2 (recommended) + Sslv3 //!< SSLv3 }; /** @@ -974,22 +974,22 @@ */ inline void init() noexcept { - static std::atomic<bool> initialized; - static std::mutex mutex; - - std::lock_guard<std::mutex> lock(mutex); - - if (!initialized) { - initialized = true; - - SSL_library_init(); - SSL_load_error_strings(); - OpenSSL_add_all_algorithms(); + static std::atomic<bool> initialized; + static std::mutex mutex; + + std::lock_guard<std::mutex> lock(mutex); + + if (!initialized) { + initialized = true; + + SSL_library_init(); + SSL_load_error_strings(); + OpenSSL_add_all_algorithms(); #if !defined(NET_NO_AUTO_SSL_INIT) - atexit(finish); + atexit(finish); #endif - } + } } /** @@ -997,7 +997,7 @@ */ inline void finish() noexcept { - ERR_free_strings(); + ERR_free_strings(); } } // !ssl @@ -1016,83 +1016,83 @@ */ class Error : public std::exception { private: - std::string m_message; + std::string m_message; public: - /** - * Construct the error using the specified error from the system. - * - * \param code the error code - * \warning the code must be a Winsock error or errno on Unix - */ - inline Error(int code) noexcept - : m_message(error(code)) - { - } - - /** - * Construct the error using the custom message. - * - * \param message the message - */ - inline Error(std::string message) noexcept - : m_message(std::move(message)) - { - } - - /** - * Construct the error using the last message from the system. - */ - inline Error() noexcept + /** + * Construct the error using the specified error from the system. + * + * \param code the error code + * \warning the code must be a Winsock error or errno on Unix + */ + inline Error(int code) noexcept + : m_message(error(code)) + { + } + + /** + * Construct the error using the custom message. + * + * \param message the message + */ + inline Error(std::string message) noexcept + : m_message(std::move(message)) + { + } + + /** + * Construct the error using the last message from the system. + */ + inline Error() noexcept #if defined(_WIN32) - : Error(WSAGetLastError()) + : Error(WSAGetLastError()) #else - : Error(errno) + : Error(errno) #endif - { - } - - /** - * Get the error (only the error content). - * - * \return the error - */ - const char *what() const noexcept override - { - return m_message.c_str(); - } + { + } + + /** + * Get the error (only the error content). + * + * \return the error + */ + const char *what() const noexcept override + { + return m_message.c_str(); + } }; class TimeoutError : public std::exception { public: - const char *what() const noexcept override - { - return std::strerror(ETIMEDOUT); - } + const char *what() const noexcept override + { + return std::strerror(ETIMEDOUT); + } }; class WouldBlockError : public std::exception { public: - const char *what() const noexcept override - { - return std::strerror(EWOULDBLOCK); - } + const char *what() const noexcept override + { + return std::strerror(EWOULDBLOCK); + } }; class WantWriteError : public std::exception { public: - const char *what() const noexcept override - { - return "operation requires writing to complete"; - } + const char *what() const noexcept override + { + return "operation requires writing to complete"; + } }; class WantReadError : public std::exception { public: - const char *what() const noexcept override - { - return "operation requires read to complete"; - } + const char *what() const noexcept override + { + return "operation requires read to complete"; + } }; /* @@ -1110,9 +1110,9 @@ * operations, the user must wait the socket to be readable or writable. This can be checked with Socket::condition. */ enum class Condition { - None, //!< No condition is required - Readable = (1 << 0), //!< The socket must be readable - Writable = (1 << 1) //!< The socket must be writable + None, //!< No condition is required + Readable = (1 << 0), //!< The socket must be readable + Writable = (1 << 1) //!< The socket must be writable }; /** @@ -1124,7 +1124,7 @@ */ inline Condition operator^(Condition v1, Condition v2) noexcept { - return static_cast<Condition>(static_cast<int>(v1) ^ static_cast<int>(v2)); + return static_cast<Condition>(static_cast<int>(v1) ^ static_cast<int>(v2)); } /** @@ -1136,7 +1136,7 @@ */ inline Condition operator&(Condition v1, Condition v2) noexcept { - return static_cast<Condition>(static_cast<int>(v1) & static_cast<int>(v2)); + return static_cast<Condition>(static_cast<int>(v1) & static_cast<int>(v2)); } /** @@ -1148,7 +1148,7 @@ */ inline Condition operator|(Condition v1, Condition v2) noexcept { - return static_cast<Condition>(static_cast<int>(v1) | static_cast<int>(v2)); + return static_cast<Condition>(static_cast<int>(v1) | static_cast<int>(v2)); } /** @@ -1159,7 +1159,7 @@ */ inline Condition operator~(Condition v) noexcept { - return static_cast<Condition>(~static_cast<int>(v)); + return static_cast<Condition>(~static_cast<int>(v)); } /** @@ -1171,9 +1171,9 @@ */ inline Condition &operator|=(Condition &v1, Condition v2) noexcept { - v1 = static_cast<Condition>(static_cast<int>(v1) | static_cast<int>(v2)); - - return v1; + v1 = static_cast<Condition>(static_cast<int>(v1) | static_cast<int>(v2)); + + return v1; } /** @@ -1185,9 +1185,9 @@ */ inline Condition &operator&=(Condition &v1, Condition v2) noexcept { - v1 = static_cast<Condition>(static_cast<int>(v1) & static_cast<int>(v2)); - - return v1; + v1 = static_cast<Condition>(static_cast<int>(v1) & static_cast<int>(v2)); + + return v1; } /** @@ -1199,9 +1199,9 @@ */ inline Condition &operator^=(Condition &v1, Condition v2) noexcept { - v1 = static_cast<Condition>(static_cast<int>(v1) ^ static_cast<int>(v2)); - - return v1; + v1 = static_cast<Condition>(static_cast<int>(v1) ^ static_cast<int>(v2)); + + return v1; } /* @@ -1235,299 +1235,299 @@ template <typename Address> class Socket { protected: - /** - * The native handle. - */ - Handle m_handle{Invalid}; + /** + * The native handle. + */ + Handle m_handle{Invalid}; public: - /** - * Create a socket handle. - * - * This is the primary function and the only one that creates the socket handle, all other constructors - * are just overloaded functions. - * - * \param domain the domain AF_* - * \param type the type SOCK_* - * \param protocol the protocol - * \throw Error on errors - */ - Socket(int domain, int type, int protocol) - { + /** + * Create a socket handle. + * + * This is the primary function and the only one that creates the socket handle, all other constructors + * are just overloaded functions. + * + * \param domain the domain AF_* + * \param type the type SOCK_* + * \param protocol the protocol + * \throw Error on errors + */ + Socket(int domain, int type, int protocol) + { #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif - m_handle = ::socket(domain, type, protocol); - - if (m_handle == Invalid) - throw Error(); - } - - /** - * Create the socket with an already defined handle and its protocol. - * - * \param handle the handle - * \param protocol the protocol - */ - explicit inline Socket(Handle handle) noexcept - : m_handle(handle) - { - } - - /** - * Create an invalid socket. Can be used when you cannot instanciate the socket immediately. - */ - explicit inline Socket(std::nullptr_t) noexcept - : m_handle(Invalid) - { - } - - /** - * Copy constructor deleted. - */ - Socket(const Socket &) = delete; - - /** - * Transfer ownership from other to this. - * - * \param other the other socket - */ - inline Socket(Socket &&other) noexcept - : m_handle(other.m_handle) - { - other.m_handle = Invalid; - } - - /** - * Default destructor. - */ - virtual ~Socket() - { - close(); - } - - /** - * Tells if the socket is not invalid. - * - * \return true if not invalid - */ - inline bool isOpen() const noexcept - { - return m_handle != Invalid; - } - - /** - * Set an option for the socket. Wrapper of setsockopt(2). - * - * \pre isOpen() - * \param level the setting level - * \param name the name - * \param arg the value - * \throw Error on errors - */ - template <typename Argument> - inline void set(int level, int name, const Argument &arg) - { - assert(m_handle != Invalid); - - if (::setsockopt(m_handle, level, name, (ConstArg)&arg, sizeof (arg)) == Failure) - throw Error(); - } - - /** - * Object-oriented option setter. - * - * The object must have `set(Socket<Address> &) const`. - * - * \pre isOpen() - * \param option the option - * \throw Error on errors - */ - template <typename Option> - inline void set(const Option &option) - { - assert(m_handle != Invalid); - - option.set(*this); - } - - /** - * Get an option for the socket. Wrapper of getsockopt(2). - * - * \pre isOpen() - * \param level the setting level - * \param name the name - * \return the value - * \throw Error on errors - */ - template <typename Argument> - Argument get(int level, int name) - { - assert(m_handle != Invalid); - - Argument desired, result{}; - socklen_t size = sizeof (result); - - if (::getsockopt(m_handle, level, name, (Arg)&desired, &size) == Failure) - throw Error(); - - std::memcpy(&result, &desired, size); - - return result; - } - - /** - * Object-oriented option getter. - * - * The object must have `T get(Socket<Address> &) const`, T can be any type and it is the value - * returned from this function. - * - * \pre isOpen() - * \return the same value as get() in the option - * \throw Error on errors - */ - template <typename Option> - inline auto get() -> decltype(std::declval<Option>().get(*this)) - { - assert(m_handle != Invalid); - - return Option().get(*this); - } - - /** - * Get the native handle. - * - * \return the handle - * \warning Not portable - */ - inline Handle handle() const noexcept - { - return m_handle; - } - - /** - * Bind using a native address. - * - * \pre isOpen() - * \param address the address - * \param length the size - * \throw Error on errors - */ - inline void bind(const sockaddr *address, socklen_t length) - { - assert(m_handle != Invalid); - - if (::bind(m_handle, address, length) == Failure) - throw Error(); - } - - /** - * Overload that takes an address. - * - * \pre isOpen() - * \param address the address - * \throw Error on errors - */ - inline void bind(const Address &address) - { - assert(m_handle != Invalid); - - bind(address.address(), address.length()); - } - - /** - * Listen for pending connection. - * - * \pre isOpen() - * \param max the maximum number - * \throw Error on errors - */ - inline void listen(int max = 128) - { - assert(m_handle != Invalid); - - if (::listen(this->m_handle, max) == Failure) - throw Error(); - } - - /** - * Get the local name. This is a wrapper of getsockname(). - * - * \pre isOpen() - * \return the address - * \throw Error on failures - */ - Address getsockname() const - { - assert(m_handle != Invalid); - - sockaddr_storage ss; - socklen_t length = sizeof (sockaddr_storage); - - if (::getsockname(m_handle, reinterpret_cast<sockaddr *>(&ss), &length) == Failure) - throw Error(); - - return Address(reinterpret_cast<sockaddr *>(&ss), length); - } - - /** - * Get connected address. This is a wrapper for getpeername(). - * - * \pre isOpen() - * \return the address - * \throw Error on failures - */ - Address getpeername() const - { - assert(m_handle != Invalid); - - sockaddr_storage ss; - socklen_t length = sizeof (sockaddr_storage); - - if (::getpeername(m_handle, reinterpret_cast<sockaddr *>(&ss), &length) == Failure) - throw Error(); - - return Address(reinterpret_cast<sockaddr *>(&ss), length); - } - - /** - * Close the socket. - * - * Automatically called from the destructor. - */ - void close() - { - if (m_handle != Invalid) { + m_handle = ::socket(domain, type, protocol); + + if (m_handle == Invalid) + throw Error(); + } + + /** + * Create the socket with an already defined handle and its protocol. + * + * \param handle the handle + * \param protocol the protocol + */ + explicit inline Socket(Handle handle) noexcept + : m_handle(handle) + { + } + + /** + * Create an invalid socket. Can be used when you cannot instanciate the socket immediately. + */ + explicit inline Socket(std::nullptr_t) noexcept + : m_handle(Invalid) + { + } + + /** + * Copy constructor deleted. + */ + Socket(const Socket &) = delete; + + /** + * Transfer ownership from other to this. + * + * \param other the other socket + */ + inline Socket(Socket &&other) noexcept + : m_handle(other.m_handle) + { + other.m_handle = Invalid; + } + + /** + * Default destructor. + */ + virtual ~Socket() + { + close(); + } + + /** + * Tells if the socket is not invalid. + * + * \return true if not invalid + */ + inline bool isOpen() const noexcept + { + return m_handle != Invalid; + } + + /** + * Set an option for the socket. Wrapper of setsockopt(2). + * + * \pre isOpen() + * \param level the setting level + * \param name the name + * \param arg the value + * \throw Error on errors + */ + template <typename Argument> + inline void set(int level, int name, const Argument &arg) + { + assert(m_handle != Invalid); + + if (::setsockopt(m_handle, level, name, (ConstArg)&arg, sizeof (arg)) == Failure) + throw Error(); + } + + /** + * Object-oriented option setter. + * + * The object must have `set(Socket<Address> &) const`. + * + * \pre isOpen() + * \param option the option + * \throw Error on errors + */ + template <typename Option> + inline void set(const Option &option) + { + assert(m_handle != Invalid); + + option.set(*this); + } + + /** + * Get an option for the socket. Wrapper of getsockopt(2). + * + * \pre isOpen() + * \param level the setting level + * \param name the name + * \return the value + * \throw Error on errors + */ + template <typename Argument> + Argument get(int level, int name) + { + assert(m_handle != Invalid); + + Argument desired, result{}; + socklen_t size = sizeof (result); + + if (::getsockopt(m_handle, level, name, (Arg)&desired, &size) == Failure) + throw Error(); + + std::memcpy(&result, &desired, size); + + return result; + } + + /** + * Object-oriented option getter. + * + * The object must have `T get(Socket<Address> &) const`, T can be any type and it is the value + * returned from this function. + * + * \pre isOpen() + * \return the same value as get() in the option + * \throw Error on errors + */ + template <typename Option> + inline auto get() -> decltype(std::declval<Option>().get(*this)) + { + assert(m_handle != Invalid); + + return Option().get(*this); + } + + /** + * Get the native handle. + * + * \return the handle + * \warning Not portable + */ + inline Handle handle() const noexcept + { + return m_handle; + } + + /** + * Bind using a native address. + * + * \pre isOpen() + * \param address the address + * \param length the size + * \throw Error on errors + */ + inline void bind(const sockaddr *address, socklen_t length) + { + assert(m_handle != Invalid); + + if (::bind(m_handle, address, length) == Failure) + throw Error(); + } + + /** + * Overload that takes an address. + * + * \pre isOpen() + * \param address the address + * \throw Error on errors + */ + inline void bind(const Address &address) + { + assert(m_handle != Invalid); + + bind(address.address(), address.length()); + } + + /** + * Listen for pending connection. + * + * \pre isOpen() + * \param max the maximum number + * \throw Error on errors + */ + inline void listen(int max = 128) + { + assert(m_handle != Invalid); + + if (::listen(this->m_handle, max) == Failure) + throw Error(); + } + + /** + * Get the local name. This is a wrapper of getsockname(). + * + * \pre isOpen() + * \return the address + * \throw Error on failures + */ + Address getsockname() const + { + assert(m_handle != Invalid); + + sockaddr_storage ss; + socklen_t length = sizeof (sockaddr_storage); + + if (::getsockname(m_handle, reinterpret_cast<sockaddr *>(&ss), &length) == Failure) + throw Error(); + + return Address(reinterpret_cast<sockaddr *>(&ss), length); + } + + /** + * Get connected address. This is a wrapper for getpeername(). + * + * \pre isOpen() + * \return the address + * \throw Error on failures + */ + Address getpeername() const + { + assert(m_handle != Invalid); + + sockaddr_storage ss; + socklen_t length = sizeof (sockaddr_storage); + + if (::getpeername(m_handle, reinterpret_cast<sockaddr *>(&ss), &length) == Failure) + throw Error(); + + return Address(reinterpret_cast<sockaddr *>(&ss), length); + } + + /** + * Close the socket. + * + * Automatically called from the destructor. + */ + void close() + { + if (m_handle != Invalid) { #if defined(_WIN32) - ::closesocket(m_handle); + ::closesocket(m_handle); #else - ::close(m_handle); + ::close(m_handle); #endif - m_handle = Invalid; - } - } - - /** - * Assignment operator forbidden. - * - * \return *this - */ - Socket &operator=(const Socket &) = delete; - - /** - * Transfer ownership from other to this. The other socket is left - * invalid and will not be closed. - * - * \param other the other socket - * \return this - */ - Socket &operator=(Socket &&other) noexcept - { - m_handle = other.m_handle; - other.m_handle = Invalid; - - return *this; - } + m_handle = Invalid; + } + } + + /** + * Assignment operator forbidden. + * + * \return *this + */ + Socket &operator=(const Socket &) = delete; + + /** + * Transfer ownership from other to this. The other socket is left + * invalid and will not be closed. + * + * \param other the other socket + * \return this + */ + Socket &operator=(Socket &&other) noexcept + { + m_handle = other.m_handle; + other.m_handle = Invalid; + + return *this; + } }; /** @@ -1540,7 +1540,7 @@ template <typename Address> inline bool operator==(const Socket<Address> &s1, const Socket<Address> &s2) { - return s1.handle() == s2.handle(); + return s1.handle() == s2.handle(); } /** @@ -1553,7 +1553,7 @@ template <typename Address> inline bool operator!=(const Socket<Address> &s1, const Socket<Address> &s2) { - return s1.handle() != s2.handle(); + return s1.handle() != s2.handle(); } /** @@ -1566,7 +1566,7 @@ template <typename Address> inline bool operator<(const Socket<Address> &s1, const Socket<Address> &s2) { - return s1.handle() < s2.handle(); + return s1.handle() < s2.handle(); } /** @@ -1579,7 +1579,7 @@ template <typename Address> inline bool operator>(const Socket<Address> &s1, const Socket<Address> &s2) { - return s1.handle() > s2.handle(); + return s1.handle() > s2.handle(); } /** @@ -1592,7 +1592,7 @@ template <typename Address> inline bool operator<=(const Socket<Address> &s1, const Socket<Address> &s2) { - return s1.handle() <= s2.handle(); + return s1.handle() <= s2.handle(); } /** @@ -1605,7 +1605,7 @@ template <typename Address> inline bool operator>=(const Socket<Address> &s1, const Socket<Address> &s2) { - return s1.handle() >= s2.handle(); + return s1.handle() >= s2.handle(); } /** @@ -1618,146 +1618,146 @@ template <typename Address> class TcpSocket : public Socket<Address> { public: - using Socket<Address>::Socket; - - TcpSocket() - : Socket<Address>(Address().domain(), SOCK_STREAM, 0) - { - } - - /** - * Initiate connection. - * - * \param address the address - * \param length the address length - * \throw WouldBlockError if the socket is marked non-blocking and connection cannot be established immediately - * \throw Error on other errors - */ - void connect(const sockaddr *address, socklen_t length) - { - if (::connect(this->m_handle, address, length) == Failure) { + using Socket<Address>::Socket; + + TcpSocket() + : Socket<Address>(Address().domain(), SOCK_STREAM, 0) + { + } + + /** + * Initiate connection. + * + * \param address the address + * \param length the address length + * \throw WouldBlockError if the socket is marked non-blocking and connection cannot be established immediately + * \throw Error on other errors + */ + void connect(const sockaddr *address, socklen_t length) + { + if (::connect(this->m_handle, address, length) == Failure) { #if defined(_WIN32) - int error = WSAGetLastError(); - - if (error == WSAEWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(error); + int error = WSAGetLastError(); + + if (error == WSAEWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(error); #else - if (errno == EINPROGRESS) - throw WouldBlockError(); - else - throw Error(); + if (errno == EINPROGRESS) + throw WouldBlockError(); + else + throw Error(); #endif - } - } - - /** - * Overloaded function. - * - * \param address the address - * \throw WouldBlockError if the socket is marked non-blocking and connection cannot be established immediately - * \throw Error on other errors - */ - void connect(const Address &address) - { - connect(address.address(), address.length()); - } - - /** - * Accept a new client. - * - * If there are no pending connection, an invalid socket is returned. - * - * \param sc the socket - * \return the new socket - * \throw WouldBlockError if the socket is marked non-blocking and no connection are available - * \throw Error on other errors - */ - TcpSocket<Address> accept() - { - Handle handle = ::accept(this->m_handle, nullptr, 0); - - if (handle == Invalid) { + } + } + + /** + * Overloaded function. + * + * \param address the address + * \throw WouldBlockError if the socket is marked non-blocking and connection cannot be established immediately + * \throw Error on other errors + */ + void connect(const Address &address) + { + connect(address.address(), address.length()); + } + + /** + * Accept a new client. + * + * If there are no pending connection, an invalid socket is returned. + * + * \param sc the socket + * \return the new socket + * \throw WouldBlockError if the socket is marked non-blocking and no connection are available + * \throw Error on other errors + */ + TcpSocket<Address> accept() + { + Handle handle = ::accept(this->m_handle, nullptr, 0); + + if (handle == Invalid) { #if defined(_WIN32) - int error = WSAGetLastError(); - - if (error == WSAEWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(error); + int error = WSAGetLastError(); + + if (error == WSAEWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(error); #else - if (errno == EWOULDBLOCK || errno == EAGAIN) - throw WouldBlockError(); - else - throw Error(); + if (errno == EWOULDBLOCK || errno == EAGAIN) + throw WouldBlockError(); + else + throw Error(); #endif - } - - return TcpSocket<Address>(handle); - } - - /** - * Receive some data. - * - * \param data the destination buffer - * \param length the buffer length - * \return the number of bytes received - */ - unsigned recv(void *data, unsigned length) - { - int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); - int nbread = ::recv(this->m_handle, (Arg)data, max, 0); - - if (nbread == Failure) { + } + + return TcpSocket<Address>(handle); + } + + /** + * Receive some data. + * + * \param data the destination buffer + * \param length the buffer length + * \return the number of bytes received + */ + unsigned recv(void *data, unsigned length) + { + int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); + int nbread = ::recv(this->m_handle, (Arg)data, max, 0); + + if (nbread == Failure) { #if defined(_WIN32) - int error = WSAGetLastError(); - - if (error == WSAEWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(error); + int error = WSAGetLastError(); + + if (error == WSAEWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(error); #else - if (errno == EAGAIN || errno == EWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(); + if (errno == EAGAIN || errno == EWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(); #endif - } - - return static_cast<unsigned>(nbread); - } - - /** - * Send some data. - * - * \param data the data to send - * \param length the length - * \return the number of bytes sent - */ - unsigned send(const void *data, unsigned length) - { - int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); - int nbsent = ::send(this->m_handle, (ConstArg)data, max, 0); - - if (nbsent == Failure) { + } + + return static_cast<unsigned>(nbread); + } + + /** + * Send some data. + * + * \param data the data to send + * \param length the length + * \return the number of bytes sent + */ + unsigned send(const void *data, unsigned length) + { + int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); + int nbsent = ::send(this->m_handle, (ConstArg)data, max, 0); + + if (nbsent == Failure) { #if defined(_WIN32) - int error = WSAGetLastError(); - - if (error == WSAEWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(); + int error = WSAGetLastError(); + + if (error == WSAEWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(); #else - if (errno == EAGAIN || errno == EWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(); + if (errno == EAGAIN || errno == EWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(); #endif - } - - return static_cast<unsigned>(nbsent); - } + } + + return static_cast<unsigned>(nbsent); + } }; /** @@ -1768,71 +1768,71 @@ template <typename Address> class UdpSocket { public: - /** - * Receive some data. - * - * \param data the data - * \param length the length - * \param address the source address - * \param addrlen the source address in/out length - * \return the number of bytes received - */ - unsigned recvfrom(void *data, unsigned length, sockaddr *address, socklen_t *addrlen) - { - int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); - int nbread = ::recvfrom(this->m_handle, (Arg)data, max, 0, address, addrlen); - - if (nbread == Failure) { + /** + * Receive some data. + * + * \param data the data + * \param length the length + * \param address the source address + * \param addrlen the source address in/out length + * \return the number of bytes received + */ + unsigned recvfrom(void *data, unsigned length, sockaddr *address, socklen_t *addrlen) + { + int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); + int nbread = ::recvfrom(this->m_handle, (Arg)data, max, 0, address, addrlen); + + if (nbread == Failure) { #if defined(_WIN32) - int error = WSAGetLastError(); - - if (error == EWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(error); + int error = WSAGetLastError(); + + if (error == EWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(error); #else - if (errno == EAGAIN || errno == EWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(); + if (errno == EAGAIN || errno == EWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(); #endif - } - - return static_cast<unsigned>(nbread); - } - - /** - * Send some data. - * - * \param data the data to send - * \param length the data length - * \param address the destination address - * \param addrlen the destination address length - * \return the number of bytes sent - */ - unsigned sendto(const void *data, unsigned length, const sockaddr *address, socklen_t addrlen) - { - int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); - int nbsent = ::sendto(this->m_handle, (ConstArg)data, max, 0, address, addrlen); - - if (nbsent == Failure) { + } + + return static_cast<unsigned>(nbread); + } + + /** + * Send some data. + * + * \param data the data to send + * \param length the data length + * \param address the destination address + * \param addrlen the destination address length + * \return the number of bytes sent + */ + unsigned sendto(const void *data, unsigned length, const sockaddr *address, socklen_t addrlen) + { + int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); + int nbsent = ::sendto(this->m_handle, (ConstArg)data, max, 0, address, addrlen); + + if (nbsent == Failure) { #if defined(_WIN32) - int error = WSAGetLastError(); - - if (error == EWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(error); + int error = WSAGetLastError(); + + if (error == EWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(error); #else - if (errno == EAGAIN || errno == EWOULDBLOCK) - throw WouldBlockError(); - else - throw Error(); + if (errno == EAGAIN || errno == EWOULDBLOCK) + throw WouldBlockError(); + else + throw Error(); #endif - } - - return static_cast<unsigned>(nbsent); - } + } + + return static_cast<unsigned>(nbsent); + } }; #if !defined(NET_NO_SSL) @@ -1845,156 +1845,156 @@ template <typename Address> class TlsSocket : public Socket<Address> { public: - /** - * \brief SSL connection mode. - */ - enum Mode { - /// Use Server when you accept a socket server side. - Server, - - /// Use Client when you connect to a server. - Client - }; + /** + * \brief SSL connection mode. + */ + enum Mode { + /// Use Server when you accept a socket server side. + Server, + + /// Use Client when you connect to a server. + Client + }; private: - using Context = std::shared_ptr<SSL_CTX>; - using Ssl = std::unique_ptr<SSL, void (*)(SSL *)>; - - Context m_context; - Ssl m_ssl{nullptr, nullptr}; - - inline std::string error() - { - BIO *bio = BIO_new(BIO_s_mem()); - char *buf = nullptr; - - ERR_print_errors(bio); - - std::size_t length = BIO_get_mem_data (bio, &buf); - std::string result(buf, length); - - BIO_free(bio); - - return result; - } - - template <typename Function> - void wrap(Function &&function) - { - auto ret = function(); - - if (ret <= 0) { - int no = SSL_get_error(m_ssl.get(), ret); - - switch (no) { - case SSL_ERROR_WANT_READ: - throw WantReadError(); - case SSL_ERROR_WANT_WRITE: - throw WantWriteError(); - default: - throw Error(error()); - } - } - } + using Context = std::shared_ptr<SSL_CTX>; + using Ssl = std::unique_ptr<SSL, void (*)(SSL *)>; + + Context m_context; + Ssl m_ssl{nullptr, nullptr}; + + inline std::string error() + { + BIO *bio = BIO_new(BIO_s_mem()); + char *buf = nullptr; + + ERR_print_errors(bio); + + std::size_t length = BIO_get_mem_data (bio, &buf); + std::string result(buf, length); + + BIO_free(bio); + + return result; + } + + template <typename Function> + void wrap(Function &&function) + { + auto ret = function(); + + if (ret <= 0) { + int no = SSL_get_error(m_ssl.get(), ret); + + switch (no) { + case SSL_ERROR_WANT_READ: + throw WantReadError(); + case SSL_ERROR_WANT_WRITE: + throw WantWriteError(); + default: + throw Error(error()); + } + } + } public: - /** - * Wrap a socket around an existing one. - * - * \param sock the TCP socket - * \param mode the mode - */ - inline TlsSocket(TcpSocket<Address> &sock, Mode mode = Server, const SSL_METHOD *method = TLSv1_method()) - : Socket<Address>(sock.handle()) - { + /** + * Wrap a socket around an existing one. + * + * \param sock the TCP socket + * \param mode the mode + */ + inline TlsSocket(TcpSocket<Address> &sock, Mode mode = Server, const SSL_METHOD *method = TLSv1_method()) + : Socket<Address>(sock.handle()) + { #if !defined(NET_NO_SSL_AUTO_INIT) - ssl::init(); + ssl::init(); #endif - m_context = Context(SSL_CTX_new(method), SSL_CTX_free); - m_ssl = Ssl(SSL_new(m_context.get()), SSL_free); - - SSL_set_fd(m_ssl.get(), this->m_handle); - - if (mode == Server) - SSL_set_accept_state(m_ssl.get()); - else - SSL_set_connect_state(m_ssl.get()); - } - - /** - * Use the specified private key file. - * - * \param file the path to the private key - */ - inline void setPrivateKey(std::string file, int type = SSL_FILETYPE_PEM) noexcept - { - if (SSL_use_PrivateKey_file(m_ssl.get(), file.c_str(), type) != 1) - throw Error(error()); - } - - /** - * Use the specified certificate file. - * - * \param file the path to the file - */ - inline void setCertificate(std::string file, int type = SSL_FILETYPE_PEM) noexcept - { - if (SSL_use_certificate_file(m_ssl.get(), file.c_str(), type) != 1) - throw Error(error()); - } - - /** - * Do handshake, needed in some case when you have non blocking sockets. - * - * \param address the address - * \param length the address length - * \param cond the condition - */ - void handshake() - { - wrap([&] () -> int { - SSL_do_handshake(m_ssl.get()); - }); - } - - /** - * Receive some data. - * - * \param data the destination buffer - * \param length the buffer length - * \return the number of bytes received - */ - unsigned recv(void *data, unsigned length) - { - int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); - int nbread = 0; - - wrap([&] () -> int { - return (nbread = SSL_read(m_ssl.get(), data, max)); - }); - - return static_cast<unsigned>(nbread < 0 ? 0 : nbread); - } - - /** - * Send some data. - * - * \param data the data to send - * \param length the length - * \param cond the condition - * \return the number of bytes sent - */ - unsigned send(const void *data, unsigned length) - { - int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); - int nbsent = 0; - - wrap([&] () -> int { - return (nbsent = SSL_write(m_ssl.get(), data, max)); - }); - - return static_cast<unsigned>(nbsent < 0 ? 0 : nbsent); - } + m_context = Context(SSL_CTX_new(method), SSL_CTX_free); + m_ssl = Ssl(SSL_new(m_context.get()), SSL_free); + + SSL_set_fd(m_ssl.get(), this->m_handle); + + if (mode == Server) + SSL_set_accept_state(m_ssl.get()); + else + SSL_set_connect_state(m_ssl.get()); + } + + /** + * Use the specified private key file. + * + * \param file the path to the private key + */ + inline void setPrivateKey(std::string file, int type = SSL_FILETYPE_PEM) noexcept + { + if (SSL_use_PrivateKey_file(m_ssl.get(), file.c_str(), type) != 1) + throw Error(error()); + } + + /** + * Use the specified certificate file. + * + * \param file the path to the file + */ + inline void setCertificate(std::string file, int type = SSL_FILETYPE_PEM) noexcept + { + if (SSL_use_certificate_file(m_ssl.get(), file.c_str(), type) != 1) + throw Error(error()); + } + + /** + * Do handshake, needed in some case when you have non blocking sockets. + * + * \param address the address + * \param length the address length + * \param cond the condition + */ + void handshake() + { + wrap([&] () -> int { + SSL_do_handshake(m_ssl.get()); + }); + } + + /** + * Receive some data. + * + * \param data the destination buffer + * \param length the buffer length + * \return the number of bytes received + */ + unsigned recv(void *data, unsigned length) + { + int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); + int nbread = 0; + + wrap([&] () -> int { + return (nbread = SSL_read(m_ssl.get(), data, max)); + }); + + return static_cast<unsigned>(nbread < 0 ? 0 : nbread); + } + + /** + * Send some data. + * + * \param data the data to send + * \param length the length + * \param cond the condition + * \return the number of bytes sent + */ + unsigned send(const void *data, unsigned length) + { + int max = length > INT_MAX ? INT_MAX : static_cast<int>(length); + int nbsent = 0; + + wrap([&] () -> int { + return (nbsent = SSL_write(m_ssl.get(), data, max)); + }); + + return static_cast<unsigned>(nbsent < 0 ? 0 : nbsent); + } }; #endif // !NET_NO_SSL @@ -2012,75 +2012,75 @@ */ class Generic { private: - sockaddr_storage m_address; - socklen_t m_length{0}; + sockaddr_storage m_address; + socklen_t m_length{0}; public: - /** - * Construct a null address. - */ - inline Generic() noexcept - { - std::memset(&m_address, 0, sizeof (sockaddr_storage)); - } - - /** - * Construct an address. - * - * \pre address is not null - * \pre length <= sizeof (sockaddr_storage) - * \param address the address to copy - * \param length the address length - */ - inline Generic(const sockaddr *address, socklen_t length) noexcept - : m_length(length) - { - assert(address); - assert(length <= sizeof (sockaddr_storage)); - - std::memset(&m_address, 0, sizeof (sockaddr_storage)); - std::memcpy(&m_address, address, length); - } - - /** - * Get the address family. - * - * \return the address family - */ - inline int domain() const noexcept - { - return m_address.ss_family; - } - - /** - * Get the underlying address. - * - * \return the address - */ - inline sockaddr *address() noexcept - { - return reinterpret_cast<sockaddr *>(&m_address); - } - - /** - * Overloaded function. - * - * \return the address - */ - inline const sockaddr *address() const noexcept - { - return reinterpret_cast<const sockaddr *>(&m_address); - } - - /** - * Get the underlying address length. - * - * \return the length - */ - inline socklen_t length() const noexcept - { - return m_length; - } + /** + * Construct a null address. + */ + inline Generic() noexcept + { + std::memset(&m_address, 0, sizeof (sockaddr_storage)); + } + + /** + * Construct an address. + * + * \pre address is not null + * \pre length <= sizeof (sockaddr_storage) + * \param address the address to copy + * \param length the address length + */ + inline Generic(const sockaddr *address, socklen_t length) noexcept + : m_length(length) + { + assert(address); + assert(length <= sizeof (sockaddr_storage)); + + std::memset(&m_address, 0, sizeof (sockaddr_storage)); + std::memcpy(&m_address, address, length); + } + + /** + * Get the address family. + * + * \return the address family + */ + inline int domain() const noexcept + { + return m_address.ss_family; + } + + /** + * Get the underlying address. + * + * \return the address + */ + inline sockaddr *address() noexcept + { + return reinterpret_cast<sockaddr *>(&m_address); + } + + /** + * Overloaded function. + * + * \return the address + */ + inline const sockaddr *address() const noexcept + { + return reinterpret_cast<const sockaddr *>(&m_address); + } + + /** + * Get the underlying address length. + * + * \return the length + */ + inline socklen_t length() const noexcept + { + return m_length; + } }; /** @@ -2092,7 +2092,7 @@ */ inline bool operator==(const Generic &a1, const Generic &a2) noexcept { - return a1.length() == a2.length() && std::memcmp(a1.address(), a2.address(), a1.length()) == 0; + return a1.length() == a2.length() && std::memcmp(a1.address(), a2.address(), a1.length()) == 0; } /** @@ -2104,7 +2104,7 @@ */ inline bool operator!=(const Generic &a1, const Generic &a2) noexcept { - return !(a1 == a2); + return !(a1 == a2); } /** @@ -2116,266 +2116,266 @@ */ class Ip { private: - union { - sockaddr_in6 m_sin6; - sockaddr_in m_sin; - }; - - int m_domain; + union { + sockaddr_in6 m_sin6; + sockaddr_in m_sin; + }; + + int m_domain; public: - /** - * Create IP address, defaults to IPv4. - * - * \pre domain must be AF_INET or AF_INET6 - * \param domain the domain - */ - inline Ip(int domain = AF_INET) noexcept - : m_domain(domain) - { - assert(domain == AF_INET || domain == AF_INET6); - - std::memset(&m_sin, 0, sizeof (sockaddr_in)); - } - - /** - * Create an IP address on the specific ip address. - * - * \pre domain must be AF_INET or AF_INET6 - * \param ip the address or "*" for any - * \param port the port - * \param domain the domain - * \warning If NET_HAVE_INET_PTON is undefined, host can not be other than "*" - * \throw Error on failures or if inet_pton is unavailable - */ - inline Ip(const std::string &ip, std::uint16_t port, int domain) - : Ip(domain) - { - if (m_domain == AF_INET) - make(ip, port, m_sin); - else - make(ip, port, m_sin6); - } - - /** - * Create the IP address from the storage. - * - * \pre the storage domain must be AF_INET or AF_INET6 - * \param ss the the storage - * \param length the storage length - */ - inline Ip(const sockaddr *ss, socklen_t length) noexcept - : Ip(ss->sa_family) - { - assert(ss->sa_family == AF_INET || ss->sa_family == AF_INET6); - - if (ss->sa_family == AF_INET) - std::memcpy(&m_sin, ss, length); - else - std::memcpy(&m_sin6, ss, length); - } - - /** - * Get the domain. - * - * \return AF_INET or AF_INET6 - */ - inline int domain() const noexcept - { - return m_domain; - } - - /** - * Get the underlying address, may be a sockaddr_in or sockaddr_in6. - * - * \return the address - */ - inline const sockaddr *address() const noexcept - { - return m_domain == AF_INET ? reinterpret_cast<const sockaddr *>(&m_sin) : reinterpret_cast<const sockaddr *>(&m_sin6); - } - - /** - * Get the address length. - * - * \return the address length - */ - inline socklen_t length() const noexcept - { - return m_domain == AF_INET ? sizeof (sockaddr_in) : sizeof (sockaddr_in6); - } - - /** - * Retrieve the port. - * - * \return the port - */ - inline std::uint16_t port() const noexcept - { - return m_domain == AF_INET ? ntohs(m_sin.sin_port) : ntohs(m_sin6.sin6_port); - } - - /** - * Get the ip address. - * - * \return the ip address - * \throw Error on errors or if inet_ntop is unavailable - */ - inline std::string ip() const - { - return m_domain == AF_INET ? ip(m_sin) : ip(m_sin6); - } - - /** - * Prepare the sockaddr_in structure with the given ip. - * - * \param ip the ip address - * \param port the port - * \param sin the Ipv4 address - * \throw Error if inet_pton is unavailable - */ - static void make(const std::string &ip, std::uint16_t port, sockaddr_in &sin) - { + /** + * Create IP address, defaults to IPv4. + * + * \pre domain must be AF_INET or AF_INET6 + * \param domain the domain + */ + inline Ip(int domain = AF_INET) noexcept + : m_domain(domain) + { + assert(domain == AF_INET || domain == AF_INET6); + + std::memset(&m_sin, 0, sizeof (sockaddr_in)); + } + + /** + * Create an IP address on the specific ip address. + * + * \pre domain must be AF_INET or AF_INET6 + * \param ip the address or "*" for any + * \param port the port + * \param domain the domain + * \warning If NET_HAVE_INET_PTON is undefined, host can not be other than "*" + * \throw Error on failures or if inet_pton is unavailable + */ + inline Ip(const std::string &ip, std::uint16_t port, int domain) + : Ip(domain) + { + if (m_domain == AF_INET) + make(ip, port, m_sin); + else + make(ip, port, m_sin6); + } + + /** + * Create the IP address from the storage. + * + * \pre the storage domain must be AF_INET or AF_INET6 + * \param ss the the storage + * \param length the storage length + */ + inline Ip(const sockaddr *ss, socklen_t length) noexcept + : Ip(ss->sa_family) + { + assert(ss->sa_family == AF_INET || ss->sa_family == AF_INET6); + + if (ss->sa_family == AF_INET) + std::memcpy(&m_sin, ss, length); + else + std::memcpy(&m_sin6, ss, length); + } + + /** + * Get the domain. + * + * \return AF_INET or AF_INET6 + */ + inline int domain() const noexcept + { + return m_domain; + } + + /** + * Get the underlying address, may be a sockaddr_in or sockaddr_in6. + * + * \return the address + */ + inline const sockaddr *address() const noexcept + { + return m_domain == AF_INET ? reinterpret_cast<const sockaddr *>(&m_sin) : reinterpret_cast<const sockaddr *>(&m_sin6); + } + + /** + * Get the address length. + * + * \return the address length + */ + inline socklen_t length() const noexcept + { + return m_domain == AF_INET ? sizeof (sockaddr_in) : sizeof (sockaddr_in6); + } + + /** + * Retrieve the port. + * + * \return the port + */ + inline std::uint16_t port() const noexcept + { + return m_domain == AF_INET ? ntohs(m_sin.sin_port) : ntohs(m_sin6.sin6_port); + } + + /** + * Get the ip address. + * + * \return the ip address + * \throw Error on errors or if inet_ntop is unavailable + */ + inline std::string ip() const + { + return m_domain == AF_INET ? ip(m_sin) : ip(m_sin6); + } + + /** + * Prepare the sockaddr_in structure with the given ip. + * + * \param ip the ip address + * \param port the port + * \param sin the Ipv4 address + * \throw Error if inet_pton is unavailable + */ + static void make(const std::string &ip, std::uint16_t port, sockaddr_in &sin) + { #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - - if (ip == "*") - sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + + if (ip == "*") + sin.sin_addr.s_addr = INADDR_ANY; #if defined(NET_HAVE_INET_PTON) - else if (inet_pton(AF_INET, ip.c_str(), &sin.sin_addr) <= 0) - throw Error(); + else if (inet_pton(AF_INET, ip.c_str(), &sin.sin_addr) <= 0) + throw Error(); #else - else - throw Error(std::strerror(ENOSYS)); + else + throw Error(std::strerror(ENOSYS)); #endif - } - - /** - * Prepare the sockaddr_in structure with the given ip. - * - * \param ip the ip address - * \param port the port - * \param sin6 the Ipv6 address - * \throw Error if inet_pton is unavailable - */ - static void make(const std::string &ip, std::uint16_t port, sockaddr_in6 &sin6) - { + } + + /** + * Prepare the sockaddr_in structure with the given ip. + * + * \param ip the ip address + * \param port the port + * \param sin6 the Ipv6 address + * \throw Error if inet_pton is unavailable + */ + static void make(const std::string &ip, std::uint16_t port, sockaddr_in6 &sin6) + { #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif - sin6.sin6_family = AF_INET6; - sin6.sin6_port = htons(port); - - if (ip == "*") - sin6.sin6_addr = in6addr_any; + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(port); + + if (ip == "*") + sin6.sin6_addr = in6addr_any; #if defined(NET_HAVE_INET_PTON) - else if (inet_pton(AF_INET6, ip.c_str(), &sin6.sin6_addr) <= 0) - throw Error(); + else if (inet_pton(AF_INET6, ip.c_str(), &sin6.sin6_addr) <= 0) + throw Error(); #else - else - throw Error(std::strerror(ENOSYS)); + else + throw Error(std::strerror(ENOSYS)); #endif - } - - /** - * Get the underlying ip from the given address. - * - * \param sin the Ipv4 address - * \return the ip address - * \throw Error if inet_ntop is unavailable - */ - static std::string ip(const sockaddr_in &sin) - { + } + + /** + * Get the underlying ip from the given address. + * + * \param sin the Ipv4 address + * \return the ip address + * \throw Error if inet_ntop is unavailable + */ + static std::string ip(const sockaddr_in &sin) + { #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif #if !defined(NET_HAVE_INET_NTOP) - (void)sin; - - throw Error(ENOSYS, std::strerror(ENOSYS)); + (void)sin; + + throw Error(ENOSYS, std::strerror(ENOSYS)); #else - char result[INET_ADDRSTRLEN + 1]; - - std::memset(result, 0, sizeof (result)); - - if (!inet_ntop(AF_INET, const_cast<in_addr *>(&sin.sin_addr), result, sizeof (result))) - throw Error(); - - return result; + char result[INET_ADDRSTRLEN + 1]; + + std::memset(result, 0, sizeof (result)); + + if (!inet_ntop(AF_INET, const_cast<in_addr *>(&sin.sin_addr), result, sizeof (result))) + throw Error(); + + return result; #endif - } - - /** - * Get the underlying ip from the given address. - * - * \param sin6 the Ipv6 address - * \return the ip address - * \throw Error if inet_ntop is unavailable - */ - static std::string ip(const sockaddr_in6 &sin6) - { + } + + /** + * Get the underlying ip from the given address. + * + * \param sin6 the Ipv6 address + * \return the ip address + * \throw Error if inet_ntop is unavailable + */ + static std::string ip(const sockaddr_in6 &sin6) + { #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif #if !defined(NET_HAVE_INET_NTOP) - (void)sin6; - - throw Error(ENOSYS, std::strerror(ENOSYS)); + (void)sin6; + + throw Error(ENOSYS, std::strerror(ENOSYS)); #else - char result[INET6_ADDRSTRLEN]; - - std::memset(result, 0, sizeof (result)); - - if (!inet_ntop(AF_INET6, const_cast<in6_addr *>(&sin6.sin6_addr), result, sizeof (result))) - throw Error(); - - return result; + char result[INET6_ADDRSTRLEN]; + + std::memset(result, 0, sizeof (result)); + + if (!inet_ntop(AF_INET6, const_cast<in6_addr *>(&sin6.sin6_addr), result, sizeof (result))) + throw Error(); + + return result; #endif - } - - /** - * Resolve an hostname. - * - * This function wraps getaddrinfo and returns the first result. - * - * \param host the hostname - * \param service the service name (port or name) - * \param domain the domain (e.g. AF_INET) - * \param type the socket type (e.g. SOCK_STREAM) - * \return the resolved address - * \throw Error on failures - */ - static Ip resolve(const std::string &host, const std::string &service, int domain = AF_INET, int type = SOCK_STREAM) - { - assert(domain == AF_INET || domain == AF_INET6); + } + + /** + * Resolve an hostname. + * + * This function wraps getaddrinfo and returns the first result. + * + * \param host the hostname + * \param service the service name (port or name) + * \param domain the domain (e.g. AF_INET) + * \param type the socket type (e.g. SOCK_STREAM) + * \return the resolved address + * \throw Error on failures + */ + static Ip resolve(const std::string &host, const std::string &service, int domain = AF_INET, int type = SOCK_STREAM) + { + assert(domain == AF_INET || domain == AF_INET6); #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif - struct addrinfo hints, *res; - - std::memset(&hints, 0, sizeof (struct addrinfo)); - hints.ai_family = domain; - hints.ai_socktype = type; - - int e = getaddrinfo(host.c_str(), service.c_str(), &hints, &res); - - if (e != 0) - throw Error(gai_strerror(e)); - - Ip ip(res->ai_addr, res->ai_addrlen); - - freeaddrinfo(res); - - return ip; - } + struct addrinfo hints, *res; + + std::memset(&hints, 0, sizeof (struct addrinfo)); + hints.ai_family = domain; + hints.ai_socktype = type; + + int e = getaddrinfo(host.c_str(), service.c_str(), &hints, &res); + + if (e != 0) + throw Error(gai_strerror(e)); + + Ip ip(res->ai_addr, res->ai_addrlen); + + freeaddrinfo(res); + + return ip; + } }; /** @@ -2384,111 +2384,111 @@ */ class Ipv4 { private: - sockaddr_in m_sin; + sockaddr_in m_sin; public: - /** - * Create an Ipv4 address. - */ - inline Ipv4() noexcept - { - std::memset(&m_sin, 0, sizeof (sockaddr_in)); - } - - /** - * Create an Ipv4 address on the specific ip address. - * - * \param ip the address or "*" for any - * \param port the port - * \warning If NET_HAVE_INET_PTON is undefined, host can not be other than "*" - * \throw Error on failures or if inet_pton is unavailable - */ - inline Ipv4(const std::string &ip, std::uint16_t port) - : Ipv4() - { - Ip::make(ip, port, m_sin); - } - - /** - * Create the IP address from the storage. - * - * \pre the storage domain must be AF_INET - * \param ss the the storage - * \param length the storage length - */ - inline Ipv4(const sockaddr *ss, socklen_t length) noexcept - { - assert(ss->sa_family == AF_INET); - - std::memcpy(&m_sin, ss, length); - } - - /** - * Get the domain. - * - * \return AF_INET - */ - inline int domain() const noexcept - { - return AF_INET; - } - - /** - * Get the underlying address. - * - * \return the address - */ - inline const sockaddr *address() const noexcept - { - return reinterpret_cast<const sockaddr *>(&m_sin); - } - - /** - * Get the address length. - * - * \return the size of sockaddr_in - */ - inline socklen_t length() const noexcept - { - return sizeof (sockaddr_in); - } - - /** - * Get the port. - * - * \return the port - */ - inline std::uint16_t port() const noexcept - { - return ntohs(m_sin.sin_port); - } - - /** - * Get the ip address. - * - * \return the ip address - * \throw Error on errors or if inet_ntop is unavailable - */ - inline std::string ip() const - { - return Ip::ip(m_sin); - } - - /** - * Same as Ip::resolve with AF_INET as domain. - * - * \param host the hostname - * \param service the service name (port or name) - * \param type the socket type (e.g. SOCK_STREAM) - * \return the resolved address - * \throw Error on failures - */ - static Ipv4 resolve(const std::string &host, const std::string &service, int type = SOCK_STREAM) - { - Ip result = Ip::resolve(host, service, AF_INET, type); - - return Ipv4(result.address(), result.length()); - } + /** + * Create an Ipv4 address. + */ + inline Ipv4() noexcept + { + std::memset(&m_sin, 0, sizeof (sockaddr_in)); + } + + /** + * Create an Ipv4 address on the specific ip address. + * + * \param ip the address or "*" for any + * \param port the port + * \warning If NET_HAVE_INET_PTON is undefined, host can not be other than "*" + * \throw Error on failures or if inet_pton is unavailable + */ + inline Ipv4(const std::string &ip, std::uint16_t port) + : Ipv4() + { + Ip::make(ip, port, m_sin); + } + + /** + * Create the IP address from the storage. + * + * \pre the storage domain must be AF_INET + * \param ss the the storage + * \param length the storage length + */ + inline Ipv4(const sockaddr *ss, socklen_t length) noexcept + { + assert(ss->sa_family == AF_INET); + + std::memcpy(&m_sin, ss, length); + } + + /** + * Get the domain. + * + * \return AF_INET + */ + inline int domain() const noexcept + { + return AF_INET; + } + + /** + * Get the underlying address. + * + * \return the address + */ + inline const sockaddr *address() const noexcept + { + return reinterpret_cast<const sockaddr *>(&m_sin); + } + + /** + * Get the address length. + * + * \return the size of sockaddr_in + */ + inline socklen_t length() const noexcept + { + return sizeof (sockaddr_in); + } + + /** + * Get the port. + * + * \return the port + */ + inline std::uint16_t port() const noexcept + { + return ntohs(m_sin.sin_port); + } + + /** + * Get the ip address. + * + * \return the ip address + * \throw Error on errors or if inet_ntop is unavailable + */ + inline std::string ip() const + { + return Ip::ip(m_sin); + } + + /** + * Same as Ip::resolve with AF_INET as domain. + * + * \param host the hostname + * \param service the service name (port or name) + * \param type the socket type (e.g. SOCK_STREAM) + * \return the resolved address + * \throw Error on failures + */ + static Ipv4 resolve(const std::string &host, const std::string &service, int type = SOCK_STREAM) + { + Ip result = Ip::resolve(host, service, AF_INET, type); + + return Ipv4(result.address(), result.length()); + } }; /** @@ -2497,111 +2497,111 @@ */ class Ipv6 { private: - sockaddr_in6 m_sin6; + sockaddr_in6 m_sin6; public: - /** - * Create an Ipv6 address. - */ - inline Ipv6() noexcept - { - std::memset(&m_sin6, 0, sizeof (sockaddr_in6)); - } - - /** - * Create an Ipv6 address on the specific ip address. - * - * \param ip the address or "*" for any - * \param port the port - * \warning If NET_HAVE_INET_PTON is undefined, host can not be other than "*" - * \throw Error on failures or if inet_pton is unavailable - */ - inline Ipv6(const std::string &ip, std::uint16_t port) - : Ipv6() - { - Ip::make(ip, port, m_sin6); - } - - /** - * Create the IP address from the storage. - * - * \pre the storage domain must be AF_INET6 - * \param ss the the storage - * \param length the storage length - */ - inline Ipv6(const sockaddr *ss, socklen_t length) noexcept - { - assert(ss->sa_family == AF_INET6); - - std::memcpy(&m_sin6, ss, length); - } - - /** - * Get the domain. - * - * \return AF_INET6 - */ - inline int domain() const noexcept - { - return AF_INET6; - } - - /** - * Get the underlying address. - * - * \return the address - */ - inline const sockaddr *address() const noexcept - { - return reinterpret_cast<const sockaddr *>(&m_sin6); - } - - /** - * Get the address length. - * - * \return the size of sockaddr_in - */ - inline socklen_t length() const noexcept - { - return sizeof (sockaddr_in6); - } - - /** - * Get the port. - * - * \return the port - */ - inline std::uint16_t port() const noexcept - { - return ntohs(m_sin6.sin6_port); - } - - /** - * Get the ip address. - * - * \return the ip address - * \throw Error on errors or if inet_ntop is unavailable - */ - inline std::string ip() const - { - return Ip::ip(m_sin6); - } - - /** - * Same as Ip::resolve with AF_INET6 as domain. - * - * \param host the hostname - * \param service the service name (port or name) - * \param type the socket type (e.g. SOCK_STREAM) - * \return the resolved address - * \throw Error on failures - */ - static Ipv6 resolve(const std::string &host, const std::string &service, int type = SOCK_STREAM) - { - Ip result = Ip::resolve(host, service, AF_INET6, type); - - return Ipv6(result.address(), result.length()); - } + /** + * Create an Ipv6 address. + */ + inline Ipv6() noexcept + { + std::memset(&m_sin6, 0, sizeof (sockaddr_in6)); + } + + /** + * Create an Ipv6 address on the specific ip address. + * + * \param ip the address or "*" for any + * \param port the port + * \warning If NET_HAVE_INET_PTON is undefined, host can not be other than "*" + * \throw Error on failures or if inet_pton is unavailable + */ + inline Ipv6(const std::string &ip, std::uint16_t port) + : Ipv6() + { + Ip::make(ip, port, m_sin6); + } + + /** + * Create the IP address from the storage. + * + * \pre the storage domain must be AF_INET6 + * \param ss the the storage + * \param length the storage length + */ + inline Ipv6(const sockaddr *ss, socklen_t length) noexcept + { + assert(ss->sa_family == AF_INET6); + + std::memcpy(&m_sin6, ss, length); + } + + /** + * Get the domain. + * + * \return AF_INET6 + */ + inline int domain() const noexcept + { + return AF_INET6; + } + + /** + * Get the underlying address. + * + * \return the address + */ + inline const sockaddr *address() const noexcept + { + return reinterpret_cast<const sockaddr *>(&m_sin6); + } + + /** + * Get the address length. + * + * \return the size of sockaddr_in + */ + inline socklen_t length() const noexcept + { + return sizeof (sockaddr_in6); + } + + /** + * Get the port. + * + * \return the port + */ + inline std::uint16_t port() const noexcept + { + return ntohs(m_sin6.sin6_port); + } + + /** + * Get the ip address. + * + * \return the ip address + * \throw Error on errors or if inet_ntop is unavailable + */ + inline std::string ip() const + { + return Ip::ip(m_sin6); + } + + /** + * Same as Ip::resolve with AF_INET6 as domain. + * + * \param host the hostname + * \param service the service name (port or name) + * \param type the socket type (e.g. SOCK_STREAM) + * \return the resolved address + * \throw Error on failures + */ + static Ipv6 resolve(const std::string &host, const std::string &service, int type = SOCK_STREAM) + { + Ip result = Ip::resolve(host, service, AF_INET6, type); + + return Ipv6(result.address(), result.length()); + } }; #if !defined(_WIN32) @@ -2614,87 +2614,87 @@ */ class Local { private: - sockaddr_un m_sun; - std::string m_path; + sockaddr_un m_sun; + std::string m_path; public: - /** - * Get the domain AF_LOCAL. - * - * \return AF_LOCAL - */ - inline int domain() const noexcept - { - return AF_LOCAL; - } - - /** - * Default constructor. - */ - inline Local() noexcept - { - std::memset(&m_sun, 0, sizeof (sockaddr_un)); - } - - /** - * Construct an address to a path. - * - * \param path the path - * \param rm remove the file before (default: false) - */ - Local(std::string path, bool rm = false) noexcept - : m_path(std::move(path)) - { - // Silently remove the file even if it fails. - if (rm) - ::remove(m_path.c_str()); - - // Copy the path. - std::memset(m_sun.sun_path, 0, sizeof (m_sun.sun_path)); - std::strncpy(m_sun.sun_path, m_path.c_str(), sizeof (m_sun.sun_path) - 1); - - // Set the parameters. - m_sun.sun_family = AF_LOCAL; - } - - /** - * Construct an unix address from a storage address. - * - * \pre storage's domain must be AF_LOCAL - * \param ss the storage - * \param length the length - */ - Local(const sockaddr *ss, socklen_t length) noexcept - { - assert(ss->sa_family == AF_LOCAL); - - std::memcpy(&m_sun, ss, length); - m_path = reinterpret_cast<const sockaddr_un &>(m_sun).sun_path; - } - - /** - * Get the sockaddr_un. - * - * \return the address - */ - inline const sockaddr *address() const noexcept - { - return reinterpret_cast<const sockaddr *>(&m_sun); - } - - /** - * Get the address length. - * - * \return the length - */ - inline socklen_t length() const noexcept - { + /** + * Get the domain AF_LOCAL. + * + * \return AF_LOCAL + */ + inline int domain() const noexcept + { + return AF_LOCAL; + } + + /** + * Default constructor. + */ + inline Local() noexcept + { + std::memset(&m_sun, 0, sizeof (sockaddr_un)); + } + + /** + * Construct an address to a path. + * + * \param path the path + * \param rm remove the file before (default: false) + */ + Local(std::string path, bool rm = false) noexcept + : m_path(std::move(path)) + { + // Silently remove the file even if it fails. + if (rm) + ::remove(m_path.c_str()); + + // Copy the path. + std::memset(m_sun.sun_path, 0, sizeof (m_sun.sun_path)); + std::strncpy(m_sun.sun_path, m_path.c_str(), sizeof (m_sun.sun_path) - 1); + + // Set the parameters. + m_sun.sun_family = AF_LOCAL; + } + + /** + * Construct an unix address from a storage address. + * + * \pre storage's domain must be AF_LOCAL + * \param ss the storage + * \param length the length + */ + Local(const sockaddr *ss, socklen_t length) noexcept + { + assert(ss->sa_family == AF_LOCAL); + + std::memcpy(&m_sun, ss, length); + m_path = reinterpret_cast<const sockaddr_un &>(m_sun).sun_path; + } + + /** + * Get the sockaddr_un. + * + * \return the address + */ + inline const sockaddr *address() const noexcept + { + return reinterpret_cast<const sockaddr *>(&m_sun); + } + + /** + * Get the address length. + * + * \return the length + */ + inline socklen_t length() const noexcept + { #if defined(NET_HAVE_SUN_LEN) - return SUN_LEN(&m_sun); + return SUN_LEN(&m_sun); #else - return sizeof (m_sun); + return sizeof (m_sun); #endif - } + } }; #endif // !_WIN32 @@ -2723,119 +2723,119 @@ */ class Iterator : public std::iterator<std::forward_iterator_tag, Generic> { private: - std::vector<Generic> m_addresses; - std::size_t m_index{0}; + std::vector<Generic> m_addresses; + std::size_t m_index{0}; public: - /** - * Construct a null iterator. - * - * The default constructed iterator is not dereferenceable. - */ - inline Iterator() noexcept = default; - - /** - * Construct an address iterator with a set of addresses. - * - * \pre index < m_addresses.size() - * \param addresses the addresses - * \param index the first index - */ - inline Iterator(std::vector<Generic> addresses, std::size_t index = 0) noexcept - : m_addresses(std::move(addresses)) - , m_index(index) - { - assert(index < m_addresses.size()); - } - - /** - * Get the generic address. - * - * \pre this is dereferenceable - * \return the generic address - */ - inline const Generic &operator*() const noexcept - { - assert(m_index <= m_addresses.size()); - - return m_addresses[m_index]; - } - - /** - * Overloaded function. - * - * \pre this is dereferenceable - * \return the generic address - */ - inline Generic &operator*() noexcept - { - assert(m_index <= m_addresses.size()); - - return m_addresses[m_index]; - } - - /** - * Get the generic address. - * - * \pre this is dereferenceable - * \return the generic address - */ - inline const Generic *operator->() const noexcept - { - assert(m_index <= m_addresses.size()); - - return &m_addresses[m_index]; - } - - /** - * Overloaded function. - * - * \pre this is dereferenceable - * \return the generic address - */ - inline Generic *operator->() noexcept - { - assert(m_index <= m_addresses.size()); - - return &m_addresses[m_index]; - } - - /** - * Pre-increment the iterator. - * - * \return this - */ - inline Iterator &operator++(int) noexcept - { - if (m_index + 1 >= m_addresses.size()) { - m_addresses.clear(); - m_index = 0; - } else - m_index ++; - - return *this; - } - - /** - * Post-increment the iterator. - * - * \return copy of this - */ - inline Iterator operator++() noexcept - { - Iterator save = *this; - - if (m_index + 1 >= m_addresses.size()) { - m_addresses.clear(); - m_index = 0; - } else - m_index ++; - - return save; - } - - friend bool operator==(const Iterator &, const Iterator &) noexcept; - friend bool operator!=(const Iterator &, const Iterator &) noexcept; + /** + * Construct a null iterator. + * + * The default constructed iterator is not dereferenceable. + */ + inline Iterator() noexcept = default; + + /** + * Construct an address iterator with a set of addresses. + * + * \pre index < m_addresses.size() + * \param addresses the addresses + * \param index the first index + */ + inline Iterator(std::vector<Generic> addresses, std::size_t index = 0) noexcept + : m_addresses(std::move(addresses)) + , m_index(index) + { + assert(index < m_addresses.size()); + } + + /** + * Get the generic address. + * + * \pre this is dereferenceable + * \return the generic address + */ + inline const Generic &operator*() const noexcept + { + assert(m_index <= m_addresses.size()); + + return m_addresses[m_index]; + } + + /** + * Overloaded function. + * + * \pre this is dereferenceable + * \return the generic address + */ + inline Generic &operator*() noexcept + { + assert(m_index <= m_addresses.size()); + + return m_addresses[m_index]; + } + + /** + * Get the generic address. + * + * \pre this is dereferenceable + * \return the generic address + */ + inline const Generic *operator->() const noexcept + { + assert(m_index <= m_addresses.size()); + + return &m_addresses[m_index]; + } + + /** + * Overloaded function. + * + * \pre this is dereferenceable + * \return the generic address + */ + inline Generic *operator->() noexcept + { + assert(m_index <= m_addresses.size()); + + return &m_addresses[m_index]; + } + + /** + * Pre-increment the iterator. + * + * \return this + */ + inline Iterator &operator++(int) noexcept + { + if (m_index + 1 >= m_addresses.size()) { + m_addresses.clear(); + m_index = 0; + } else + m_index ++; + + return *this; + } + + /** + * Post-increment the iterator. + * + * \return copy of this + */ + inline Iterator operator++() noexcept + { + Iterator save = *this; + + if (m_index + 1 >= m_addresses.size()) { + m_addresses.clear(); + m_index = 0; + } else + m_index ++; + + return save; + } + + friend bool operator==(const Iterator &, const Iterator &) noexcept; + friend bool operator!=(const Iterator &, const Iterator &) noexcept; }; /** @@ -2847,7 +2847,7 @@ */ inline bool operator==(const Iterator &i1, const Iterator &i2) noexcept { - return i1.m_addresses == i2.m_addresses && i1.m_index == i2.m_index; + return i1.m_addresses == i2.m_addresses && i1.m_index == i2.m_index; } /** @@ -2859,7 +2859,7 @@ */ inline bool operator!=(const Iterator &i1, const Iterator &i2) noexcept { - return !(i1 == i2); + return !(i1 == i2); } } // !address @@ -2876,74 +2876,74 @@ */ class SockBlockMode { private: - bool m_value; + bool m_value; public: - /** - * Create the option. - * - * By default the blocking mode is set to true. - * - * \param value set to true to make blocking sockets - */ - inline SockBlockMode(bool value = true) noexcept - : m_value(value) - { - } - - /** - * Set the option. - * - * \param sc the socket - * \throw Error on errors - */ - template <typename Address> - void set(Socket<Address> &sc) const - { + /** + * Create the option. + * + * By default the blocking mode is set to true. + * + * \param value set to true to make blocking sockets + */ + inline SockBlockMode(bool value = true) noexcept + : m_value(value) + { + } + + /** + * Set the option. + * + * \param sc the socket + * \throw Error on errors + */ + template <typename Address> + void set(Socket<Address> &sc) const + { #if defined(O_NONBLOCK) && !defined(_WIN32) - int flags; - - if ((flags = fcntl(sc.handle(), F_GETFL, 0)) < 0) - flags = 0; - - if (m_value) - flags &= ~(O_NONBLOCK); - else - flags |= O_NONBLOCK; - - if (fcntl(sc.handle(), F_SETFL, flags) < 0) - throw Error(); + int flags; + + if ((flags = fcntl(sc.handle(), F_GETFL, 0)) < 0) + flags = 0; + + if (m_value) + flags &= ~(O_NONBLOCK); + else + flags |= O_NONBLOCK; + + if (fcntl(sc.handle(), F_SETFL, flags) < 0) + throw Error(); #else - unsigned long flags = (m_value) ? 0 : 1; - - if (ioctlsocket(sc.handle(), FIONBIO, &flags) == Failure) - throw Error(); + unsigned long flags = (m_value) ? 0 : 1; + + if (ioctlsocket(sc.handle(), FIONBIO, &flags) == Failure) + throw Error(); #endif - } - - /** - * Get the option. - * - * \param sc the socket - * \return the value - * \throw Error on errors - */ - template <typename Address> - bool get(Socket<Address> &sc) const - { + } + + /** + * Get the option. + * + * \param sc the socket + * \return the value + * \throw Error on errors + */ + template <typename Address> + bool get(Socket<Address> &sc) const + { #if defined(O_NONBLOCK) && !defined(_WIN32) - int flags = fcntl(sc.handle(), F_GETFL, 0); - - if (flags < 0) - throw Error(); - - return !(flags & O_NONBLOCK); + int flags = fcntl(sc.handle(), F_GETFL, 0); + + if (flags < 0) + throw Error(); + + return !(flags & O_NONBLOCK); #else - (void)sc; - - throw Error(std::strerror(ENOSYS)); + (void)sc; + + throw Error(std::strerror(ENOSYS)); #endif - } + } }; /** @@ -2952,43 +2952,43 @@ */ class SockReceiveBuffer { private: - int m_value; + int m_value; public: - /** - * Create the option. - * - * \param size the buffer size - */ - inline SockReceiveBuffer(int size = 2048) noexcept - : m_value(size) - { - } - - /** - * Set the option. - * - * \param sc the socket - * \throw Error on errors - */ - template <typename Address> - inline void set(Socket<Address> &sc) const - { - sc.set(SOL_SOCKET, SO_RCVBUF, m_value); - } - - /** - * Get the option. - * - * \param sc the socket - * \return the value - * \throw Error on errors - */ - template <typename Address> - inline int get(Socket<Address> &sc) const - { - return sc.template get<int>(SOL_SOCKET, SO_RCVBUF); - } + /** + * Create the option. + * + * \param size the buffer size + */ + inline SockReceiveBuffer(int size = 2048) noexcept + : m_value(size) + { + } + + /** + * Set the option. + * + * \param sc the socket + * \throw Error on errors + */ + template <typename Address> + inline void set(Socket<Address> &sc) const + { + sc.set(SOL_SOCKET, SO_RCVBUF, m_value); + } + + /** + * Get the option. + * + * \param sc the socket + * \return the value + * \throw Error on errors + */ + template <typename Address> + inline int get(Socket<Address> &sc) const + { + return sc.template get<int>(SOL_SOCKET, SO_RCVBUF); + } }; /** @@ -2997,45 +2997,45 @@ */ class SockReuseAddress { private: - bool m_value; + bool m_value; public: - /** - * Create the option. - * - * By default the option reuses the address. - * - * \param value set to true to reuse the address - */ - inline SockReuseAddress(bool value = true) noexcept - : m_value(value) - { - } - - /** - * Set the option. - * - * \param sc the socket - * \throw Error on errors - */ - template <typename Address> - inline void set(Socket<Address> &sc) const - { - sc.set(SOL_SOCKET, SO_REUSEADDR, m_value ? 1 : 0); - } - - /** - * Get the option. - * - * \param sc the socket - * \return the value - * \throw Error on errors - */ - template <typename Address> - inline bool get(Socket<Address> &sc) const - { - return sc.template get<int>(SOL_SOCKET, SO_REUSEADDR) != 0; - } + /** + * Create the option. + * + * By default the option reuses the address. + * + * \param value set to true to reuse the address + */ + inline SockReuseAddress(bool value = true) noexcept + : m_value(value) + { + } + + /** + * Set the option. + * + * \param sc the socket + * \throw Error on errors + */ + template <typename Address> + inline void set(Socket<Address> &sc) const + { + sc.set(SOL_SOCKET, SO_REUSEADDR, m_value ? 1 : 0); + } + + /** + * Get the option. + * + * \param sc the socket + * \return the value + * \throw Error on errors + */ + template <typename Address> + inline bool get(Socket<Address> &sc) const + { + return sc.template get<int>(SOL_SOCKET, SO_REUSEADDR) != 0; + } }; /** @@ -3044,43 +3044,43 @@ */ class SockSendBuffer { private: - int m_value; + int m_value; public: - /** - * Create the option. - * - * \param size the buffer size - */ - inline SockSendBuffer(int size = 2048) noexcept - : m_value(size) - { - } - - /** - * Set the option. - * - * \param sc the socket - * \throw Error on errors - */ - template <typename Address> - inline void set(Socket<Address> &sc) const - { - sc.set(SOL_SOCKET, SO_SNDBUF, m_value); - } - - /** - * Get the option. - * - * \param sc the socket - * \return the value - * \throw Error on errors - */ - template <typename Address> - inline int get(Socket<Address> &sc) const - { - return sc.template get<int>(SOL_SOCKET, SO_SNDBUF); - } + /** + * Create the option. + * + * \param size the buffer size + */ + inline SockSendBuffer(int size = 2048) noexcept + : m_value(size) + { + } + + /** + * Set the option. + * + * \param sc the socket + * \throw Error on errors + */ + template <typename Address> + inline void set(Socket<Address> &sc) const + { + sc.set(SOL_SOCKET, SO_SNDBUF, m_value); + } + + /** + * Get the option. + * + * \param sc the socket + * \return the value + * \throw Error on errors + */ + template <typename Address> + inline int get(Socket<Address> &sc) const + { + return sc.template get<int>(SOL_SOCKET, SO_SNDBUF); + } }; /** @@ -3089,45 +3089,45 @@ */ class TcpNoDelay { private: - bool m_value; + bool m_value; public: - /** - * Create the option. - * - * By default disable TCP delay. - * - * \param value set to true to disable TCP delay - */ - inline TcpNoDelay(bool value = true) noexcept - : m_value(value) - { - } - - /** - * Set the option. - * - * \param sc the socket - * \throw Error on errors - */ - template <typename Address> - inline void set(Socket<Address> &sc) const - { - sc.set(IPPROTO_TCP, TCP_NODELAY, m_value ? 1 : 0); - } - - /** - * Get the option. - * - * \param sc the socket - * \return the value - * \throw Error on errors - */ - template <typename Address> - inline bool get(Socket<Address> &sc) const - { - return sc.template get<int>(IPPROTO_TCP, TCP_NODELAY) != 0; - } + /** + * Create the option. + * + * By default disable TCP delay. + * + * \param value set to true to disable TCP delay + */ + inline TcpNoDelay(bool value = true) noexcept + : m_value(value) + { + } + + /** + * Set the option. + * + * \param sc the socket + * \throw Error on errors + */ + template <typename Address> + inline void set(Socket<Address> &sc) const + { + sc.set(IPPROTO_TCP, TCP_NODELAY, m_value ? 1 : 0); + } + + /** + * Get the option. + * + * \param sc the socket + * \return the value + * \throw Error on errors + */ + template <typename Address> + inline bool get(Socket<Address> &sc) const + { + return sc.template get<int>(IPPROTO_TCP, TCP_NODELAY) != 0; + } }; /** @@ -3139,45 +3139,45 @@ */ class Ipv6Only { private: - bool m_value; + bool m_value; public: - /** - * Create the option. - * - * By default with want IPv6 only. - * - * \param value set to true to use IPv6 only - */ - inline Ipv6Only(bool value = true) noexcept - : m_value(value) - { - } - - /** - * Set the option. - * - * \param sc the socket - * \throw Error on errors - */ - template <typename Address> - inline void set(Socket<Address> &sc) const - { - sc.set(IPPROTO_IPV6, IPV6_V6ONLY, m_value ? 1 : 0); - } - - /** - * Get the option. - * - * \param sc the socket - * \return the value - * \throw Error on errors - */ - template <typename Address> - inline bool get(Socket<Address> &sc) const - { - return sc.template get<int>(IPPROTO_IPV6, IPV6_V6ONLY) != 0; - } + /** + * Create the option. + * + * By default with want IPv6 only. + * + * \param value set to true to use IPv6 only + */ + inline Ipv6Only(bool value = true) noexcept + : m_value(value) + { + } + + /** + * Set the option. + * + * \param sc the socket + * \throw Error on errors + */ + template <typename Address> + inline void set(Socket<Address> &sc) const + { + sc.set(IPPROTO_IPV6, IPV6_V6ONLY, m_value ? 1 : 0); + } + + /** + * Get the option. + * + * \param sc the socket + * \return the value + * \throw Error on errors + */ + template <typename Address> + inline bool get(Socket<Address> &sc) const + { + return sc.template get<int>(IPPROTO_IPV6, IPV6_V6ONLY) != 0; + } }; } // !option @@ -3190,8 +3190,8 @@ */ class ListenerStatus { public: - Handle socket; //!< which socket is ready - Condition flags; //!< the flags + Handle socket; //!< which socket is ready + Condition flags; //!< the flags }; /** @@ -3213,171 +3213,171 @@ */ class Epoll { private: - int m_handle{-1}; - std::vector<epoll_event> m_events; - - Epoll(const Epoll &) = delete; - Epoll &operator=(const Epoll &) = delete; - - std::uint32_t toEpoll(Condition condition) const noexcept - { - std::uint32_t events = 0; - - if ((condition & Condition::Readable) == Condition::Readable) - events |= EPOLLIN; - if ((condition & Condition::Writable) == Condition::Writable) - events |= EPOLLOUT; - - return events; - } - - Condition toCondition(std::uint32_t events) const noexcept - { - Condition condition = Condition::None; - - if ((events & EPOLLIN) || (events & EPOLLHUP)) - condition |= Condition::Readable; - if (events & EPOLLOUT) - condition |= Condition::Writable; - - return condition; - } - - void update(Handle h, int op, int eflags) - { - epoll_event ev; - - std::memset(&ev, 0, sizeof (epoll_event)); - - ev.events = eflags; - ev.data.fd = h; - - if (epoll_ctl(m_handle, op, h, &ev) < 0) - throw Error(); - } + int m_handle{-1}; + std::vector<epoll_event> m_events; + + Epoll(const Epoll &) = delete; + Epoll &operator=(const Epoll &) = delete; + + std::uint32_t toEpoll(Condition condition) const noexcept + { + std::uint32_t events = 0; + + if ((condition & Condition::Readable) == Condition::Readable) + events |= EPOLLIN; + if ((condition & Condition::Writable) == Condition::Writable) + events |= EPOLLOUT; + + return events; + } + + Condition toCondition(std::uint32_t events) const noexcept + { + Condition condition = Condition::None; + + if ((events & EPOLLIN) || (events & EPOLLHUP)) + condition |= Condition::Readable; + if (events & EPOLLOUT) + condition |= Condition::Writable; + + return condition; + } + + void update(Handle h, int op, int eflags) + { + epoll_event ev; + + std::memset(&ev, 0, sizeof (epoll_event)); + + ev.events = eflags; + ev.data.fd = h; + + if (epoll_ctl(m_handle, op, h, &ev) < 0) + throw Error(); + } public: - /** - * Create epoll. - * - * \throw Error on failures - */ - inline Epoll() - : m_handle(epoll_create1(0)) - { - if (m_handle < 0) - throw Error(); - } - - /** - * Move constructor. - * - * \param other the other backend - */ - inline Epoll(Epoll &&other) noexcept - : m_handle(other.m_handle) - { - other.m_handle = -1; - } - - /** - * Close the kqueue descriptor. - */ - inline ~Epoll() - { - if (m_handle != -1) - close(m_handle); - } - - /** - * Get the backend name. - * - * \return kqueue - */ - inline std::string name() const noexcept - { - return "epoll"; - } - - /** - * For set and unset, we need to apply the whole flags required, so if the socket - * was set to Connection::Readable and user *8adds** Connection::Writable, we must - * place both. - * - * \param table the listener table - * \param h the handle - * \param condition the condition - * \param add set to true if the socket is new to the backend - * \throw Error on failures - */ - void set(const ListenerTable &table, Handle h, Condition condition, bool add) - { - if (add) { - update(h, EPOLL_CTL_ADD, toEpoll(condition)); - m_events.resize(m_events.size() + 1); - } else - update(h, EPOLL_CTL_MOD, toEpoll(table.at(h) | condition)); - } - - /** - * Unset is a bit complicated case because Listener tells us which - * flag to remove but to update epoll descriptor we need to pass - * the effective flags that we want to be applied. - * - * So we put the same flags that are currently effective and remove the - * requested one. - * - * \param table the listener table - * \param h the handle - * \param condition the condition - * \param add set to true if the socket is new to the backend - * \throw Error on failures - */ - void unset(const ListenerTable &table, Handle h, Condition condition, bool remove) - { - if (remove) { - update(h, EPOLL_CTL_DEL, 0); - m_events.resize(m_events.size() - 1); - } else - update(h, EPOLL_CTL_MOD, toEpoll(table.at(h) & ~(condition))); - } - - /** - * Wait for sockets to be ready. - * - * \param ms the milliseconds timeout - * \return the sockets ready - * \throw Error on failures - */ - std::vector<ListenerStatus> wait(const ListenerTable &, int ms) - { - int ret = epoll_wait(m_handle, m_events.data(), m_events.size(), ms); - std::vector<ListenerStatus> result; - - if (ret == 0) - throw TimeoutError(); - if (ret < 0) - throw Error(); - - for (int i = 0; i < ret; ++i) - result.push_back(ListenerStatus{m_events[i].data.fd, toCondition(m_events[i].events)}); - - return result; - } - - /** - * Move operator. - * - * \param other the other - * \return this - */ - inline Epoll &operator=(Epoll &&other) - { - m_handle = other.m_handle; - other.m_handle = -1; - - return *this; - } + /** + * Create epoll. + * + * \throw Error on failures + */ + inline Epoll() + : m_handle(epoll_create1(0)) + { + if (m_handle < 0) + throw Error(); + } + + /** + * Move constructor. + * + * \param other the other backend + */ + inline Epoll(Epoll &&other) noexcept + : m_handle(other.m_handle) + { + other.m_handle = -1; + } + + /** + * Close the kqueue descriptor. + */ + inline ~Epoll() + { + if (m_handle != -1) + close(m_handle); + } + + /** + * Get the backend name. + * + * \return kqueue + */ + inline std::string name() const noexcept + { + return "epoll"; + } + + /** + * For set and unset, we need to apply the whole flags required, so if the socket + * was set to Connection::Readable and user *8adds** Connection::Writable, we must + * place both. + * + * \param table the listener table + * \param h the handle + * \param condition the condition + * \param add set to true if the socket is new to the backend + * \throw Error on failures + */ + void set(const ListenerTable &table, Handle h, Condition condition, bool add) + { + if (add) { + update(h, EPOLL_CTL_ADD, toEpoll(condition)); + m_events.resize(m_events.size() + 1); + } else + update(h, EPOLL_CTL_MOD, toEpoll(table.at(h) | condition)); + } + + /** + * Unset is a bit complicated case because Listener tells us which + * flag to remove but to update epoll descriptor we need to pass + * the effective flags that we want to be applied. + * + * So we put the same flags that are currently effective and remove the + * requested one. + * + * \param table the listener table + * \param h the handle + * \param condition the condition + * \param add set to true if the socket is new to the backend + * \throw Error on failures + */ + void unset(const ListenerTable &table, Handle h, Condition condition, bool remove) + { + if (remove) { + update(h, EPOLL_CTL_DEL, 0); + m_events.resize(m_events.size() - 1); + } else + update(h, EPOLL_CTL_MOD, toEpoll(table.at(h) & ~(condition))); + } + + /** + * Wait for sockets to be ready. + * + * \param ms the milliseconds timeout + * \return the sockets ready + * \throw Error on failures + */ + std::vector<ListenerStatus> wait(const ListenerTable &, int ms) + { + int ret = epoll_wait(m_handle, m_events.data(), m_events.size(), ms); + std::vector<ListenerStatus> result; + + if (ret == 0) + throw TimeoutError(); + if (ret < 0) + throw Error(); + + for (int i = 0; i < ret; ++i) + result.push_back(ListenerStatus{m_events[i].data.fd, toCondition(m_events[i].events)}); + + return result; + } + + /** + * Move operator. + * + * \param other the other + * \return this + */ + inline Epoll &operator=(Epoll &&other) + { + m_handle = other.m_handle; + other.m_handle = -1; + + return *this; + } }; #endif // !NET_HAVE_EPOLL @@ -3393,147 +3393,147 @@ */ class Kqueue { private: - std::vector<struct kevent> m_result; - int m_handle; - - Kqueue(const Kqueue &) = delete; - Kqueue &operator=(const Kqueue &) = delete; - - void update(Handle h, int filter, int kflags) - { - struct kevent ev; - - EV_SET(&ev, h, filter, kflags, 0, 0, nullptr); - - if (kevent(m_handle, &ev, 1, nullptr, 0, nullptr) < 0) - throw Error(); - } + std::vector<struct kevent> m_result; + int m_handle; + + Kqueue(const Kqueue &) = delete; + Kqueue &operator=(const Kqueue &) = delete; + + void update(Handle h, int filter, int kflags) + { + struct kevent ev; + + EV_SET(&ev, h, filter, kflags, 0, 0, nullptr); + + if (kevent(m_handle, &ev, 1, nullptr, 0, nullptr) < 0) + throw Error(); + } public: - /** - * Create kqueue. - * - * \throw Error on failures - */ - inline Kqueue() - : m_handle(kqueue()) - { - if (m_handle < 0) - throw Error(); - } - - /** - * Move constructor. - * - * \param other the other backend - */ - inline Kqueue(Kqueue &&other) noexcept - : m_handle(other.m_handle) - { - other.m_handle = -1; - } - - /** - * Close the kqueue descriptor. - */ - inline ~Kqueue() - { - if (m_handle != -1) - close(m_handle); - } - - /** - * Get the backend name. - * - * \return kqueue - */ - inline std::string name() const noexcept - { - return "kqueue"; - } - - /** - * Set socket. - * - * \param h the handle - * \param condition the condition - * \param add set to true if the socket is new to the backend - * \throw Error on failures - */ - void set(const ListenerTable &, Handle h, Condition condition, bool add) - { - if ((condition & Condition::Readable) == Condition::Readable) - update(h, EVFILT_READ, EV_ADD | EV_ENABLE); - if ((condition & Condition::Writable) == Condition::Writable) - update(h, EVFILT_WRITE, EV_ADD | EV_ENABLE); - if (add) - m_result.resize(m_result.size() + 1); - } - - /** - * Unset socket. - * - * \param h the handle - * \param condition the condition - * \param remove set to true if the socket is completely removed - * \throw Error on failures - */ - void unset(const ListenerTable &, Handle h, Condition condition, bool remove) - { - if ((condition & Condition::Readable) == Condition::Readable) - update(h, EVFILT_READ, EV_DELETE); - if ((condition & Condition::Writable) == Condition::Writable) - update(h, EVFILT_WRITE, EV_DELETE); - if (remove) - m_result.resize(m_result.size() - 1); - } - - /** - * Wait for sockets to be ready. - * - * \param ms the milliseconds timeout - * \return the sockets ready - * \throw Error on failures - */ - std::vector<ListenerStatus> wait(const ListenerTable &, int ms) - { - std::vector<ListenerStatus> sockets; - timespec ts = { 0, 0 }; - timespec *pts = (ms <= 0) ? nullptr : &ts; - - ts.tv_sec = ms / 1000; - ts.tv_nsec = (ms % 1000) * 1000000; - - int nevents = kevent(m_handle, nullptr, 0, &m_result[0], m_result.capacity(), pts); - - if (nevents == 0) - throw TimeoutError(); - if (nevents < 0) - throw Error(); - - for (int i = 0; i < nevents; ++i) { - sockets.push_back(ListenerStatus{ - static_cast<Handle>(m_result[i].ident), - m_result[i].filter == EVFILT_READ ? Condition::Readable : Condition::Writable - }); - } - - return sockets; - } - - /** - * Move operator. - * - * \param other the other - * \return this - */ - inline Kqueue &operator=(Kqueue &&other) noexcept - { - m_handle = other.m_handle; - other.m_handle = -1; - - return *this; - } + /** + * Create kqueue. + * + * \throw Error on failures + */ + inline Kqueue() + : m_handle(kqueue()) + { + if (m_handle < 0) + throw Error(); + } + + /** + * Move constructor. + * + * \param other the other backend + */ + inline Kqueue(Kqueue &&other) noexcept + : m_handle(other.m_handle) + { + other.m_handle = -1; + } + + /** + * Close the kqueue descriptor. + */ + inline ~Kqueue() + { + if (m_handle != -1) + close(m_handle); + } + + /** + * Get the backend name. + * + * \return kqueue + */ + inline std::string name() const noexcept + { + return "kqueue"; + } + + /** + * Set socket. + * + * \param h the handle + * \param condition the condition + * \param add set to true if the socket is new to the backend + * \throw Error on failures + */ + void set(const ListenerTable &, Handle h, Condition condition, bool add) + { + if ((condition & Condition::Readable) == Condition::Readable) + update(h, EVFILT_READ, EV_ADD | EV_ENABLE); + if ((condition & Condition::Writable) == Condition::Writable) + update(h, EVFILT_WRITE, EV_ADD | EV_ENABLE); + if (add) + m_result.resize(m_result.size() + 1); + } + + /** + * Unset socket. + * + * \param h the handle + * \param condition the condition + * \param remove set to true if the socket is completely removed + * \throw Error on failures + */ + void unset(const ListenerTable &, Handle h, Condition condition, bool remove) + { + if ((condition & Condition::Readable) == Condition::Readable) + update(h, EVFILT_READ, EV_DELETE); + if ((condition & Condition::Writable) == Condition::Writable) + update(h, EVFILT_WRITE, EV_DELETE); + if (remove) + m_result.resize(m_result.size() - 1); + } + + /** + * Wait for sockets to be ready. + * + * \param ms the milliseconds timeout + * \return the sockets ready + * \throw Error on failures + */ + std::vector<ListenerStatus> wait(const ListenerTable &, int ms) + { + std::vector<ListenerStatus> sockets; + timespec ts = { 0, 0 }; + timespec *pts = (ms <= 0) ? nullptr : &ts; + + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; + + int nevents = kevent(m_handle, nullptr, 0, &m_result[0], m_result.capacity(), pts); + + if (nevents == 0) + throw TimeoutError(); + if (nevents < 0) + throw Error(); + + for (int i = 0; i < nevents; ++i) { + sockets.push_back(ListenerStatus{ + static_cast<Handle>(m_result[i].ident), + m_result[i].filter == EVFILT_READ ? Condition::Readable : Condition::Writable + }); + } + + return sockets; + } + + /** + * Move operator. + * + * \param other the other + * \return this + */ + inline Kqueue &operator=(Kqueue &&other) noexcept + { + m_handle = other.m_handle; + other.m_handle = -1; + + return *this; + } }; #endif // !NET_HAVE_KQUEUE @@ -3549,120 +3549,120 @@ */ class Poll { private: - std::vector<pollfd> m_fds; - - short toPoll(Condition condition) const noexcept - { - short result = 0; - - if ((condition & Condition::Readable) == Condition::Readable) - result |= POLLIN; - if ((condition & Condition::Writable) == Condition::Writable) - result |= POLLOUT; - - return result; - } - - Condition toCondition(short &event) const noexcept - { - Condition condition = Condition::None; - - /* - * Poll implementations mark the socket differently regarding the disconnection of a socket. - * - * At least, even if POLLHUP or POLLIN is set, recv() always return 0 so we mark the socket as readable. - */ - if ((event & POLLIN) || (event & POLLHUP)) - condition |= Condition::Readable; - if (event & POLLOUT) - condition |= Condition::Writable; - - // Reset event for safety. - event = 0; - - return condition; - } + std::vector<pollfd> m_fds; + + short toPoll(Condition condition) const noexcept + { + short result = 0; + + if ((condition & Condition::Readable) == Condition::Readable) + result |= POLLIN; + if ((condition & Condition::Writable) == Condition::Writable) + result |= POLLOUT; + + return result; + } + + Condition toCondition(short &event) const noexcept + { + Condition condition = Condition::None; + + /* + * Poll implementations mark the socket differently regarding the disconnection of a socket. + * + * At least, even if POLLHUP or POLLIN is set, recv() always return 0 so we mark the socket as readable. + */ + if ((event & POLLIN) || (event & POLLHUP)) + condition |= Condition::Readable; + if (event & POLLOUT) + condition |= Condition::Writable; + + // Reset event for safety. + event = 0; + + return condition; + } public: - /** - * Get the backend name. - * - * \return kqueue - */ - inline std::string name() const noexcept - { - return "poll"; - } - - /** - * Set socket. - * - * \param h the handle - * \param condition the condition - * \param add set to true if the socket is new to the backend - * \throw Error on failures - */ - void set(const ListenerTable &, Handle h, Condition condition, bool add) - { - if (add) - m_fds.push_back(pollfd{h, toPoll(condition), 0}); - else { - auto it = std::find_if(m_fds.begin(), m_fds.end(), [&] (const pollfd &pfd) { - return pfd.fd == h; - }); - - it->events |= toPoll(condition); - } - } - - /** - * Unset socket. - * - * \param h the handle - * \param condition the condition - * \param remove set to true if the socket is completely removed - * \throw Error on failures - */ - void unset(const ListenerTable &, Handle h, Condition condition, bool remove) - { - auto it = std::find_if(m_fds.begin(), m_fds.end(), [&] (const pollfd &pfd) { - return pfd.fd == h; - }); - - if (remove) - m_fds.erase(it); - else - it->events &= ~(toPoll(condition)); - } - - /** - * Wait for sockets to be ready. - * - * \param ms the milliseconds timeout - * \return the sockets ready - * \throw Error on failures - */ - std::vector<ListenerStatus> wait(const ListenerTable &, int ms) - { + /** + * Get the backend name. + * + * \return kqueue + */ + inline std::string name() const noexcept + { + return "poll"; + } + + /** + * Set socket. + * + * \param h the handle + * \param condition the condition + * \param add set to true if the socket is new to the backend + * \throw Error on failures + */ + void set(const ListenerTable &, Handle h, Condition condition, bool add) + { + if (add) + m_fds.push_back(pollfd{h, toPoll(condition), 0}); + else { + auto it = std::find_if(m_fds.begin(), m_fds.end(), [&] (const pollfd &pfd) { + return pfd.fd == h; + }); + + it->events |= toPoll(condition); + } + } + + /** + * Unset socket. + * + * \param h the handle + * \param condition the condition + * \param remove set to true if the socket is completely removed + * \throw Error on failures + */ + void unset(const ListenerTable &, Handle h, Condition condition, bool remove) + { + auto it = std::find_if(m_fds.begin(), m_fds.end(), [&] (const pollfd &pfd) { + return pfd.fd == h; + }); + + if (remove) + m_fds.erase(it); + else + it->events &= ~(toPoll(condition)); + } + + /** + * Wait for sockets to be ready. + * + * \param ms the milliseconds timeout + * \return the sockets ready + * \throw Error on failures + */ + std::vector<ListenerStatus> wait(const ListenerTable &, int ms) + { #if defined(_WIN32) - auto result = WSAPoll(m_fds.data(), (ULONG)m_fds.size(), ms); + auto result = WSAPoll(m_fds.data(), (ULONG)m_fds.size(), ms); #else - auto result = poll(m_fds.data(), m_fds.size(), ms); + auto result = poll(m_fds.data(), m_fds.size(), ms); #endif - if (result == 0) - throw TimeoutError(); - if (result < 0) - throw Error(); - - std::vector<ListenerStatus> sockets; - - for (auto &fd : m_fds) - if (fd.revents != 0) - sockets.push_back(ListenerStatus{fd.fd, toCondition(fd.revents)}); - - return sockets; - } + if (result == 0) + throw TimeoutError(); + if (result < 0) + throw Error(); + + std::vector<ListenerStatus> sockets; + + for (auto &fd : m_fds) + if (fd.revents != 0) + sockets.push_back(ListenerStatus{fd.fd, toCondition(fd.revents)}); + + return sockets; + } }; #endif // !NET_HAVE_POLL @@ -3675,82 +3675,82 @@ */ class Select { public: - /** - * Get the backend name. - * - * \return select - */ - inline std::string name() const - { - return "select"; - } - - /** - * No-op. - */ - inline void set(const ListenerTable &, Handle, Condition, bool) noexcept - { - } - - /** - * No-op. - */ - inline void unset(const ListenerTable &, Handle, Condition, bool) noexcept - { - } - - /** - * Wait for sockets to be ready. - * - * \param table the listener table - * \param ms the milliseconds timeout - * \return the sockets ready - * \throw Error on failures - */ - std::vector<ListenerStatus> wait(const ListenerTable &table, int ms) - { - timeval maxwait, *towait; - fd_set readset; - fd_set writeset; - - FD_ZERO(&readset); - FD_ZERO(&writeset); - - Handle max = 0; - - for (const auto &pair : table) { - if ((pair.second & Condition::Readable) == Condition::Readable) - FD_SET(pair.first, &readset); - if ((pair.second & Condition::Writable) == Condition::Writable) - FD_SET(pair.first, &writeset); - if (pair.first > max) - max = pair.first; - } - - maxwait.tv_sec = 0; - maxwait.tv_usec = ms * 1000; - - // Set to nullptr for infinite timeout. - towait = (ms < 0) ? nullptr : &maxwait; - - auto error = ::select(static_cast<int>(max + 1), &readset, &writeset, nullptr, towait); - - if (error == Failure) - throw Error(); - if (error == 0) - throw TimeoutError(); - - std::vector<ListenerStatus> sockets; - - for (const auto &pair : table) { - if (FD_ISSET(pair.first, &readset)) - sockets.push_back(ListenerStatus{pair.first, Condition::Readable}); - if (FD_ISSET(pair.first, &writeset)) - sockets.push_back(ListenerStatus{pair.first, Condition::Writable}); - } - - return sockets; - } + /** + * Get the backend name. + * + * \return select + */ + inline std::string name() const + { + return "select"; + } + + /** + * No-op. + */ + inline void set(const ListenerTable &, Handle, Condition, bool) noexcept + { + } + + /** + * No-op. + */ + inline void unset(const ListenerTable &, Handle, Condition, bool) noexcept + { + } + + /** + * Wait for sockets to be ready. + * + * \param table the listener table + * \param ms the milliseconds timeout + * \return the sockets ready + * \throw Error on failures + */ + std::vector<ListenerStatus> wait(const ListenerTable &table, int ms) + { + timeval maxwait, *towait; + fd_set readset; + fd_set writeset; + + FD_ZERO(&readset); + FD_ZERO(&writeset); + + Handle max = 0; + + for (const auto &pair : table) { + if ((pair.second & Condition::Readable) == Condition::Readable) + FD_SET(pair.first, &readset); + if ((pair.second & Condition::Writable) == Condition::Writable) + FD_SET(pair.first, &writeset); + if (pair.first > max) + max = pair.first; + } + + maxwait.tv_sec = 0; + maxwait.tv_usec = ms * 1000; + + // Set to nullptr for infinite timeout. + towait = (ms < 0) ? nullptr : &maxwait; + + auto error = ::select(static_cast<int>(max + 1), &readset, &writeset, nullptr, towait); + + if (error == Failure) + throw Error(); + if (error == 0) + throw TimeoutError(); + + std::vector<ListenerStatus> sockets; + + for (const auto &pair : table) { + if (FD_ISSET(pair.first, &readset)) + sockets.push_back(ListenerStatus{pair.first, Condition::Readable}); + if (FD_ISSET(pair.first, &writeset)) + sockets.push_back(ListenerStatus{pair.first, Condition::Writable}); + } + + return sockets; + } }; } // !backend @@ -3772,237 +3772,237 @@ template <typename Backend = backend :: NET_DEFAULT_BACKEND> class Listener { private: - Backend m_backend; - ListenerTable m_table; + Backend m_backend; + ListenerTable m_table; public: - /** - * Construct an empty listener. - */ - Listener() = default; - - /** - * Get the backend. - * - * \return the backend - */ - inline const Backend &backend() const noexcept - { - return m_backend; - } - - /** - * Get the non-modifiable table. - * - * \return the table - */ - inline const ListenerTable &table() const noexcept - { - return m_table; - } - - /** - * Overloaded function. - * - * \return the iterator - */ - inline ListenerTable::const_iterator begin() const noexcept - { - return m_table.begin(); - } - - /** - * Overloaded function. - * - * \return the iterator - */ - inline ListenerTable::const_iterator cbegin() const noexcept - { - return m_table.cbegin(); - } - - /** - * Overloaded function. - * - * \return the iterator - */ - inline ListenerTable::const_iterator end() const noexcept - { - return m_table.end(); - } - - /** - * Overloaded function. - * - * \return the iterator - */ - inline ListenerTable::const_iterator cend() const noexcept - { - return m_table.cend(); - } - - /** - * Add or update a socket to the listener. - * - * If the socket is already placed with the appropriate flags, the - * function is a no-op. - * - * If incorrect flags are passed, the function does nothing. - * - * \param sc the socket - * \param condition the condition (may be OR'ed) - * \throw Error if the backend failed to set - */ - void set(Handle sc, Condition condition) - { - // Invalid or useless flags. - if (condition == Condition::None || static_cast<int>(condition) > 0x3) - return; - - auto it = m_table.find(sc); - - // Do not update the table if the backend failed to add or update. - if (it == m_table.end()) { - m_backend.set(m_table, sc, condition, true); - m_table.emplace(sc, condition); - } else { - // Remove flag if already present. - if ((condition & Condition::Readable) == Condition::Readable && - (it->second & Condition::Readable) == Condition::Readable) - condition &= ~(Condition::Readable); - if ((condition & Condition::Writable) == Condition::Writable && - (it->second & Condition::Writable) == Condition::Writable) - condition &= ~(Condition::Writable); - - // Still need a call? - if (condition != Condition::None) { - m_backend.set(m_table, sc, condition, false); - it->second |= condition; - } - } - } - - /** - * Unset a socket from the listener, only the flags is removed - * unless the two flagss are requested. - * - * For example, if you added a socket for both reading and writing, - * unsetting the write flags will keep the socket for reading. - * - * \param sc the socket - * \param condition the condition (may be OR'ed) - * \see remove - */ - void unset(Handle sc, Condition condition) - { - auto it = m_table.find(sc); - - // Invalid or useless flags. - if (condition == Condition::None || static_cast<int>(condition) > 0x3 || it == m_table.end()) - return; - - // Like set, do not update if the socket is already at the appropriate state. - if ((condition & Condition::Readable) == Condition::Readable && - (it->second & Condition::Readable) != Condition::Readable) - condition &= ~(Condition::Readable); - if ((condition & Condition::Writable) == Condition::Writable && - (it->second & Condition::Writable) != Condition::Writable) - condition &= ~(Condition::Writable); - - if (condition != Condition::None) { - // Determine if it's a complete removal. - bool removal = ((it->second) & ~(condition)) == Condition::None; - - m_backend.unset(m_table, sc, condition, removal); - - if (removal) - m_table.erase(it); - else - it->second &= ~(condition); - } - } - - /** - * Remove completely the socket from the listener. - * - * It is a shorthand for unset(sc, Condition::Readable | Condition::Writable); - * - * \param sc the socket - */ - inline void remove(Handle sc) - { - unset(sc, Condition::Readable | Condition::Writable); - } - - /** - * Remove all sockets. - */ - inline void clear() - { - while (!m_table.empty()) - remove(m_table.begin()->first); - } - - /** - * Get the number of sockets in the listener. - * - * \return the number of sockets - */ - inline ListenerTable::size_type size() const noexcept - { - return m_table.size(); - } - - /** - * Select a socket. Waits for a specific amount of time specified as the duration. - * - * \param duration the duration - * \return the socket ready - */ - template <typename Rep, typename Ratio> - inline ListenerStatus wait(const std::chrono::duration<Rep, Ratio> &duration) - { - auto cvt = std::chrono::duration_cast<std::chrono::milliseconds>(duration); - auto max = cvt.count() > INT_MAX ? INT_MAX : static_cast<int>(cvt.count()); - - return m_backend.wait(m_table, max)[0]; - } - - /** - * Overload with milliseconds. - * - * \param timeout the optional timeout in milliseconds - * \return the socket ready - */ - inline ListenerStatus wait(long long int timeout = -1) - { - return wait(std::chrono::milliseconds(timeout)); - } - - /** - * Select multiple sockets. - * - * \param duration the duration - * \return the socket ready - */ - template <typename Rep, typename Ratio> - inline std::vector<ListenerStatus> waitMultiple(const std::chrono::duration<Rep, Ratio> &duration) - { - auto cvt = std::chrono::duration_cast<std::chrono::milliseconds>(duration); - - return m_backend.wait(m_table, cvt.count()); - } - - /** - * Overload with milliseconds. - * - * \param timeout the optional timeout in milliseconds - * \return the socket ready - */ - inline std::vector<ListenerStatus> waitMultiple(int timeout = -1) - { - return waitMultiple(std::chrono::milliseconds(timeout)); - } + /** + * Construct an empty listener. + */ + Listener() = default; + + /** + * Get the backend. + * + * \return the backend + */ + inline const Backend &backend() const noexcept + { + return m_backend; + } + + /** + * Get the non-modifiable table. + * + * \return the table + */ + inline const ListenerTable &table() const noexcept + { + return m_table; + } + + /** + * Overloaded function. + * + * \return the iterator + */ + inline ListenerTable::const_iterator begin() const noexcept + { + return m_table.begin(); + } + + /** + * Overloaded function. + * + * \return the iterator + */ + inline ListenerTable::const_iterator cbegin() const noexcept + { + return m_table.cbegin(); + } + + /** + * Overloaded function. + * + * \return the iterator + */ + inline ListenerTable::const_iterator end() const noexcept + { + return m_table.end(); + } + + /** + * Overloaded function. + * + * \return the iterator + */ + inline ListenerTable::const_iterator cend() const noexcept + { + return m_table.cend(); + } + + /** + * Add or update a socket to the listener. + * + * If the socket is already placed with the appropriate flags, the + * function is a no-op. + * + * If incorrect flags are passed, the function does nothing. + * + * \param sc the socket + * \param condition the condition (may be OR'ed) + * \throw Error if the backend failed to set + */ + void set(Handle sc, Condition condition) + { + // Invalid or useless flags. + if (condition == Condition::None || static_cast<int>(condition) > 0x3) + return; + + auto it = m_table.find(sc); + + // Do not update the table if the backend failed to add or update. + if (it == m_table.end()) { + m_backend.set(m_table, sc, condition, true); + m_table.emplace(sc, condition); + } else { + // Remove flag if already present. + if ((condition & Condition::Readable) == Condition::Readable && + (it->second & Condition::Readable) == Condition::Readable) + condition &= ~(Condition::Readable); + if ((condition & Condition::Writable) == Condition::Writable && + (it->second & Condition::Writable) == Condition::Writable) + condition &= ~(Condition::Writable); + + // Still need a call? + if (condition != Condition::None) { + m_backend.set(m_table, sc, condition, false); + it->second |= condition; + } + } + } + + /** + * Unset a socket from the listener, only the flags is removed + * unless the two flagss are requested. + * + * For example, if you added a socket for both reading and writing, + * unsetting the write flags will keep the socket for reading. + * + * \param sc the socket + * \param condition the condition (may be OR'ed) + * \see remove + */ + void unset(Handle sc, Condition condition) + { + auto it = m_table.find(sc); + + // Invalid or useless flags. + if (condition == Condition::None || static_cast<int>(condition) > 0x3 || it == m_table.end()) + return; + + // Like set, do not update if the socket is already at the appropriate state. + if ((condition & Condition::Readable) == Condition::Readable && + (it->second & Condition::Readable) != Condition::Readable) + condition &= ~(Condition::Readable); + if ((condition & Condition::Writable) == Condition::Writable && + (it->second & Condition::Writable) != Condition::Writable) + condition &= ~(Condition::Writable); + + if (condition != Condition::None) { + // Determine if it's a complete removal. + bool removal = ((it->second) & ~(condition)) == Condition::None; + + m_backend.unset(m_table, sc, condition, removal); + + if (removal) + m_table.erase(it); + else + it->second &= ~(condition); + } + } + + /** + * Remove completely the socket from the listener. + * + * It is a shorthand for unset(sc, Condition::Readable | Condition::Writable); + * + * \param sc the socket + */ + inline void remove(Handle sc) + { + unset(sc, Condition::Readable | Condition::Writable); + } + + /** + * Remove all sockets. + */ + inline void clear() + { + while (!m_table.empty()) + remove(m_table.begin()->first); + } + + /** + * Get the number of sockets in the listener. + * + * \return the number of sockets + */ + inline ListenerTable::size_type size() const noexcept + { + return m_table.size(); + } + + /** + * Select a socket. Waits for a specific amount of time specified as the duration. + * + * \param duration the duration + * \return the socket ready + */ + template <typename Rep, typename Ratio> + inline ListenerStatus wait(const std::chrono::duration<Rep, Ratio> &duration) + { + auto cvt = std::chrono::duration_cast<std::chrono::milliseconds>(duration); + auto max = cvt.count() > INT_MAX ? INT_MAX : static_cast<int>(cvt.count()); + + return m_backend.wait(m_table, max)[0]; + } + + /** + * Overload with milliseconds. + * + * \param timeout the optional timeout in milliseconds + * \return the socket ready + */ + inline ListenerStatus wait(long long int timeout = -1) + { + return wait(std::chrono::milliseconds(timeout)); + } + + /** + * Select multiple sockets. + * + * \param duration the duration + * \return the socket ready + */ + template <typename Rep, typename Ratio> + inline std::vector<ListenerStatus> waitMultiple(const std::chrono::duration<Rep, Ratio> &duration) + { + auto cvt = std::chrono::duration_cast<std::chrono::milliseconds>(duration); + + return m_backend.wait(m_table, cvt.count()); + } + + /** + * Overload with milliseconds. + * + * \param timeout the optional timeout in milliseconds + * \return the socket ready + */ + inline std::vector<ListenerStatus> waitMultiple(int timeout = -1) + { + return waitMultiple(std::chrono::milliseconds(timeout)); + } }; @@ -4095,26 +4095,26 @@ inline address::Iterator resolve(const std::string &host, const std::string &service, int domain = AF_UNSPEC, int type = 0) { #if !defined(NET_NO_AUTO_INIT) - init(); + init(); #endif - struct addrinfo hints, *res, *p; - - std::memset(&hints, 0, sizeof (hints)); - hints.ai_family = domain; - hints.ai_socktype = type; - - int e = getaddrinfo(host.c_str(), service.c_str(), &hints, &res); - - if (e != 0) - throw Error(gai_strerror(e)); - - std::vector<address::Generic> addresses; - - for (p = res; p != nullptr; p = p->ai_next) - addresses.push_back(address::Generic(p->ai_addr, p->ai_addrlen)); - - return address::Iterator(addresses, 0); + struct addrinfo hints, *res, *p; + + std::memset(&hints, 0, sizeof (hints)); + hints.ai_family = domain; + hints.ai_socktype = type; + + int e = getaddrinfo(host.c_str(), service.c_str(), &hints, &res); + + if (e != 0) + throw Error(gai_strerror(e)); + + std::vector<address::Generic> addresses; + + for (p = res; p != nullptr; p = p->ai_next) + addresses.push_back(address::Generic(p->ai_addr, p->ai_addrlen)); + + return address::Iterator(addresses, 0); } #if 0 @@ -4133,7 +4133,7 @@ template <typename Address> address::Iterator resolve(const Socket<Address> &sc, const std::string &host, const std::string &service) { - return resolve(host, service, Address().domain(), sc.type()); + return resolve(host, service, Address().domain(), sc.type()); } #endif @@ -4153,13 +4153,13 @@ */ inline address::Generic resolveOne(const std::string &host, const std::string &service, int domain, int type) { - address::Iterator end; - address::Iterator it = resolve(host, service, domain, type); - - if (it == end) - throw Error("no address available"); - - return *it; + address::Iterator end; + address::Iterator it = resolve(host, service, domain, type); + + if (it == end) + throw Error("no address available"); + + return *it; } #if 0 @@ -4178,7 +4178,7 @@ template <typename Address> address::Generic resolveOne(const Socket<Address> &sc, const std::string &host, const std::string &service) { - return resolveOne(host, service, Address().domain(), sc.type()); + return resolveOne(host, service, Address().domain(), sc.type()); } #endif
--- a/modules/net/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/net/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -40,47 +40,47 @@ TEST(Options, reuse) { - SocketTcpIp s; + SocketTcpIp s; - try { - s.set(option::SockReuseAddress(true)); - ASSERT_TRUE(s.get<option::SockReuseAddress>()); + try { + s.set(option::SockReuseAddress(true)); + ASSERT_TRUE(s.get<option::SockReuseAddress>()); - s.set(option::SockReuseAddress(false)); - ASSERT_FALSE(s.get<option::SockReuseAddress>()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + s.set(option::SockReuseAddress(false)); + ASSERT_FALSE(s.get<option::SockReuseAddress>()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Options, nodelay) { - SocketTcpIp s; + SocketTcpIp s; - try { - s.set(option::TcpNoDelay(true)); - ASSERT_TRUE(s.get<option::TcpNoDelay>()); + try { + s.set(option::TcpNoDelay(true)); + ASSERT_TRUE(s.get<option::TcpNoDelay>()); - s.set(option::TcpNoDelay(false)); - ASSERT_FALSE(s.get<option::TcpNoDelay>()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + s.set(option::TcpNoDelay(false)); + ASSERT_FALSE(s.get<option::TcpNoDelay>()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Options, v6only) { - SocketTcpIpv6 s; + SocketTcpIpv6 s; - try { - s.set(option::Ipv6Only(true)); - ASSERT_TRUE(s.get<option::Ipv6Only>()); + try { + s.set(option::Ipv6Only(true)); + ASSERT_TRUE(s.get<option::Ipv6Only>()); - s.set(option::Ipv6Only(false)); - ASSERT_FALSE(s.get<option::Ipv6Only>()); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + s.set(option::Ipv6Only(false)); + ASSERT_FALSE(s.get<option::Ipv6Only>()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -90,77 +90,77 @@ class TcpServerTest : public testing::Test { protected: - SocketTcp<Ipv4> m_server; - SocketTcp<Ipv4> m_client; + SocketTcp<Ipv4> m_server; + SocketTcp<Ipv4> m_client; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - TcpServerTest() - { - m_server.set(SockReuseAddress()); - } + TcpServerTest() + { + m_server.set(SockReuseAddress()); + } - ~TcpServerTest() - { - if (m_tserver.joinable()) - m_tserver.join(); - if (m_tclient.joinable()) - m_tclient.join(); - } + ~TcpServerTest() + { + if (m_tserver.joinable()) + m_tserver.join(); + if (m_tclient.joinable()) + m_tclient.join(); + } }; TEST_F(TcpServerTest, connect) { - m_tserver = std::thread([this] () { - try { - SocketTcp<Ipv4> sc; + m_tserver = std::thread([this] () { + try { + SocketTcp<Ipv4> sc; - m_server.bind(Ipv4("*", 16000)); - m_server.listen(); - m_server.accept(); - m_server.close(); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } - }); + m_server.bind(Ipv4("*", 16000)); + m_server.listen(); + m_server.accept(); + m_server.close(); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } + }); - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(100ms); - m_tclient = std::thread([this] () { - try { - m_client.connect(Ipv4("127.0.0.1", 16000)); - m_client.close(); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } - }); + m_tclient = std::thread([this] () { + try { + m_client.connect(Ipv4("127.0.0.1", 16000)); + m_client.close(); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } + }); } TEST_F(TcpServerTest, io) { - m_tserver = std::thread([this] () { - m_server.bind(Ipv4("*", 16000)); - m_server.listen(); + m_tserver = std::thread([this] () { + m_server.bind(Ipv4("*", 16000)); + m_server.listen(); - SocketTcp<Ipv4> client = m_server.accept(); + SocketTcp<Ipv4> client = m_server.accept(); - auto msg = client.recv(512); + auto msg = client.recv(512); - ASSERT_EQ("hello world", msg); + ASSERT_EQ("hello world", msg); - client.send(msg); - }); + client.send(msg); + }); - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(100ms); - m_tclient = std::thread([this] () { - m_client.connect(Ipv4("127.0.0.1", 16000)); - m_client.send("hello world"); + m_tclient = std::thread([this] () { + m_client.connect(Ipv4("127.0.0.1", 16000)); + m_client.send("hello world"); - ASSERT_EQ("hello world", m_client.recv(512)); - }); + ASSERT_EQ("hello world", m_client.recv(512)); + }); } /* @@ -170,62 +170,62 @@ class UdpServerTest : public testing::Test { protected: - SocketUdp<Ipv4> m_server; - SocketUdp<Ipv4> m_client; + SocketUdp<Ipv4> m_server; + SocketUdp<Ipv4> m_client; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - UdpServerTest() - { - m_server.set(SockBlockMode()); - } + UdpServerTest() + { + m_server.set(SockBlockMode()); + } - ~UdpServerTest() - { - if (m_tserver.joinable()) - m_tserver.join(); - if (m_tclient.joinable()) - m_tclient.join(); - } + ~UdpServerTest() + { + if (m_tserver.joinable()) + m_tserver.join(); + if (m_tclient.joinable()) + m_tclient.join(); + } }; TEST_F(UdpServerTest, io) { - m_tserver = std::thread([this] () { - try { - Ipv4 client; - Ipv4 info("*", 16000); - - m_server.bind(info); + m_tserver = std::thread([this] () { + try { + Ipv4 client; + Ipv4 info("*", 16000); + + m_server.bind(info); + + auto msg = m_server.recvfrom(512, client); + + ASSERT_EQ("hello world", msg); - auto msg = m_server.recvfrom(512, client); - - ASSERT_EQ("hello world", msg); - - m_server.sendto(msg, client); - m_server.close(); - } catch (const net::Error &ex) { - FAIL() << ex.function() << ": " << ex.what(); - } - }); + m_server.sendto(msg, client); + m_server.close(); + } catch (const net::Error &ex) { + FAIL() << ex.function() << ": " << ex.what(); + } + }); - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(100ms); - m_tclient = std::thread([this] () { - try { - Ipv4 info("127.0.0.1", 16000); + m_tclient = std::thread([this] () { + try { + Ipv4 info("127.0.0.1", 16000); + + m_client.sendto("hello world", info); - m_client.sendto("hello world", info); - - ASSERT_EQ("hello world", m_client.recvfrom(512, info)); - - m_client.close(); - } catch (const net::Error &ex) { - FAIL() << ex.function() << ": " << ex.what(); - } - }); + ASSERT_EQ("hello world", m_client.recvfrom(512, info)); + + m_client.close(); + } catch (const net::Error &ex) { + FAIL() << ex.function() << ": " << ex.what(); + } + }); } /* @@ -235,105 +235,105 @@ class TestBackendSet { public: - int m_callcount{0}; - bool m_added{false}; - Condition m_flags{Condition::None}; + int m_callcount{0}; + bool m_added{false}; + Condition m_flags{Condition::None}; - inline void set(const ListenerTable &, Handle, Condition flags, bool add) noexcept - { - m_callcount ++; - m_added = add; - m_flags |= flags; - } + inline void set(const ListenerTable &, Handle, Condition flags, bool add) noexcept + { + m_callcount ++; + m_added = add; + m_flags |= flags; + } - inline void unset(const ListenerTable &, Handle, Condition, bool) noexcept - { - } + inline void unset(const ListenerTable &, Handle, Condition, bool) noexcept + { + } - std::vector<ListenerStatus> wait(const ListenerTable &, int) - { - return {}; - } + std::vector<ListenerStatus> wait(const ListenerTable &, int) + { + return {}; + } }; class TestBackendSetFail { public: - inline void set(const ListenerTable &, Handle, Condition, bool) - { - throw "fail"; - } + inline void set(const ListenerTable &, Handle, Condition, bool) + { + throw "fail"; + } - inline void unset(const ListenerTable &, Handle, Condition, bool) noexcept - { - } + inline void unset(const ListenerTable &, Handle, Condition, bool) noexcept + { + } - std::vector<ListenerStatus> wait(const ListenerTable &, int) - { - return {}; - } + std::vector<ListenerStatus> wait(const ListenerTable &, int) + { + return {}; + } }; TEST(ListenerSet, initialAdd) { - Listener<TestBackendSet> listener; - Handle s = 0; + Listener<TestBackendSet> listener; + Handle s = 0; - listener.set(s, Condition::Readable); + listener.set(s, Condition::Readable); - ASSERT_EQ(1U, listener.size()); - ASSERT_EQ(1, listener.backend().m_callcount); - ASSERT_TRUE(listener.backend().m_added); - ASSERT_TRUE(listener.backend().m_flags == Condition::Readable); + ASSERT_EQ(1U, listener.size()); + ASSERT_EQ(1, listener.backend().m_callcount); + ASSERT_TRUE(listener.backend().m_added); + ASSERT_TRUE(listener.backend().m_flags == Condition::Readable); } TEST(ListenerSet, readThenWrite) { - Listener<TestBackendSet> listener; - Handle s = 0; + Listener<TestBackendSet> listener; + Handle s = 0; - listener.set(s, Condition::Readable); - listener.set(s, Condition::Writable); + listener.set(s, Condition::Readable); + listener.set(s, Condition::Writable); - ASSERT_EQ(1U, listener.size()); - ASSERT_EQ(2, listener.backend().m_callcount); - ASSERT_FALSE(listener.backend().m_added); - ASSERT_TRUE(static_cast<int>(listener.backend().m_flags) == 0x3); + ASSERT_EQ(1U, listener.size()); + ASSERT_EQ(2, listener.backend().m_callcount); + ASSERT_FALSE(listener.backend().m_added); + ASSERT_TRUE(static_cast<int>(listener.backend().m_flags) == 0x3); } TEST(ListenerSet, allOneShot) { - Listener<TestBackendSet> listener; - Handle s = 0; + Listener<TestBackendSet> listener; + Handle s = 0; - listener.set(s, Condition::Readable | Condition::Writable); + listener.set(s, Condition::Readable | Condition::Writable); - ASSERT_EQ(1U, listener.size()); - ASSERT_EQ(1, listener.backend().m_callcount); - ASSERT_TRUE(listener.backend().m_added); - ASSERT_TRUE(static_cast<int>(listener.backend().m_flags) == 0x3); + ASSERT_EQ(1U, listener.size()); + ASSERT_EQ(1, listener.backend().m_callcount); + ASSERT_TRUE(listener.backend().m_added); + ASSERT_TRUE(static_cast<int>(listener.backend().m_flags) == 0x3); } TEST(ListenerSet, readTwice) { - Listener<TestBackendSet> listener; - Handle s = 0; + Listener<TestBackendSet> listener; + Handle s = 0; - listener.set(s, Condition::Readable); - listener.set(s, Condition::Readable); + listener.set(s, Condition::Readable); + listener.set(s, Condition::Readable); - ASSERT_EQ(1U, listener.size()); - ASSERT_EQ(1, listener.backend().m_callcount); - ASSERT_TRUE(listener.backend().m_added); - ASSERT_TRUE(listener.backend().m_flags == Condition::Readable); + ASSERT_EQ(1U, listener.size()); + ASSERT_EQ(1, listener.backend().m_callcount); + ASSERT_TRUE(listener.backend().m_added); + ASSERT_TRUE(listener.backend().m_flags == Condition::Readable); } TEST(ListenerSet, failure) { - Listener<TestBackendSetFail> listener; - Handle s = 0; + Listener<TestBackendSetFail> listener; + Handle s = 0; - ASSERT_ANY_THROW(listener.set(s, Condition::Readable)); - ASSERT_EQ(0U, listener.size()); + ASSERT_ANY_THROW(listener.set(s, Condition::Readable)); + ASSERT_EQ(0U, listener.size()); } /* @@ -343,119 +343,119 @@ class TestBackendUnset { public: - bool m_isset{false}; - bool m_isunset{false}; - Condition m_flags{Condition::None}; - bool m_removal{false}; + bool m_isset{false}; + bool m_isunset{false}; + Condition m_flags{Condition::None}; + bool m_removal{false}; - inline void set(const ListenerTable &, Handle &, Condition flags, bool) noexcept - { - m_isset = true; - m_flags |= flags; - } + inline void set(const ListenerTable &, Handle &, Condition flags, bool) noexcept + { + m_isset = true; + m_flags |= flags; + } - inline void unset(const ListenerTable &, Handle &, Condition flags, bool remove) noexcept - { - m_isunset = true; - m_flags &= ~(flags); - m_removal = remove; - } + inline void unset(const ListenerTable &, Handle &, Condition flags, bool remove) noexcept + { + m_isunset = true; + m_flags &= ~(flags); + m_removal = remove; + } - std::vector<ListenerStatus> wait(const ListenerTable &, int) noexcept - { - return {}; - } + std::vector<ListenerStatus> wait(const ListenerTable &, int) noexcept + { + return {}; + } }; class TestBackendUnsetFail { public: - inline void set(const ListenerTable &, Handle &, Condition, bool) noexcept - { - } + inline void set(const ListenerTable &, Handle &, Condition, bool) noexcept + { + } - inline void unset(const ListenerTable &, Handle &, Condition, bool) - { - throw "fail"; - } + inline void unset(const ListenerTable &, Handle &, Condition, bool) + { + throw "fail"; + } - std::vector<ListenerStatus> wait(const ListenerTable &, int) - { - return {}; - } + std::vector<ListenerStatus> wait(const ListenerTable &, int) + { + return {}; + } }; TEST(ListenerUnsetRemove, unset) { - Listener<TestBackendUnset> listener; - Handle s = 0; + Listener<TestBackendUnset> listener; + Handle s = 0; - listener.set(s, Condition::Readable); - listener.unset(s, Condition::Readable); + listener.set(s, Condition::Readable); + listener.unset(s, Condition::Readable); - ASSERT_EQ(0U, listener.size()); - ASSERT_TRUE(listener.backend().m_isset); - ASSERT_TRUE(listener.backend().m_isunset); - ASSERT_TRUE(listener.backend().m_flags == Condition::None); - ASSERT_TRUE(listener.backend().m_removal); + ASSERT_EQ(0U, listener.size()); + ASSERT_TRUE(listener.backend().m_isset); + ASSERT_TRUE(listener.backend().m_isunset); + ASSERT_TRUE(listener.backend().m_flags == Condition::None); + ASSERT_TRUE(listener.backend().m_removal); } TEST(ListenerUnsetRemove, unsetOne) { - Listener<TestBackendUnset> listener; - Handle s = 0; + Listener<TestBackendUnset> listener; + Handle s = 0; - listener.set(s, Condition::Readable | Condition::Writable); - listener.unset(s, Condition::Readable); + listener.set(s, Condition::Readable | Condition::Writable); + listener.unset(s, Condition::Readable); - ASSERT_EQ(1U, listener.size()); - ASSERT_TRUE(listener.backend().m_isset); - ASSERT_TRUE(listener.backend().m_isunset); - ASSERT_TRUE(listener.backend().m_flags == Condition::Writable); - ASSERT_FALSE(listener.backend().m_removal); + ASSERT_EQ(1U, listener.size()); + ASSERT_TRUE(listener.backend().m_isset); + ASSERT_TRUE(listener.backend().m_isunset); + ASSERT_TRUE(listener.backend().m_flags == Condition::Writable); + ASSERT_FALSE(listener.backend().m_removal); } TEST(ListenerUnsetRemove, unsetAll) { - Listener<TestBackendUnset> listener; - Handle s = 0; + Listener<TestBackendUnset> listener; + Handle s = 0; - listener.set(s, Condition::Readable | Condition::Writable); - listener.unset(s, Condition::Readable); - listener.unset(s, Condition::Writable); + listener.set(s, Condition::Readable | Condition::Writable); + listener.unset(s, Condition::Readable); + listener.unset(s, Condition::Writable); - ASSERT_EQ(0U, listener.size()); - ASSERT_TRUE(listener.backend().m_isset); - ASSERT_TRUE(listener.backend().m_isunset); - ASSERT_TRUE(listener.backend().m_flags == Condition::None); - ASSERT_TRUE(listener.backend().m_removal); + ASSERT_EQ(0U, listener.size()); + ASSERT_TRUE(listener.backend().m_isset); + ASSERT_TRUE(listener.backend().m_isunset); + ASSERT_TRUE(listener.backend().m_flags == Condition::None); + ASSERT_TRUE(listener.backend().m_removal); } TEST(ListenerUnsetRemove, remove) { - Listener<TestBackendUnset> listener; - Handle s = 0; + Listener<TestBackendUnset> listener; + Handle s = 0; - listener.set(s, Condition::Readable | Condition::Writable); - listener.remove(s); + listener.set(s, Condition::Readable | Condition::Writable); + listener.remove(s); - ASSERT_EQ(0U, listener.size()); - ASSERT_TRUE(listener.backend().m_isset); - ASSERT_TRUE(listener.backend().m_isunset); - ASSERT_TRUE(listener.backend().m_flags == Condition::None); - ASSERT_TRUE(listener.backend().m_removal); + ASSERT_EQ(0U, listener.size()); + ASSERT_TRUE(listener.backend().m_isset); + ASSERT_TRUE(listener.backend().m_isunset); + ASSERT_TRUE(listener.backend().m_flags == Condition::None); + ASSERT_TRUE(listener.backend().m_removal); } TEST(ListenerUnsetRemove, failure) { - Listener<TestBackendUnsetFail> listener; - Handle s = 0; + Listener<TestBackendUnsetFail> listener; + Handle s = 0; - listener.set(s, Condition::Readable | Condition::Writable); + listener.set(s, Condition::Readable | Condition::Writable); - ASSERT_ANY_THROW(listener.remove(s)); + ASSERT_ANY_THROW(listener.remove(s)); - // If fail, kept into the table. - ASSERT_EQ(1U, listener.size()); + // If fail, kept into the table. + ASSERT_EQ(1U, listener.size()); } /* @@ -465,73 +465,73 @@ class ListenerTest : public testing::Test { protected: - Listener<backend::Select> m_listener; - SocketTcp<Ipv4> m_masterTcp; - SocketTcp<Ipv4> m_clientTcp; + Listener<backend::Select> m_listener; + SocketTcp<Ipv4> m_masterTcp; + SocketTcp<Ipv4> m_clientTcp; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - ListenerTest() - { - m_masterTcp.set(SockReuseAddress()); - m_masterTcp.bind(Ipv4("*", 16000)); - m_masterTcp.listen(); - } + ListenerTest() + { + m_masterTcp.set(SockReuseAddress()); + m_masterTcp.bind(Ipv4("*", 16000)); + m_masterTcp.listen(); + } - ~ListenerTest() - { - if (m_tserver.joinable()) { - m_tserver.join(); - } - if (m_tclient.joinable()) { - m_tclient.join(); - } - } + ~ListenerTest() + { + if (m_tserver.joinable()) { + m_tserver.join(); + } + if (m_tclient.joinable()) { + m_tclient.join(); + } + } }; TEST_F(ListenerTest, accept) { - m_tserver = std::thread([this] () { - try { - m_listener.set(m_masterTcp.handle(), Condition::Readable); - m_listener.wait(); - m_masterTcp.accept(); - m_masterTcp.close(); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } - }); + m_tserver = std::thread([this] () { + try { + m_listener.set(m_masterTcp.handle(), Condition::Readable); + m_listener.wait(); + m_masterTcp.accept(); + m_masterTcp.close(); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } + }); - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(100ms); - m_tclient = std::thread([this] () { - m_clientTcp.connect(Ipv4("127.0.0.1", 16000)); - }); + m_tclient = std::thread([this] () { + m_clientTcp.connect(Ipv4("127.0.0.1", 16000)); + }); } TEST_F(ListenerTest, recv) { - m_tserver = std::thread([this] () { - try { - m_listener.set(m_masterTcp.handle(), Condition::Readable); - m_listener.wait(); + m_tserver = std::thread([this] () { + try { + m_listener.set(m_masterTcp.handle(), Condition::Readable); + m_listener.wait(); - SocketTcp<Ipv4> sc = m_masterTcp.accept(); + SocketTcp<Ipv4> sc = m_masterTcp.accept(); - ASSERT_EQ("hello", sc.recv(512)); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } - }); + ASSERT_EQ("hello", sc.recv(512)); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } + }); - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(100ms); - m_tclient = std::thread([this] () { - m_clientTcp.connect(Ipv4("127.0.0.1", 16000)); - m_clientTcp.send("hello"); - }); + m_tclient = std::thread([this] () { + m_clientTcp.connect(Ipv4("127.0.0.1", 16000)); + m_clientTcp.send("hello"); + }); } /* @@ -541,25 +541,25 @@ class NonBlockingConnectTest : public testing::Test { protected: - SocketTcp<Ipv4> m_server; - SocketTcp<Ipv4> m_client; + SocketTcp<Ipv4> m_server; + SocketTcp<Ipv4> m_client; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - NonBlockingConnectTest() - { - m_client.set(SockBlockMode(false)); - } + NonBlockingConnectTest() + { + m_client.set(SockBlockMode(false)); + } - ~NonBlockingConnectTest() - { - if (m_tserver.joinable()) - m_tserver.join(); - if (m_tclient.joinable()) - m_tclient.join(); - } + ~NonBlockingConnectTest() + { + if (m_tserver.joinable()) + m_tserver.join(); + if (m_tclient.joinable()) + m_tclient.join(); + } }; /* @@ -569,27 +569,27 @@ class TcpAcceptTest : public testing::Test { protected: - SocketTcp<Ipv4> m_server; - SocketTcp<Ipv4> m_client; + SocketTcp<Ipv4> m_server; + SocketTcp<Ipv4> m_client; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - TcpAcceptTest() - { - m_server.set(SockReuseAddress()); - m_server.bind(Ipv4("*", 16000)); - m_server.listen(); - } + TcpAcceptTest() + { + m_server.set(SockReuseAddress()); + m_server.bind(Ipv4("*", 16000)); + m_server.listen(); + } - ~TcpAcceptTest() - { - if (m_tserver.joinable()) - m_tserver.join(); - if (m_tclient.joinable()) - m_tclient.join(); - } + ~TcpAcceptTest() + { + if (m_tserver.joinable()) + m_tserver.join(); + if (m_tclient.joinable()) + m_tclient.join(); + } }; /* @@ -599,44 +599,44 @@ class TcpRecvTest : public testing::Test { protected: - SocketTcp<Ipv4> m_server; - SocketTcp<Ipv4> m_client; + SocketTcp<Ipv4> m_server; + SocketTcp<Ipv4> m_client; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - TcpRecvTest() - { - m_server.set(SockReuseAddress()); - m_server.bind(Ipv4("*", 16000)); - m_server.listen(); - } + TcpRecvTest() + { + m_server.set(SockReuseAddress()); + m_server.bind(Ipv4("*", 16000)); + m_server.listen(); + } - ~TcpRecvTest() - { - if (m_tserver.joinable()) - m_tserver.join(); - if (m_tclient.joinable()) - m_tclient.join(); - } + ~TcpRecvTest() + { + if (m_tserver.joinable()) + m_tserver.join(); + if (m_tclient.joinable()) + m_tclient.join(); + } }; TEST_F(TcpRecvTest, blockingSuccess) { - m_tserver = std::thread([this] () { - SocketTcp<Ipv4> client = m_server.accept(); + m_tserver = std::thread([this] () { + SocketTcp<Ipv4> client = m_server.accept(); - ASSERT_EQ("hello", client.recv(32)); - }); + ASSERT_EQ("hello", client.recv(32)); + }); - std::this_thread::sleep_for(100ms); + std::this_thread::sleep_for(100ms); - m_tclient = std::thread([this] () { - m_client.connect(Ipv4("127.0.0.1", 16000)); - m_client.send("hello"); - m_client.close(); - }); + m_tclient = std::thread([this] () { + m_client.connect(Ipv4("127.0.0.1", 16000)); + m_client.send("hello"); + m_client.close(); + }); } /* @@ -648,71 +648,71 @@ class TlsRecvTest : public testing::Test { protected: - SocketTls<Ipv4> m_server{nullptr}; - SocketTls<Ipv4> m_client{nullptr}; + SocketTls<Ipv4> m_server{nullptr}; + SocketTls<Ipv4> m_client{nullptr}; - std::thread m_tserver; - std::thread m_tclient; + std::thread m_tserver; + std::thread m_tclient; public: - TlsRecvTest() - { - Tls cp, sp; + TlsRecvTest() + { + Tls cp, sp; - // Client. - cp.setVerify(false); + // Client. + cp.setVerify(false); - m_client = SocketTls<Ipv4>(Ipv4(), std::move(cp)); + m_client = SocketTls<Ipv4>(Ipv4(), std::move(cp)); - // Server. - sp.setVerify(false); - sp.setCertificate(DIRECTORY "test.crt"); - sp.setPrivateKey(DIRECTORY "test.key"); + // Server. + sp.setVerify(false); + sp.setCertificate(DIRECTORY "test.crt"); + sp.setPrivateKey(DIRECTORY "test.key"); - m_server = SocketTls<Ipv4>(Ipv4(), std::move(sp)); - m_server.set(SockReuseAddress()); - m_server.bind(Ipv4("*", 16000)); - m_server.listen(); - } + m_server = SocketTls<Ipv4>(Ipv4(), std::move(sp)); + m_server.set(SockReuseAddress()); + m_server.bind(Ipv4("*", 16000)); + m_server.listen(); + } - ~TlsRecvTest() - { - if (m_tserver.joinable()) - m_tserver.join(); - if (m_tclient.joinable()) - m_tclient.join(); - } + ~TlsRecvTest() + { + if (m_tserver.joinable()) + m_tserver.join(); + if (m_tclient.joinable()) + m_tclient.join(); + } }; TEST_F(TlsRecvTest, blockingSuccess) { - m_tserver = std::thread([this] () { - try { - SocketTls<Ipv4> client = m_server.accept(); + m_tserver = std::thread([this] () { + try { + SocketTls<Ipv4> client = m_server.accept(); - ASSERT_EQ("hello", client.recv(32)); - } catch (const net::Error &ex) { - FAIL() << ex.function() << ": " << ex.what(); - } - }); + ASSERT_EQ("hello", client.recv(32)); + } catch (const net::Error &ex) { + FAIL() << ex.function() << ": " << ex.what(); + } + }); - std::this_thread::sleep_for(250ms); + std::this_thread::sleep_for(250ms); - m_tclient = std::thread([this] () { - try { - m_client.connect(Ipv4("127.0.0.1", 16000)); - m_client.send("hello"); - } catch (const net::Error &ex) { - FAIL() << ex.function() << ": " << ex.what(); - } - }); + m_tclient = std::thread([this] () { + try { + m_client.connect(Ipv4("127.0.0.1", 16000)); + m_client.send("hello"); + } catch (const net::Error &ex) { + FAIL() << ex.function() << ": " << ex.what(); + } + }); } #endif int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/options/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/options/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -19,8 +19,8 @@ project(options) code_define_module( - NAME options - SOURCES - ${options_SOURCE_DIR}/options.cpp - ${options_SOURCE_DIR}/options.h + NAME options + SOURCES + ${options_SOURCE_DIR}/options.cpp + ${options_SOURCE_DIR}/options.h )
--- a/modules/options/options.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/options/options.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -29,152 +29,152 @@ inline bool isOption(const std::string &arg) noexcept { - return arg.size() >= 2 && arg[0] == '-'; + return arg.size() >= 2 && arg[0] == '-'; } inline bool isLongOption(const std::string &arg) noexcept { - assert(isOption(arg)); + assert(isOption(arg)); - return arg.size() >= 3 && arg[1] == '-'; + return arg.size() >= 3 && arg[1] == '-'; } inline bool isShortSimple(const std::string &arg) noexcept { - assert(isOption(arg)); - assert(!isLongOption(arg)); + assert(isOption(arg)); + assert(!isLongOption(arg)); - return arg.size() == 2; + return arg.size() == 2; } void parseLongOption(Result &result, Args &args, Iterator &it, Iterator &end, const Options &definition) { - auto arg = *it++; - auto opt = definition.find(arg); + auto arg = *it++; + auto opt = definition.find(arg); - if (opt == definition.end()) - throw InvalidOption{arg}; + if (opt == definition.end()) + throw InvalidOption{arg}; - /* Need argument? */ - if (opt->second) { - if (it == end || isOption(*it)) - throw MissingValue{arg}; + /* Need argument? */ + if (opt->second) { + if (it == end || isOption(*it)) + throw MissingValue{arg}; - result.insert(std::make_pair(arg, *it++)); - it = args.erase(args.begin(), it); - end = args.end(); - } else { - result.insert(std::make_pair(arg, "")); - it = args.erase(args.begin()); - end = args.end(); - } + result.insert(std::make_pair(arg, *it++)); + it = args.erase(args.begin(), it); + end = args.end(); + } else { + result.insert(std::make_pair(arg, "")); + it = args.erase(args.begin()); + end = args.end(); + } } void parseShortOption(Result &result, Args &args, Iterator &it, Iterator &end, const Options &definition) { - if (isShortSimple(*it)) { - /* - * Here two cases: - * - * -v (no option) - * -c value - */ - auto arg = *it++; - auto opt = definition.find(arg); + if (isShortSimple(*it)) { + /* + * Here two cases: + * + * -v (no option) + * -c value + */ + auto arg = *it++; + auto opt = definition.find(arg); - if (opt == definition.end()) - throw InvalidOption{arg}; + if (opt == definition.end()) + throw InvalidOption{arg}; - /* Need argument? */ - if (opt->second) { - if (it == end || isOption(*it)) - throw MissingValue{arg}; + /* Need argument? */ + if (opt->second) { + if (it == end || isOption(*it)) + throw MissingValue{arg}; - result.insert(std::make_pair(arg, *it++)); - it = args.erase(args.begin(), it); - end = args.end(); - } else { - result.insert(std::make_pair(arg, "")); - it = args.erase(args.begin()); - end = args.end(); - } - } else { - /* - * Here multiple scenarios: - * - * 1. -abc (-a -b -c if all are simple boolean arguments) - * 2. -vc foo.conf (-v -c foo.conf if -c is argument dependant) - * 3. -vcfoo.conf (-v -c foo.conf also) - */ - auto value = it->substr(1); - auto len = value.length(); - int toremove = 1; + result.insert(std::make_pair(arg, *it++)); + it = args.erase(args.begin(), it); + end = args.end(); + } else { + result.insert(std::make_pair(arg, "")); + it = args.erase(args.begin()); + end = args.end(); + } + } else { + /* + * Here multiple scenarios: + * + * 1. -abc (-a -b -c if all are simple boolean arguments) + * 2. -vc foo.conf (-v -c foo.conf if -c is argument dependant) + * 3. -vcfoo.conf (-v -c foo.conf also) + */ + auto value = it->substr(1); + auto len = value.length(); + int toremove = 1; - for (decltype(len) i = 0; i < len; ++i) { - auto arg = std::string{'-'} + value[i]; - auto opt = definition.find(arg); + for (decltype(len) i = 0; i < len; ++i) { + auto arg = std::string{'-'} + value[i]; + auto opt = definition.find(arg); - if (opt == definition.end()) - throw InvalidOption{arg}; + if (opt == definition.end()) + throw InvalidOption{arg}; - if (opt->second) { - if (i == (len - 1)) { - /* End of string, get the next argument (see 2.) */ - if (++it == end || isOption(*it)) - throw MissingValue{arg}; + if (opt->second) { + if (i == (len - 1)) { + /* End of string, get the next argument (see 2.) */ + if (++it == end || isOption(*it)) + throw MissingValue{arg}; - result.insert(std::make_pair(arg, *it)); - toremove += 1; - } else { - result.insert(std::make_pair(arg, value.substr(i + 1))); - i = len; - } - } else { - result.insert(std::make_pair(arg, "")); - } - } + result.insert(std::make_pair(arg, *it)); + toremove += 1; + } else { + result.insert(std::make_pair(arg, value.substr(i + 1))); + i = len; + } + } else { + result.insert(std::make_pair(arg, "")); + } + } - it = args.erase(args.begin(), args.begin() + toremove); - end = args.end(); - } + it = args.erase(args.begin(), args.begin() + toremove); + end = args.end(); + } } } // !namespace Result read(std::vector<std::string> &args, const Options &definition) { - Result result; + Result result; - auto it = args.begin(); - auto end = args.end(); + auto it = args.begin(); + auto end = args.end(); - while (it != end) { - if (!isOption(*it)) - break; + while (it != end) { + if (!isOption(*it)) + break; - if (isLongOption(*it)) - parseLongOption(result, args, it, end, definition); - else - parseShortOption(result, args, it, end, definition); - } + if (isLongOption(*it)) + parseLongOption(result, args, it, end, definition); + else + parseShortOption(result, args, it, end, definition); + } - return result; + return result; } Result read(int &argc, char **&argv, const Options &definition) { - std::vector<std::string> args; + std::vector<std::string> args; - for (int i = 0; i < argc; ++i) - args.push_back(argv[i]); + for (int i = 0; i < argc; ++i) + args.push_back(argv[i]); - auto before = args.size(); - auto result = read(args, definition); + auto before = args.size(); + auto result = read(args, definition); - argc -= before - args.size(); - argv += before - args.size(); + argc -= before - args.size(); + argv += before - args.size(); - return result; + return result; } } // !option
--- a/modules/options/options.h Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/options/options.h Wed Jun 15 13:13:26 2016 +0200 @@ -36,34 +36,34 @@ */ class InvalidOption : public std::exception { private: - std::string message; + std::string message; public: - /** - * The invalid option given. - */ - std::string argument; + /** + * The invalid option given. + */ + std::string argument; - /** - * Construct the exception. - * - * @param arg the argument missing - */ - inline InvalidOption(std::string arg) - : argument{std::move(arg)} - { - message = std::string{"invalid option: "} + argument; - } + /** + * Construct the exception. + * + * @param arg the argument missing + */ + inline InvalidOption(std::string arg) + : argument{std::move(arg)} + { + message = std::string{"invalid option: "} + argument; + } - /** - * Get the error message. - * - * @return the error message - */ - const char *what() const noexcept override - { - return message.c_str(); - } + /** + * Get the error message. + * + * @return the error message + */ + const char *what() const noexcept override + { + return message.c_str(); + } }; /** @@ -72,34 +72,34 @@ */ class MissingValue : public std::exception { private: - std::string message; + std::string message; public: - /** - * The argument that requires a value. - */ - std::string argument; + /** + * The argument that requires a value. + */ + std::string argument; - /** - * Construct the exception. - * - * @param arg the argument that requires a value - */ - inline MissingValue(std::string arg) - : argument{std::move(arg)} - { - message = std::string{"missing argument for: "} + argument; - } + /** + * Construct the exception. + * + * @param arg the argument that requires a value + */ + inline MissingValue(std::string arg) + : argument{std::move(arg)} + { + message = std::string{"missing argument for: "} + argument; + } - /** - * Get the error message. - * - * @return the error message - */ - const char *what() const noexcept override - { - return message.c_str(); - } + /** + * Get the error message. + * + * @return the error message + */ + const char *what() const noexcept override + { + return message.c_str(); + } }; /**
--- a/modules/options/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/options/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -26,96 +26,96 @@ TEST(Short, simpleNoArg) { - std::vector<std::string> args{"-a", "-b"}; + std::vector<std::string> args{"-a", "-b"}; - option::Options options{ - { "-a", false }, - { "-b", false } - }; + option::Options options{ + { "-a", false }, + { "-b", false } + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(2U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(2U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_TRUE(pack.count("-a") != 0); - ASSERT_TRUE(pack.count("-b") != 0); + ASSERT_TRUE(pack.count("-a") != 0); + ASSERT_TRUE(pack.count("-b") != 0); } TEST(Short, simpleArg) { - std::vector<std::string> args{"-v", "-cfoo.conf"}; + std::vector<std::string> args{"-v", "-cfoo.conf"}; - option::Options options{ - { "-v", false }, - { "-c", true } - }; + option::Options options{ + { "-v", false }, + { "-c", true } + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(2U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(2U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_TRUE(pack.count("-v") != 0); - ASSERT_EQ("foo.conf", pack.find("-c")->second); + ASSERT_TRUE(pack.count("-v") != 0); + ASSERT_EQ("foo.conf", pack.find("-c")->second); } TEST(Short, spacedArg) { - std::vector<std::string> args{"-v", "-c", "foo.conf"}; + std::vector<std::string> args{"-v", "-c", "foo.conf"}; - option::Options options{ - { "-v", false }, - { "-c", true } - }; + option::Options options{ + { "-v", false }, + { "-c", true } + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(2U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(2U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_TRUE(pack.count("-v") != 0); - ASSERT_EQ("foo.conf", pack.find("-c")->second); + ASSERT_TRUE(pack.count("-v") != 0); + ASSERT_EQ("foo.conf", pack.find("-c")->second); } TEST(Short, compacted) { - std::vector<std::string> args{"-abc"}; + std::vector<std::string> args{"-abc"}; - option::Options options{ - { "-a", false }, - { "-b", false }, - { "-c", false }, - }; + option::Options options{ + { "-a", false }, + { "-b", false }, + { "-c", false }, + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(3U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(3U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_TRUE(pack.count("-a") != 0); - ASSERT_TRUE(pack.count("-b") != 0); - ASSERT_TRUE(pack.count("-c") != 0); + ASSERT_TRUE(pack.count("-a") != 0); + ASSERT_TRUE(pack.count("-b") != 0); + ASSERT_TRUE(pack.count("-c") != 0); } TEST(Short, compactedArg) { - std::vector<std::string> args{"-vdcfoo.conf"}; + std::vector<std::string> args{"-vdcfoo.conf"}; - option::Options options{ - { "-v", false }, - { "-d", false }, - { "-c", true }, - }; + option::Options options{ + { "-v", false }, + { "-d", false }, + { "-c", true }, + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(3U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(3U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_TRUE(pack.count("-v") != 0); - ASSERT_TRUE(pack.count("-d") != 0); - ASSERT_EQ("foo.conf", pack.find("-c")->second); + ASSERT_TRUE(pack.count("-v") != 0); + ASSERT_TRUE(pack.count("-d") != 0); + ASSERT_EQ("foo.conf", pack.find("-c")->second); } /* -------------------------------------------------------- @@ -124,37 +124,37 @@ TEST(Long, simple) { - std::vector<std::string> args{"--fullscreen"}; + std::vector<std::string> args{"--fullscreen"}; - option::Options options{ - { "--verbose", false }, - { "--fullscreen", false } - }; + option::Options options{ + { "--verbose", false }, + { "--fullscreen", false } + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(1U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(1U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_TRUE(pack.count("--fullscreen") != 0); + ASSERT_TRUE(pack.count("--fullscreen") != 0); } TEST(Long, simpleArg) { - std::vector<std::string> args{"--config", "config.conf", "--level", "2"}; + std::vector<std::string> args{"--config", "config.conf", "--level", "2"}; - option::Options options{ - { "--config", true }, - { "--level", true } - }; + option::Options options{ + { "--config", true }, + { "--level", true } + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(2U, pack.size()); - ASSERT_EQ(0U, args.size()); + ASSERT_EQ(2U, pack.size()); + ASSERT_EQ(0U, args.size()); - ASSERT_EQ("config.conf", pack.find("--config")->second); - ASSERT_EQ("2", pack.find("--level")->second); + ASSERT_EQ("config.conf", pack.find("--config")->second); + ASSERT_EQ("2", pack.find("--level")->second); } /* -------------------------------------------------------- @@ -163,122 +163,122 @@ TEST(Errors, stop) { - std::vector<std::string> args{"-v", "install", "-y", "irccd"}; - std::vector<std::string> expected{"install", "-y", "irccd"}; + std::vector<std::string> args{"-v", "install", "-y", "irccd"}; + std::vector<std::string> expected{"install", "-y", "irccd"}; - option::Options options{ - { "-v", false } - }; + option::Options options{ + { "-v", false } + }; - option::Result pack = option::read(args, options); + option::Result pack = option::read(args, options); - ASSERT_EQ(1U, pack.size()); - ASSERT_EQ(3U, args.size()); + ASSERT_EQ(1U, pack.size()); + ASSERT_EQ(3U, args.size()); - ASSERT_TRUE(pack.count("-v") != 0); - ASSERT_EQ(expected, args); + ASSERT_TRUE(pack.count("-v") != 0); + ASSERT_EQ(expected, args); } TEST(Errors, missingShortArg) { - std::vector<std::string> args{"-c"}; + std::vector<std::string> args{"-c"}; - option::Options options{ - { "-c", true } - }; + option::Options options{ + { "-c", true } + }; - try { - option::Result pack = option::read(args, options); + try { + option::Result pack = option::read(args, options); - FAIL() << "exception expected"; - } catch (const option::MissingValue &) { - } + FAIL() << "exception expected"; + } catch (const option::MissingValue &) { + } } TEST(Errors, missingShortArg2) { - std::vector<std::string> args{"-vc"}; + std::vector<std::string> args{"-vc"}; - option::Options options{ - { "-v", false }, - { "-c", true } - }; + option::Options options{ + { "-v", false }, + { "-c", true } + }; - try { - option::Result pack = option::read(args, options); + try { + option::Result pack = option::read(args, options); - FAIL() << "exception expected"; - } catch (const option::MissingValue &) { - } + FAIL() << "exception expected"; + } catch (const option::MissingValue &) { + } } TEST(Errors, missingLongArg) { - std::vector<std::string> args{"--config"}; + std::vector<std::string> args{"--config"}; - option::Options options{ - { "--config", true } - }; + option::Options options{ + { "--config", true } + }; - try { - option::Result pack = option::read(args, options); + try { + option::Result pack = option::read(args, options); - FAIL() << "exception expected"; - } catch (const option::MissingValue &) { - } + FAIL() << "exception expected"; + } catch (const option::MissingValue &) { + } } TEST(Errors, invalidOption) { - std::vector<std::string> args{"-x"}; + std::vector<std::string> args{"-x"}; - option::Options options{ - { "-v", true } - }; + option::Options options{ + { "-v", true } + }; - try { - option::Result pack = option::read(args, options); + try { + option::Result pack = option::read(args, options); - FAIL() << "exception expected"; - } catch (const option::InvalidOption &) { - } + FAIL() << "exception expected"; + } catch (const option::InvalidOption &) { + } } TEST(Errors, invalidOption2) { - std::vector<std::string> args{"--destroy"}; + std::vector<std::string> args{"--destroy"}; - option::Options options{ - { "--verbose", true } - }; + option::Options options{ + { "--verbose", true } + }; - try { - option::Result pack = option::read(args, options); + try { + option::Result pack = option::read(args, options); - FAIL() << "exception expected"; - } catch (const option::InvalidOption &) { - } + FAIL() << "exception expected"; + } catch (const option::InvalidOption &) { + } } TEST(Errors, invalidOption3) { - std::vector<std::string> args{"-vx"}; + std::vector<std::string> args{"-vx"}; - option::Options options{ - { "-x", true } - }; + option::Options options{ + { "-x", true } + }; - try { - option::Result pack = option::read(args, options); + try { + option::Result pack = option::read(args, options); - FAIL() << "exception expected"; - } catch (const option::InvalidOption &) { - } + FAIL() << "exception expected"; + } catch (const option::InvalidOption &) { + } } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/timer/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/timer/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -17,6 +17,6 @@ # code_define_module( - NAME timer - SOURCES timer.hpp -) \ No newline at end of file + NAME timer + SOURCES timer.hpp +)
--- a/modules/timer/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/timer/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -24,43 +24,43 @@ TEST(Basic, repeat) { - Timer timer(Timer::Repeat, 500); - int max = 0; + Timer timer(Timer::Repeat, 500); + int max = 0; - timer.setHandler([&] () { - max ++; - }); - timer.start(); + timer.setHandler([&] () { + max ++; + }); + timer.start(); - // Should be at least 5 - std::this_thread::sleep_for(3s); + // Should be at least 5 + std::this_thread::sleep_for(3s); - ASSERT_GE(max, 5); + ASSERT_GE(max, 5); } TEST(Basic, restart) { - Timer timer(Timer::Repeat, 500); - int max = 0; + Timer timer(Timer::Repeat, 500); + int max = 0; - timer.setHandler([&] () { - max ++; - }); + timer.setHandler([&] () { + max ++; + }); - timer.start(); - std::this_thread::sleep_for(3s); - timer.stop(); - std::this_thread::sleep_for(3s); - timer.start(); - std::this_thread::sleep_for(3s); + timer.start(); + std::this_thread::sleep_for(3s); + timer.stop(); + std::this_thread::sleep_for(3s); + timer.start(); + std::this_thread::sleep_for(3s); - ASSERT_GE(max, 10); - ASSERT_LT(max, 15); + ASSERT_GE(max, 10); + ASSERT_LT(max, 15); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/timer/timer.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/timer/timer.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -38,148 +38,148 @@ */ class Timer { public: - /** - * \brief Type of timer. - */ - enum Type { - /// Periodic timer. - Repeat, - /// Oneshot timer. - Single - }; + /** + * \brief Type of timer. + */ + enum Type { + /// Periodic timer. + Repeat, + /// Oneshot timer. + Single + }; private: - Type m_type; - std::atomic<bool> m_alive{true}; - std::thread m_thread; - std::mutex m_mutex; - std::condition_variable m_condition; - std::function<void ()> m_handler; - std::uint32_t m_delay; + Type m_type; + std::atomic<bool> m_alive{true}; + std::thread m_thread; + std::mutex m_mutex; + std::condition_variable m_condition; + std::function<void ()> m_handler; + std::uint32_t m_delay; - inline void call() - { - if (m_alive && m_handler) - m_handler(); - } + inline void call() + { + if (m_alive && m_handler) + m_handler(); + } - inline void wait() - { - std::unique_lock<std::mutex> lock(m_mutex); + inline void wait() + { + std::unique_lock<std::mutex> lock(m_mutex); - m_condition.wait_for(lock, std::chrono::milliseconds(m_delay), [&] () { - return static_cast<bool>(!m_alive); - }); - } + m_condition.wait_for(lock, std::chrono::milliseconds(m_delay), [&] () { + return static_cast<bool>(!m_alive); + }); + } - inline void runOne() - { - wait(); - call(); - } + inline void runOne() + { + wait(); + call(); + } - inline void runForever() - { - while (m_alive) { - wait(); - call(); - } - } + inline void runForever() + { + while (m_alive) { + wait(); + call(); + } + } public: - /** - * Constructor. - * - * \param type the type of timer - * \param delay the delay in milliseconds - */ - inline Timer(Type type, std::uint32_t delay) noexcept - : m_type(type) - , m_delay(delay) - { - } + /** + * Constructor. + * + * \param type the type of timer + * \param delay the delay in milliseconds + */ + inline Timer(Type type, std::uint32_t delay) noexcept + : m_type(type) + , m_delay(delay) + { + } - /** - * Stop the timer. - */ - inline ~Timer() - { - stop(); - } + /** + * Stop the timer. + */ + inline ~Timer() + { + stop(); + } - /** - * Get the current handler. - * - * \return the handler - */ - inline const std::function<void ()> &handler() const noexcept - { - return m_handler; - } + /** + * Get the current handler. + * + * \return the handler + */ + inline const std::function<void ()> &handler() const noexcept + { + return m_handler; + } - /** - * Overloaded function. - * - * \return the handler - */ - inline std::function<void ()> &handler() noexcept - { - return m_handler; - } + /** + * Overloaded function. + * + * \return the handler + */ + inline std::function<void ()> &handler() noexcept + { + return m_handler; + } - /** - * Set the handler. - * - * \pre !isActive() - * \param handler the handler - */ - inline void setHandler(std::function<void ()> handler) - { - assert(!m_thread.joinable()); + /** + * Set the handler. + * + * \pre !isActive() + * \param handler the handler + */ + inline void setHandler(std::function<void ()> handler) + { + assert(!m_thread.joinable()); - m_handler = std::move(handler); - } + m_handler = std::move(handler); + } - /** - * Tells if a pending thread is still active even if the execution has finished. - * - * \return true if active - */ - inline bool isActive() const noexcept - { - return m_thread.joinable(); - } + /** + * Tells if a pending thread is still active even if the execution has finished. + * + * \return true if active + */ + inline bool isActive() const noexcept + { + return m_thread.joinable(); + } - /** - * Start the timer. - * - * \pre the timer must not be running - */ - void start() - { - assert(!m_thread.joinable()); + /** + * Start the timer. + * + * \pre the timer must not be running + */ + void start() + { + assert(!m_thread.joinable()); - m_alive = true; + m_alive = true; - if (m_type == Single) - m_thread = std::thread(std::bind(&Timer::runOne, this)); - else - m_thread = std::thread(std::bind(&Timer::runForever, this)); - } + if (m_type == Single) + m_thread = std::thread(std::bind(&Timer::runOne, this)); + else + m_thread = std::thread(std::bind(&Timer::runForever, this)); + } - /** - * Stop the timer. - * - * Can be safely called multiple times. - */ - void stop() - { - if (m_thread.joinable()) { - m_alive = false; - m_condition.notify_one(); - m_thread.join(); - } - } + /** + * Stop the timer. + * + * Can be safely called multiple times. + */ + void stop() + { + if (m_thread.joinable()) { + m_alive = false; + m_condition.notify_one(); + m_thread.join(); + } + } }; -#endif // !TIMER_HPP \ No newline at end of file +#endif // !TIMER_HPP
--- a/modules/unicode/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -21,6 +21,6 @@ add_subdirectory(generator) code_define_module( - NAME unicode - SOURCES unicode.cpp unicode.hpp -) \ No newline at end of file + NAME unicode + SOURCES unicode.cpp unicode.hpp +)
--- a/modules/unicode/generator/cat/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/cat/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -18,16 +18,16 @@ add_executable(cat cat.cpp) set_target_properties( - cat - PROPERTIES - RUNTIME_OUTPUT_NAME cat - RUNTIME_OUTPUT_NAME_DEBUG cat - RUNTIME_OUTPUT_NAME_RELEASE cat - RUNTIME_OUTPUT_NAME_RELWITHDEBINFO cat - RUNTIME_OUTPUT_NAME_MINISIZEREL cat - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR} - RUNTIME_OUTPUT_DIRECTORY_MINISIZEREL ${CMAKE_BINARY_DIR} + cat + PROPERTIES + RUNTIME_OUTPUT_NAME cat + RUNTIME_OUTPUT_NAME_DEBUG cat + RUNTIME_OUTPUT_NAME_RELEASE cat + RUNTIME_OUTPUT_NAME_RELWITHDEBINFO cat + RUNTIME_OUTPUT_NAME_MINISIZEREL cat + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY_MINISIZEREL ${CMAKE_BINARY_DIR} ) \ No newline at end of file
--- a/modules/unicode/generator/cat/cat.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/cat/cat.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -24,23 +24,23 @@ int main(int argc, char **argv) { - -- argc; - ++ argv; + -- argc; + ++ argv; - if (argc < 2) { - std::cerr << "usage: cat output file1 [files...]" << std::endl; - return 1; - } + if (argc < 2) { + std::cerr << "usage: cat output file1 [files...]" << std::endl; + return 1; + } - std::ofstream output(argv[0]); + std::ofstream output(argv[0]); - for (int i = 1; i < argc; ++i) { - std::ifstream input(argv[i]); - std::string line; + for (int i = 1; i < argc; ++i) { + std::ifstream input(argv[i]); + std::string line; - while (std::getline(input, line)) - output << line << "\n"; - } + while (std::getline(input, line)) + output << line << "\n"; + } - return 0; + return 0; }
--- a/modules/unicode/generator/make-unicode/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/make-unicode/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -17,27 +17,27 @@ # add_executable( - generator - src/mkunicode.c - src/utf.h - src/utfdef.h + generator + src/mkunicode.c + src/utf.h + src/utfdef.h ) add_custom_target( - generate-unicode - COMMAND - $<TARGET_FILE:generator> ${unicode_BINARY_DIR}/unicode-tmp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UnicodeData.txt - COMMAND - $<TARGET_FILE:cat> - ${unicode_SOURCE_DIR}/unicode.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/unicode-before.cpp - ${unicode_BINARY_DIR}/unicode-tmp.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/unicode-after.cpp - COMMAND - ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/unicode.hpp ${unicode_SOURCE_DIR} - COMMAND - ${CMAKE_COMMAND} -E remove ${unicode_BINARY_DIR}/unicode-tmp.cpp - DEPENDS - generator - ${CMAKE_BINARY_DIR}/cat + generate-unicode + COMMAND + $<TARGET_FILE:generator> ${unicode_BINARY_DIR}/unicode-tmp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UnicodeData.txt + COMMAND + $<TARGET_FILE:cat> + ${unicode_SOURCE_DIR}/unicode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/unicode-before.cpp + ${unicode_BINARY_DIR}/unicode-tmp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/unicode-after.cpp + COMMAND + ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/unicode.hpp ${unicode_SOURCE_DIR} + COMMAND + ${CMAKE_COMMAND} -E remove ${unicode_BINARY_DIR}/unicode-tmp.cpp + DEPENDS + generator + ${CMAKE_BINARY_DIR}/cat )
--- a/modules/unicode/generator/make-unicode/src/mkunicode.c Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/make-unicode/src/mkunicode.c Wed Jun 15 13:13:26 2016 +0200 @@ -33,12 +33,12 @@ * * isalpharune(c) is true iff c is a "letter" category * isupperrune(c) is true iff c is the target of toupperrune, - * or is in the uppercase letter category + * or is in the uppercase letter category * similarly for islowerrune and istitlerune. * isspacerune is true for space category chars, "C" locale white space chars, - * and two additions: - * 0085 "next line" control char - * feff] "zero-width non-break space" + * and two additions: + * 0085 "next line" control char + * feff] "zero-width non-break space" * isdigitrune is true iff c is a numeric-digit category. */ @@ -53,203 +53,203 @@ #define nelem(x) (sizeof(x)/sizeof((x)[0])) enum { - /* - * fields in the unicode data file - */ - FIELD_CODE, - FIELD_NAME, - FIELD_CATEGORY, - FIELD_COMBINING, - FIELD_BIDIR, - FIELD_DECOMP, - FIELD_DECIMAL_DIG, - FIELD_DIG, - FIELD_NUMERIC_VAL, - FIELD_MIRRORED, - FIELD_UNICODE_1_NAME, - FIELD_COMMENT, - FIELD_UPPER, - FIELD_LOWER, - FIELD_TITLE, - NFIELDS, + /* + * fields in the unicode data file + */ + FIELD_CODE, + FIELD_NAME, + FIELD_CATEGORY, + FIELD_COMBINING, + FIELD_BIDIR, + FIELD_DECOMP, + FIELD_DECIMAL_DIG, + FIELD_DIG, + FIELD_NUMERIC_VAL, + FIELD_MIRRORED, + FIELD_UNICODE_1_NAME, + FIELD_COMMENT, + FIELD_UPPER, + FIELD_LOWER, + FIELD_TITLE, + NFIELDS, - MAX_LINE = 1024, + MAX_LINE = 1024, - TO_OFFSET = 1 << 20, + TO_OFFSET = 1 << 20, - NRUNES = 1 << 21, + NRUNES = 1 << 21, }; -#define TO_DELTA(xmapped,x) (TO_OFFSET + (xmapped) - (x)) +#define TO_DELTA(xmapped,x) (TO_OFFSET + (xmapped) - (x)) -static FILE *out; -static char myisspace[NRUNES]; -static char myisalpha[NRUNES]; -static char myisdigit[NRUNES]; -static char myisupper[NRUNES]; -static char myislower[NRUNES]; -static char myistitle[NRUNES]; +static FILE *out; +static char myisspace[NRUNES]; +static char myisalpha[NRUNES]; +static char myisdigit[NRUNES]; +static char myisupper[NRUNES]; +static char myislower[NRUNES]; +static char myistitle[NRUNES]; -static int mytoupper[NRUNES]; -static int mytolower[NRUNES]; -static int mytotitle[NRUNES]; +static int mytoupper[NRUNES]; +static int mytolower[NRUNES]; +static int mytotitle[NRUNES]; -static void check(void); -static void mktables(char *src, int usepairs); -static void fatal(const char *fmt, ...); -static int mygetfields(char **fields, int nfields, char *str, const char *delim); -static int getunicodeline(FILE *in, char **fields, char *buf); -static int getcode(char *s); +static void check(void); +static void mktables(char *src, int usepairs); +static void fatal(const char *fmt, ...); +static int mygetfields(char **fields, int nfields, char *str, const char *delim); +static int getunicodeline(FILE *in, char **fields, char *buf); +static int getcode(char *s); static void usage(void) { - fprintf(stderr, "usage: mktables [-cp] output UnicodeData.txt\n"); - exit(1); + fprintf(stderr, "usage: mktables [-cp] output UnicodeData.txt\n"); + exit(1); } int main(int argc, char *argv[]) { - FILE *in; - char buf[MAX_LINE], buf2[MAX_LINE]; - char *fields[NFIELDS + 1], *fields2[NFIELDS + 1]; - char *p; - int i, code, last, usepairs; + FILE *in; + char buf[MAX_LINE], buf2[MAX_LINE]; + char *fields[NFIELDS + 1], *fields2[NFIELDS + 1]; + char *p; + int i, code, last, usepairs; - usepairs = 0; + usepairs = 0; - --argc; - ++argv; + --argc; + ++argv; - if (argc != 2){ - usage(); - } + if (argc != 2){ + usage(); + } - out = fopen(argv[0], "w"); - if (out == NULL) { - fatal("can't open %s", argv[0]); - } + out = fopen(argv[0], "w"); + if (out == NULL) { + fatal("can't open %s", argv[0]); + } - in = fopen(argv[1], "r"); + in = fopen(argv[1], "r"); - if (in == NULL) { - fatal("can't open %s", argv[1]); - } + if (in == NULL) { + fatal("can't open %s", argv[1]); + } - for(i = 0; i < NRUNES; i++){ - mytoupper[i] = i; - mytolower[i] = i; - mytotitle[i] = i; - } + for(i = 0; i < NRUNES; i++){ + mytoupper[i] = i; + mytolower[i] = i; + mytotitle[i] = i; + } - /* - * make sure isspace has all of the "C" locale whitespace chars - */ - myisspace['\t'] = 1; - myisspace['\n'] = 1; - myisspace['\r'] = 1; - myisspace['\f'] = 1; - myisspace['\v'] = 1; + /* + * make sure isspace has all of the "C" locale whitespace chars + */ + myisspace['\t'] = 1; + myisspace['\n'] = 1; + myisspace['\r'] = 1; + myisspace['\f'] = 1; + myisspace['\v'] = 1; - /* - * a couple of other exceptions - */ - myisspace[0x85] = 1; /* control char, "next line" */ - myisspace[0xfeff] = 1; /* zero-width non-break space */ + /* + * a couple of other exceptions + */ + myisspace[0x85] = 1; /* control char, "next line" */ + myisspace[0xfeff] = 1; /* zero-width non-break space */ - last = -1; - while(getunicodeline(in, fields, buf)){ - code = getcode(fields[FIELD_CODE]); - if (code >= NRUNES) - fatal("code-point value too big: %x", code); - if(code <= last) - fatal("bad code sequence: %x then %x", last, code); - last = code; + last = -1; + while(getunicodeline(in, fields, buf)){ + code = getcode(fields[FIELD_CODE]); + if (code >= NRUNES) + fatal("code-point value too big: %x", code); + if(code <= last) + fatal("bad code sequence: %x then %x", last, code); + last = code; - /* - * check for ranges - */ - p = fields[FIELD_CATEGORY]; - if(strstr(fields[FIELD_NAME], ", First>") != NULL){ - if(!getunicodeline(in, fields2, buf2)) - fatal("range start at eof"); - if (strstr(fields2[FIELD_NAME], ", Last>") == NULL) - fatal("range start not followed by range end"); - last = getcode(fields2[FIELD_CODE]); - if(last <= code) - fatal("range out of sequence: %x then %x", code, last); - if(strcmp(p, fields2[FIELD_CATEGORY]) != 0) - fatal("range with mismatched category"); - } + /* + * check for ranges + */ + p = fields[FIELD_CATEGORY]; + if(strstr(fields[FIELD_NAME], ", First>") != NULL){ + if(!getunicodeline(in, fields2, buf2)) + fatal("range start at eof"); + if (strstr(fields2[FIELD_NAME], ", Last>") == NULL) + fatal("range start not followed by range end"); + last = getcode(fields2[FIELD_CODE]); + if(last <= code) + fatal("range out of sequence: %x then %x", code, last); + if(strcmp(p, fields2[FIELD_CATEGORY]) != 0) + fatal("range with mismatched category"); + } - /* - * set properties and conversions - */ - for (; code <= last; code++){ - if(p[0] == 'L') - myisalpha[code] = 1; - if(p[0] == 'Z') - myisspace[code] = 1; + /* + * set properties and conversions + */ + for (; code <= last; code++){ + if(p[0] == 'L') + myisalpha[code] = 1; + if(p[0] == 'Z') + myisspace[code] = 1; - if(strcmp(p, "Lu") == 0) - myisupper[code] = 1; - if(strcmp(p, "Ll") == 0) - myislower[code] = 1; + if(strcmp(p, "Lu") == 0) + myisupper[code] = 1; + if(strcmp(p, "Ll") == 0) + myislower[code] = 1; - if(strcmp(p, "Lt") == 0) - myistitle[code] = 1; + if(strcmp(p, "Lt") == 0) + myistitle[code] = 1; - if(strcmp(p, "Nd") == 0) - myisdigit[code] = 1; + if(strcmp(p, "Nd") == 0) + myisdigit[code] = 1; - /* - * when finding conversions, also need to mark - * upper/lower case, since some chars, like - * "III" (0x2162), aren't defined as letters but have a - * lower case mapping ("iii" (0x2172)). - */ - if(fields[FIELD_UPPER][0] != '\0'){ - mytoupper[code] = getcode(fields[FIELD_UPPER]); - } - if(fields[FIELD_LOWER][0] != '\0'){ - mytolower[code] = getcode(fields[FIELD_LOWER]); - } - if(fields[FIELD_TITLE][0] != '\0'){ - mytotitle[code] = getcode(fields[FIELD_TITLE]); - } - } - } + /* + * when finding conversions, also need to mark + * upper/lower case, since some chars, like + * "III" (0x2162), aren't defined as letters but have a + * lower case mapping ("iii" (0x2172)). + */ + if(fields[FIELD_UPPER][0] != '\0'){ + mytoupper[code] = getcode(fields[FIELD_UPPER]); + } + if(fields[FIELD_LOWER][0] != '\0'){ + mytolower[code] = getcode(fields[FIELD_LOWER]); + } + if(fields[FIELD_TITLE][0] != '\0'){ + mytotitle[code] = getcode(fields[FIELD_TITLE]); + } + } + } - fclose(in); + fclose(in); - /* - * check for codes with no totitle mapping but a toupper mapping. - * these appear in UnicodeData-2.0.14.txt, but are almost certainly - * erroneous. - */ - for(i = 0; i < NRUNES; i++){ - if(mytotitle[i] == i - && mytoupper[i] != i - && !myistitle[i]) - fprintf(stderr, "warning: code=%.4x not istitle, totitle is same, toupper=%.4x\n", i, mytoupper[i]); - } + /* + * check for codes with no totitle mapping but a toupper mapping. + * these appear in UnicodeData-2.0.14.txt, but are almost certainly + * erroneous. + */ + for(i = 0; i < NRUNES; i++){ + if(mytotitle[i] == i + && mytoupper[i] != i + && !myistitle[i]) + fprintf(stderr, "warning: code=%.4x not istitle, totitle is same, toupper=%.4x\n", i, mytoupper[i]); + } - /* - * make sure isupper[c] is true if for some x toupper[x] == c - * ditto for islower and istitle - */ - for(i = 0; i < NRUNES; i++) { - if(mytoupper[i] != i) - myisupper[mytoupper[i]] = 1; - if(mytolower[i] != i) - myislower[mytolower[i]] = 1; - if(mytotitle[i] != i) - myistitle[mytotitle[i]] = 1; - } + /* + * make sure isupper[c] is true if for some x toupper[x] == c + * ditto for islower and istitle + */ + for(i = 0; i < NRUNES; i++) { + if(mytoupper[i] != i) + myisupper[mytoupper[i]] = 1; + if(mytolower[i] != i) + myislower[mytolower[i]] = 1; + if(mytotitle[i] != i) + myistitle[mytotitle[i]] = 1; + } - mktables(argv[0], usepairs); - exit(0); + mktables(argv[0], usepairs); + exit(0); } /* @@ -259,42 +259,42 @@ static int mkisrange(const char* label, char* prop, int force) { - int start, stop, some; + int start, stop, some; - /* - * first, the ranges - */ - some = 0; - for(start = 0; start < NRUNES; ) { - if(!prop[start]){ - start++; - continue; - } + /* + * first, the ranges + */ + some = 0; + for(start = 0; start < NRUNES; ) { + if(!prop[start]){ + start++; + continue; + } - for(stop = start + 1; stop < NRUNES; stop++){ - if(!prop[stop]){ - break; - } - prop[stop] = 0; - } - if(force || stop != start + 1){ - if(!some){ - fprintf(out, "namespace {\n\n"); - fprintf(out, "const char32_t is%sr[] = {\n", label); - some = 1; - } - prop[start] = 0; - fprintf(out, "\t0x%.4x, 0x%.4x,\n", start, stop - 1); - } + for(stop = start + 1; stop < NRUNES; stop++){ + if(!prop[stop]){ + break; + } + prop[stop] = 0; + } + if(force || stop != start + 1){ + if(!some){ + fprintf(out, "namespace {\n\n"); + fprintf(out, "const char32_t is%sr[] = {\n", label); + some = 1; + } + prop[start] = 0; + fprintf(out, " 0x%.4x, 0x%.4x,\n", start, stop - 1); + } - start = stop; - } - if(some) { - fprintf(out, "};\n\n"); - fprintf(out, "} // !namespace\n\n"); - } + start = stop; + } + if(some) { + fprintf(out, "};\n\n"); + fprintf(out, "} // !namespace\n\n"); + } - return some; + return some; } /* @@ -304,38 +304,38 @@ static int mkispair(const char *label, char *prop) { - int start, stop, some; + int start, stop, some; - some = 0; - for(start = 0; start + 2 < NRUNES; ) { - if(!prop[start]){ - start++; - continue; - } + some = 0; + for(start = 0; start + 2 < NRUNES; ) { + if(!prop[start]){ + start++; + continue; + } - for(stop = start + 2; stop < NRUNES; stop += 2){ - if(!prop[stop]){ - break; - } - prop[stop] = 0; - } - if(stop != start + 2){ - if(!some){ - fprintf(out, "namespace {\n\n"); - fprintf(out, "const char32_t is%sp[] = {\n", label); - some = 1; - } - prop[start] = 0; - fprintf(out, "\t0x%.4x, 0x%.4x,\n", start, stop - 2); - } + for(stop = start + 2; stop < NRUNES; stop += 2){ + if(!prop[stop]){ + break; + } + prop[stop] = 0; + } + if(stop != start + 2){ + if(!some){ + fprintf(out, "namespace {\n\n"); + fprintf(out, "const char32_t is%sp[] = {\n", label); + some = 1; + } + prop[start] = 0; + fprintf(out, " 0x%.4x, 0x%.4x,\n", start, stop - 2); + } - start = stop; - } - if(some) { - fprintf(out, "};\n\n"); - fprintf(out, "} // !namespace\n\n"); - } - return some; + start = stop; + } + if(some) { + fprintf(out, "};\n\n"); + fprintf(out, "} // !namespace\n\n"); + } + return some; } /* @@ -344,27 +344,27 @@ static int mkissingle(const char *label, char *prop) { - int start, some; + int start, some; - some = 0; - for(start = 0; start < NRUNES; start++) { - if(!prop[start]){ - continue; - } + some = 0; + for(start = 0; start < NRUNES; start++) { + if(!prop[start]){ + continue; + } - if(!some){ - fprintf(out, "namespace {\n\n"); - fprintf(out, "const char32_t is%ss[] = {\n", label); - some = 1; - } - prop[start] = 0; - fprintf(out, "\t0x%.4x,\n", start); - } - if(some) { - fprintf(out, "};\n\n"); - fprintf(out, "} // !namespace\n\n"); - } - return some; + if(!some){ + fprintf(out, "namespace {\n\n"); + fprintf(out, "const char32_t is%ss[] = {\n", label); + some = 1; + } + prop[start] = 0; + fprintf(out, " 0x%.4x,\n", start); + } + if(some) { + fprintf(out, "};\n\n"); + fprintf(out, "} // !namespace\n\n"); + } + return some; } /* @@ -373,48 +373,48 @@ static void mkis(const char* label, char* prop, int usepairs) { - int isr, isp, iss; + int isr, isp, iss; - isr = mkisrange(label, prop, 0); - isp = 0; - if(usepairs) - isp = mkispair(label, prop); - iss = mkissingle(label, prop); + isr = mkisrange(label, prop, 0); + isp = 0; + if(usepairs) + isp = mkispair(label, prop); + iss = mkissingle(label, prop); - fprintf(out, - "bool is%s(char32_t c) noexcept\n" - "{\n" - " const char32_t *p;\n" - "\n", - label); + fprintf(out, + "bool is%s(char32_t c) noexcept\n" + "{\n" + " const char32_t *p;\n" + "\n", + label); - if(isr) - fprintf(out, - " p = rbsearch(c, is%sr, nelem (is%sr)/2, 2);\n\n" - " if (p && c >= p[0] && c <= p[1])\n" - " return true;\n", - label, label); + if(isr) + fprintf(out, + " p = rbsearch(c, is%sr, nelem (is%sr)/2, 2);\n\n" + " if (p && c >= p[0] && c <= p[1])\n" + " return true;\n", + label, label); - if(isp) - fprintf(out, - "\n p = rbsearch(c, is%sp, nelem (is%sp)/2, 2);\n\n" - " if (p && c >= p[0] && c <= p[1] && !((c - p[0]) & 1))\n" - " return true;\n", - label, label); + if(isp) + fprintf(out, + "\n p = rbsearch(c, is%sp, nelem (is%sp)/2, 2);\n\n" + " if (p && c >= p[0] && c <= p[1] && !((c - p[0]) & 1))\n" + " return true;\n", + label, label); - if(iss) - fprintf(out, - "\n p = rbsearch(c, is%ss, nelem (is%ss), 1);\n\n" - " if (p && c == p[0])\n" - " return true;\n", - label, label); + if(iss) + fprintf(out, + "\n p = rbsearch(c, is%ss, nelem (is%ss), 1);\n\n" + " if (p && c == p[0])\n" + " return true;\n", + label, label); - fprintf(out, - "\n return false;\n" - "}\n" - "\n" - ); + fprintf(out, + "\n return false;\n" + "}\n" + "\n" + ); } /* @@ -424,42 +424,42 @@ static int mktorange(const char* label, int* map, int force) { - int start, stop, delta, some; + int start, stop, delta, some; - some = 0; - for(start = 0; start < NRUNES; ) { - if(map[start] == start){ - start++; - continue; - } + some = 0; + for(start = 0; start < NRUNES; ) { + if(map[start] == start){ + start++; + continue; + } - delta = TO_DELTA(map[start], start); - if(delta != (Rune)delta) - fatal("bad map delta %d", delta); - for(stop = start + 1; stop < NRUNES; stop++){ - if(TO_DELTA(map[stop], stop) != delta){ - break; - } - map[stop] = stop; - } - if(stop != start + 1){ - if(!some){ - fprintf(out, "namespace {\n\n"); - fprintf(out, "const char32_t to%sr[] = {\n", label); - some = 1; - } - map[start] = start; - fprintf(out, "\t0x%.4x, 0x%.4x, %d,\n", start, stop - 1, delta); - } + delta = TO_DELTA(map[start], start); + if(delta != (Rune)delta) + fatal("bad map delta %d", delta); + for(stop = start + 1; stop < NRUNES; stop++){ + if(TO_DELTA(map[stop], stop) != delta){ + break; + } + map[stop] = stop; + } + if(stop != start + 1){ + if(!some){ + fprintf(out, "namespace {\n\n"); + fprintf(out, "const char32_t to%sr[] = {\n", label); + some = 1; + } + map[start] = start; + fprintf(out, " 0x%.4x, 0x%.4x, %d,\n", start, stop - 1, delta); + } - start = stop; - } - if(some) { - fprintf(out, "};\n\n"); - fprintf(out, "} // !namespace\n\n"); - } + start = stop; + } + if(some) { + fprintf(out, "};\n\n"); + fprintf(out, "} // !namespace\n\n"); + } - return some; + return some; } /* @@ -469,42 +469,42 @@ static int mktopair(const char* label, int* map) { - int start, stop, delta, some; + int start, stop, delta, some; - some = 0; - for(start = 0; start + 2 < NRUNES; ) { - if(map[start] == start){ - start++; - continue; - } + some = 0; + for(start = 0; start + 2 < NRUNES; ) { + if(map[start] == start){ + start++; + continue; + } - delta = TO_DELTA(map[start], start); - if(delta != (Rune)delta) - fatal("bad map delta %d", delta); - for(stop = start + 2; stop < NRUNES; stop += 2){ - if(TO_DELTA(map[stop], stop) != delta){ - break; - } - map[stop] = stop; - } - if(stop != start + 2){ - if(!some){ - fprintf(out, "namespace {\n\n"); - fprintf(out, "const char32_t to%sp[] = {\n", label); - some = 1; - } - map[start] = start; - fprintf(out, "\t0x%.4x, 0x%.4x, %d,\n", start, stop - 2, delta); - } + delta = TO_DELTA(map[start], start); + if(delta != (Rune)delta) + fatal("bad map delta %d", delta); + for(stop = start + 2; stop < NRUNES; stop += 2){ + if(TO_DELTA(map[stop], stop) != delta){ + break; + } + map[stop] = stop; + } + if(stop != start + 2){ + if(!some){ + fprintf(out, "namespace {\n\n"); + fprintf(out, "const char32_t to%sp[] = {\n", label); + some = 1; + } + map[start] = start; + fprintf(out, " 0x%.4x, 0x%.4x, %d,\n", start, stop - 2, delta); + } - start = stop; - } - if(some) { - fprintf(out, "};\n\n"); - fprintf(out, "} // !namespace\n\n"); - } + start = stop; + } + if(some) { + fprintf(out, "};\n\n"); + fprintf(out, "} // !namespace\n\n"); + } - return some; + return some; } /* @@ -513,31 +513,31 @@ static int mktosingle(const char* label, int* map) { - int start, delta, some; + int start, delta, some; - some = 0; - for(start = 0; start < NRUNES; start++) { - if(map[start] == start){ - continue; - } + some = 0; + for(start = 0; start < NRUNES; start++) { + if(map[start] == start){ + continue; + } - delta = TO_DELTA(map[start], start); - if(delta != (Rune)delta) - fatal("bad map delta %d", delta); - if(!some){ - fprintf(out, "namespace {\n\n"); - fprintf(out, "const char32_t to%ss[] = {\n", label); - some = 1; - } - map[start] = start; - fprintf(out, "\t0x%.4x, %d,\n", start, delta); - } - if(some) { - fprintf(out, "};\n\n"); - fprintf(out, "} // !namespace\n\n"); - } + delta = TO_DELTA(map[start], start); + if(delta != (Rune)delta) + fatal("bad map delta %d", delta); + if(!some){ + fprintf(out, "namespace {\n\n"); + fprintf(out, "const char32_t to%ss[] = {\n", label); + some = 1; + } + map[start] = start; + fprintf(out, " 0x%.4x, %d,\n", start, delta); + } + if(some) { + fprintf(out, "};\n\n"); + fprintf(out, "} // !namespace\n\n"); + } - return some; + return some; } /* @@ -546,66 +546,66 @@ static void mkto(const char* label, int* map, int usepairs) { - int tor, top, tos; + int tor, top, tos; - tor = mktorange(label, map, 0); - top = 0; - if(usepairs) - top = mktopair(label, map); - tos = mktosingle(label, map); + tor = mktorange(label, map, 0); + top = 0; + if(usepairs) + top = mktopair(label, map); + tos = mktosingle(label, map); - fprintf(out, - "char32_t to%s(char32_t c) noexcept\n" - "{\n" - " const char32_t *p;\n" - "\n", - label); + fprintf(out, + "char32_t to%s(char32_t c) noexcept\n" + "{\n" + " const char32_t *p;\n" + "\n", + label); - if(tor) - fprintf(out, - " p = rbsearch(c, to%sr, nelem (to%sr)/3, 3);\n\n" - " if (p && c >= p[0] && c <= p[1])\n" - " return c + p[2] - %d;\n", - label, label, TO_OFFSET); + if(tor) + fprintf(out, + " p = rbsearch(c, to%sr, nelem (to%sr)/3, 3);\n\n" + " if (p && c >= p[0] && c <= p[1])\n" + " return c + p[2] - %d;\n", + label, label, TO_OFFSET); - if(top) - fprintf(out, - "\n p = rbsearch(c, to%sp, nelem (to%sp)/3, 3);\n\n" - " if (p && c >= p[0] && c <= p[1] && !((c - p[0]) & 1))\n" - " return c + p[2] - %d;\n", - label, label, TO_OFFSET); + if(top) + fprintf(out, + "\n p = rbsearch(c, to%sp, nelem (to%sp)/3, 3);\n\n" + " if (p && c >= p[0] && c <= p[1] && !((c - p[0]) & 1))\n" + " return c + p[2] - %d;\n", + label, label, TO_OFFSET); - if(tos) - fprintf(out, - "\n p = rbsearch(c, to%ss, nelem (to%ss)/2, 2);\n\n" - " if (p && c == p[0])\n" - " return c + p[1] - %d;\n\n", - label, label, TO_OFFSET); + if(tos) + fprintf(out, + "\n p = rbsearch(c, to%ss, nelem (to%ss)/2, 2);\n\n" + " if (p && c == p[0])\n" + " return c + p[1] - %d;\n\n", + label, label, TO_OFFSET); - fprintf(out, - " return c;\n" - "}\n" - "\n" - ); + fprintf(out, + " return c;\n" + "}\n" + "\n" + ); } // Make only range tables and a function for is<label>rune. static void mkisronly(const char* label, char* prop) { - mkisrange(label, prop, 1); - fprintf(out, - "bool is%s(char32_t c) noexcept\n" - "{\n" - " const char32_t *p;\n" - "\n" - " p = rbsearch(c, is%sr, nelem (is%sr)/2, 2);\n\n" - " if (p && c >= p[0] && c <= p[1])\n" - " return true;\n\n" - " return false;\n" - "}\n" - "\n", - label, label, label); + mkisrange(label, prop, 1); + fprintf(out, + "bool is%s(char32_t c) noexcept\n" + "{\n" + " const char32_t *p;\n" + "\n" + " p = rbsearch(c, is%sr, nelem (is%sr)/2, 2);\n\n" + " if (p && c >= p[0] && c <= p[1])\n" + " return true;\n\n" + " return false;\n" + "}\n" + "\n", + label, label, label); } /* @@ -615,122 +615,122 @@ static void mktables(char *src, int usepairs) { - /* Add nelem macro */ - fprintf(out, - "#define nelem(x) (sizeof (x) / sizeof ((x)[0]))\n\n" - ); + /* Add nelem macro */ + fprintf(out, + "#define nelem(x) (sizeof (x) / sizeof ((x)[0]))\n\n" + ); - /* Add the rbsearch function */ - fprintf(out, - "namespace {\n\n" - "const char32_t *rbsearch(char32_t c, const char32_t *t, int n, int ne) noexcept\n" - "{\n" - " const char32_t *p;\n" - " int m;\n\n" - " while (n > 1) {\n" - " m = n >> 1;\n" - " p = t + m * ne;\n\n" - " if (c >= p[0]) {\n" - " t = p;\n" - " n = n - m;\n" - " } else\n" - " n = m;\n" - " }\n\n" - " if (n && c >= t[0])\n" - " return t;\n\n" - " return nullptr;\n" - "}\n\n" - "} // !namespace\n\n" - ); + /* Add the rbsearch function */ + fprintf(out, + "namespace {\n\n" + "const char32_t *rbsearch(char32_t c, const char32_t *t, int n, int ne) noexcept\n" + "{\n" + " const char32_t *p;\n" + " int m;\n\n" + " while (n > 1) {\n" + " m = n >> 1;\n" + " p = t + m * ne;\n\n" + " if (c >= p[0]) {\n" + " t = p;\n" + " n = n - m;\n" + " } else\n" + " n = m;\n" + " }\n\n" + " if (n && c >= t[0])\n" + " return t;\n\n" + " return nullptr;\n" + "}\n\n" + "} // !namespace\n\n" + ); - /* - * we special case the space and digit tables, since they are assumed - * to be small with several ranges. - */ - mkisronly("space", myisspace); - mkisronly("digit", myisdigit); + /* + * we special case the space and digit tables, since they are assumed + * to be small with several ranges. + */ + mkisronly("space", myisspace); + mkisronly("digit", myisdigit); - mkis("alpha", myisalpha, 0); - mkis("upper", myisupper, usepairs); - mkis("lower", myislower, usepairs); - mkis("title", myistitle, usepairs); + mkis("alpha", myisalpha, 0); + mkis("upper", myisupper, usepairs); + mkis("lower", myislower, usepairs); + mkis("title", myistitle, usepairs); - mkto("upper", mytoupper, usepairs); - mkto("lower", mytolower, usepairs); - mkto("title", mytotitle, usepairs); + mkto("upper", mytoupper, usepairs); + mkto("lower", mytolower, usepairs); + mkto("title", mytotitle, usepairs); } static int mygetfields(char **fields, int nfields, char *str, const char *delim) { - int nf; + int nf; - fields[0] = str; - nf = 1; - if(nf >= nfields) - return nf; + fields[0] = str; + nf = 1; + if(nf >= nfields) + return nf; - for(; *str; str++){ - if(strchr(delim, *str) != NULL){ - *str = '\0'; - fields[nf++] = str + 1; - if(nf >= nfields) - break; - } - } - return nf; + for(; *str; str++){ + if(strchr(delim, *str) != NULL){ + *str = '\0'; + fields[nf++] = str + 1; + if(nf >= nfields) + break; + } + } + return nf; } static int getunicodeline(FILE *in, char **fields, char *buf) { - char *p; + char *p; - if(fgets(buf, MAX_LINE, in) == NULL) - return 0; + if(fgets(buf, MAX_LINE, in) == NULL) + return 0; - p = strchr(buf, '\n'); - if (p == NULL) - fatal("line too long"); - *p = '\0'; + p = strchr(buf, '\n'); + if (p == NULL) + fatal("line too long"); + *p = '\0'; - if (mygetfields(fields, NFIELDS + 1, buf, ";") != NFIELDS) - fatal("bad number of fields"); + if (mygetfields(fields, NFIELDS + 1, buf, ";") != NFIELDS) + fatal("bad number of fields"); - return 1; + return 1; } static int getcode(char *s) { - int i, code; + int i, code; - code = 0; - i = 0; - /* Parse a hex number */ - while(s[i]) { - code <<= 4; - if(s[i] >= '0' && s[i] <= '9') - code += s[i] - '0'; - else if(s[i] >= 'A' && s[i] <= 'F') - code += s[i] - 'A' + 10; - else - fatal("bad code char '%c'", s[i]); - i++; - } - return code; + code = 0; + i = 0; + /* Parse a hex number */ + while(s[i]) { + code <<= 4; + if(s[i] >= '0' && s[i] <= '9') + code += s[i] - '0'; + else if(s[i] >= 'A' && s[i] <= 'F') + code += s[i] - 'A' + 10; + else + fatal("bad code char '%c'", s[i]); + i++; + } + return code; } static void fatal(const char *fmt, ...) { - va_list arg; + va_list arg; - fprintf(stderr, "mkunicode: fatal error: "); - va_start(arg, fmt); - vfprintf(stderr, fmt, arg); - va_end(arg); - fprintf(stderr, "\n"); + fprintf(stderr, "mkunicode: fatal error: "); + va_start(arg, fmt); + vfprintf(stderr, fmt, arg); + va_end(arg); + fprintf(stderr, "\n"); - exit(1); + exit(1); }
--- a/modules/unicode/generator/make-unicode/src/utf.h Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/make-unicode/src/utf.h Wed Jun 15 13:13:26 2016 +0200 @@ -16,18 +16,18 @@ #ifndef _UTFH_ #define _UTFH_ 1 -typedef unsigned int Rune; /* Code-point values in Unicode 4.0 are 21 bits wide.*/ +typedef unsigned int Rune; /* Code-point values in Unicode 4.0 are 21 bits wide.*/ enum { - UTFmax = 4, /* maximum bytes per rune */ - Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */ - Runeself = 0x80, /* rune and UTF sequences are the same (<) */ - Runeerror = 0xFFFD, /* decoding error in UTF */ - Runemax = 0x10FFFF, /* maximum rune value */ + UTFmax = 4, /* maximum bytes per rune */ + Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */ + Runeself = 0x80, /* rune and UTF sequences are the same (<) */ + Runeerror = 0xFFFD, /* decoding error in UTF */ + Runemax = 0x10FFFF, /* maximum rune value */ }; -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -233,7 +233,7 @@ // isalpharune.3, and runestrcat.3. Some formatting changes were also made // to conform to Google style. /JRM 11/11/05) -#ifdef __cplusplus +#ifdef __cplusplus } #endif
--- a/modules/unicode/generator/make-unicode/src/utfdef.h Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/make-unicode/src/utfdef.h Wed Jun 15 13:13:26 2016 +0200 @@ -19,9 +19,9 @@ #define vlong _utfvlong #define uvlong _utfuvlong -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned int uint; -typedef unsigned long ulong; +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; #define nelem(x) (sizeof(x)/sizeof((x)[0])) \ No newline at end of file
--- a/modules/unicode/generator/make-unicode/unicode-after.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/make-unicode/unicode-after.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -1,126 +1,126 @@ void encode(char32_t c, char res[5]) noexcept { - switch (nbytesPoint(c)) { - case 1: - res[0] = static_cast<char>(c); - res[1] = '\0'; - break; - case 2: - res[0] = 0xC0 | ((c >> 6) & 0x1F); - res[1] = 0x80 | (c & 0x3F); - res[2] = '\0'; - break; - case 3: - res[0] = 0xE0 | ((c >> 12) & 0xF ); - res[1] = 0x80 | ((c >> 6) & 0x3F); - res[2] = 0x80 | (c & 0x3F); - res[3] = '\0'; - break; - case 4: - res[0] = 0xF0 | ((c >> 18) & 0x7 ); - res[1] = 0x80 | ((c >> 12) & 0x3F); - res[2] = 0x80 | ((c >> 6) & 0x3F); - res[3] = 0x80 | (c & 0x3F); - res[4] = '\0'; - break; - default: - break; - } + switch (nbytesPoint(c)) { + case 1: + res[0] = static_cast<char>(c); + res[1] = '\0'; + break; + case 2: + res[0] = 0xC0 | ((c >> 6) & 0x1F); + res[1] = 0x80 | (c & 0x3F); + res[2] = '\0'; + break; + case 3: + res[0] = 0xE0 | ((c >> 12) & 0xF ); + res[1] = 0x80 | ((c >> 6) & 0x3F); + res[2] = 0x80 | (c & 0x3F); + res[3] = '\0'; + break; + case 4: + res[0] = 0xF0 | ((c >> 18) & 0x7 ); + res[1] = 0x80 | ((c >> 12) & 0x3F); + res[2] = 0x80 | ((c >> 6) & 0x3F); + res[3] = 0x80 | (c & 0x3F); + res[4] = '\0'; + break; + default: + break; + } } void decode(char32_t &c, const char *res) noexcept { - c = 0; + c = 0; - switch (nbytesUtf8(res[0])) { - case 1: - c = res[0]; - break; - case 2: - c = (res[0] & 0x1f) << 6; - c |= (res[1] & 0x3f); - break; - case 3: - c = (res[0] & 0x0f) << 12; - c |= (res[1] & 0x3f) << 6; - c |= (res[2] & 0x3f); - break; - case 4: - c = (res[0] & 0x07) << 16; - c |= (res[1] & 0x3f) << 12; - c |= (res[2] & 0x3f) << 6; - c |= (res[3] & 0x3f); - default: - break; - } + switch (nbytesUtf8(res[0])) { + case 1: + c = res[0]; + break; + case 2: + c = (res[0] & 0x1f) << 6; + c |= (res[1] & 0x3f); + break; + case 3: + c = (res[0] & 0x0f) << 12; + c |= (res[1] & 0x3f) << 6; + c |= (res[2] & 0x3f); + break; + case 4: + c = (res[0] & 0x07) << 16; + c |= (res[1] & 0x3f) << 12; + c |= (res[2] & 0x3f) << 6; + c |= (res[3] & 0x3f); + default: + break; + } } int nbytesUtf8(char c) noexcept { - if (static_cast<unsigned char>(c) <= 127) - return 1; - if ((c & 0xE0) == 0xC0) - return 2; - if ((c & 0xF0) == 0xE0) - return 3; - if ((c & 0xF8) == 0xF0) - return 4; + if (static_cast<unsigned char>(c) <= 127) + return 1; + if ((c & 0xE0) == 0xC0) + return 2; + if ((c & 0xF0) == 0xE0) + return 3; + if ((c & 0xF8) == 0xF0) + return 4; - return -1; + return -1; } int nbytesPoint(char32_t c) noexcept { - if (c <= 0x7F) - return 1; - if (c <= 0x7FF) - return 2; - if (c <= 0xFFFF) - return 3; - if (c <= 0x1FFFFF) - return 4; + if (c <= 0x7F) + return 1; + if (c <= 0x7FF) + return 2; + if (c <= 0xFFFF) + return 3; + if (c <= 0x1FFFFF) + return 4; - return -1; + return -1; } unsigned length(const std::string &str) { - unsigned total = 0; + unsigned total = 0; - forEach(str, [&] (char32_t) { - ++ total; - }); + forEach(str, [&] (char32_t) { + ++ total; + }); - return total; + return total; } std::string toUtf8(const std::u32string &array) { - std::string res; + std::string res; - for (size_t i = 0; i < array.size(); ++i) { - char tmp[5]; - int size = nbytesPoint(array[i]); + for (size_t i = 0; i < array.size(); ++i) { + char tmp[5]; + int size = nbytesPoint(array[i]); - if (size < 0) - throw std::invalid_argument("invalid sequence"); + if (size < 0) + throw std::invalid_argument("invalid sequence"); - encode(array[i], tmp); - res.insert(res.length(), tmp); - } + encode(array[i], tmp); + res.insert(res.length(), tmp); + } - return res; + return res; } std::u32string toUtf32(const std::string &str) { - std::u32string res; + std::u32string res; - forEach(str, [&] (char32_t code) { - res.push_back(code); - }); + forEach(str, [&] (char32_t code) { + res.push_back(code); + }); - return res; + return res; } } // !unicode
--- a/modules/unicode/generator/make-unicode/unicode.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/generator/make-unicode/unicode.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -83,7 +83,7 @@ * Iterate over all real characters in the UTF-8 string. * * The function must have the following signature: - * void f(char ch) + * void f(char ch) * * \param str the UTF-8 string * \param function the function callback @@ -92,18 +92,18 @@ template <typename Func> void forEach(const std::string &str, Func function) { - for (size_t i = 0; i < str.size(); ) { - char32_t point = 0; - int size = nbytesUtf8(str[i]); + for (size_t i = 0; i < str.size(); ) { + char32_t point = 0; + int size = nbytesUtf8(str[i]); - if (size < 0) - throw std::invalid_argument("invalid sequence"); + if (size < 0) + throw std::invalid_argument("invalid sequence"); - decode(point, str.data() + i); - function(point); + decode(point, str.data() + i); + function(point); - i += size; - } + i += size; + } } /** @@ -204,10 +204,10 @@ */ inline std::u32string toupper(std::u32string str) { - for (size_t i = 0; i < str.size(); ++i) - str[i] = toupper(str[i]); + for (size_t i = 0; i < str.size(); ++i) + str[i] = toupper(str[i]); - return str; + return str; } /** @@ -219,15 +219,15 @@ */ inline std::string toupper(const std::string &str) { - std::string result; - char buffer[5]; + std::string result; + char buffer[5]; - forEach(str, [&] (char32_t code) { - encode(toupper(code), buffer); - result += buffer; - }); + forEach(str, [&] (char32_t code) { + encode(toupper(code), buffer); + result += buffer; + }); - return result; + return result; } /** @@ -238,10 +238,10 @@ */ inline std::u32string tolower(std::u32string str) { - for (size_t i = 0; i < str.size(); ++i) - str[i] = tolower(str[i]); + for (size_t i = 0; i < str.size(); ++i) + str[i] = tolower(str[i]); - return str; + return str; } /** @@ -253,15 +253,15 @@ */ inline std::string tolower(const std::string &str) { - std::string result; - char buffer[5]; + std::string result; + char buffer[5]; - forEach(str, [&] (char32_t code) { - encode(tolower(code), buffer); - result += buffer; - }); + forEach(str, [&] (char32_t code) { + encode(tolower(code), buffer); + result += buffer; + }); - return result; + return result; } } // !unicode
--- a/modules/unicode/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -33,34 +33,34 @@ TEST(Conversion32to8, ascii) { - try { - std::u32string u32{'a', 'b', 'c'}; - std::string s = unicode::toUtf8(u32); + try { + std::u32string u32{'a', 'b', 'c'}; + std::string s = unicode::toUtf8(u32); - ASSERT_EQ("abc", s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("abc", s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Conversion32to8, valid) { - try { - std::u32string u32{'a', U'é', 'c', U'𠀀'}; - std::string s = unicode::toUtf8(u32); - std::string expected = u8"aéc𠀀"; + try { + std::u32string u32{'a', U'é', 'c', U'𠀀'}; + std::string s = unicode::toUtf8(u32); + std::string expected = u8"aéc𠀀"; - ASSERT_EQ(expected, s); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, s); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Conversion32to8, invalid) { - std::u32string u32{'a', 0xFFFFFFFF, 'c'}; + std::u32string u32{'a', 0xFFFFFFFF, 'c'}; - ASSERT_ANY_THROW(unicode::toUtf8(u32)); + ASSERT_ANY_THROW(unicode::toUtf8(u32)); } /* @@ -70,28 +70,28 @@ TEST(Conversion8to32, ascii) { - try { - std::string s{"abc"}; - std::u32string expected{'a', 'b', 'c'}; - std::u32string result = unicode::toUtf32(s); + try { + std::string s{"abc"}; + std::u32string expected{'a', 'b', 'c'}; + std::u32string result = unicode::toUtf32(s); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Conversion8to32, valid) { - try { - std::string s{u8"aéc𠀀"}; - std::u32string expected{'a', U'é', 'c', U'𠀀'}; - std::u32string result = unicode::toUtf32(s); + try { + std::string s{u8"aéc𠀀"}; + std::u32string expected{'a', U'é', 'c', U'𠀀'}; + std::u32string result = unicode::toUtf32(s); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -101,41 +101,41 @@ TEST(Toupper32, ascii) { - try { - std::u32string u32{'a', 'b', 'c'}; - std::u32string expected{'A', 'B', 'C'}; - std::u32string result = unicode::toupper(u32); + try { + std::u32string u32{'a', 'b', 'c'}; + std::u32string expected{'A', 'B', 'C'}; + std::u32string result = unicode::toupper(u32); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Toupper32, valid) { - try { - std::u32string u32{U'ä', U'ç', U'ë'}; - std::u32string expected{U'Ä', U'Ç', U'Ë'}; - std::u32string result = unicode::toupper(u32); + try { + std::u32string u32{U'ä', U'ç', U'ë'}; + std::u32string expected{U'Ä', U'Ç', U'Ë'}; + std::u32string result = unicode::toupper(u32); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Toupper32, invalid) { - try { - std::u32string u32{'a', 0xFFFFFFFF, 'b'}; - std::u32string expected{'A', 0xFFFFFFFF, 'B'}; - std::u32string result = unicode::toupper(u32); + try { + std::u32string u32{'a', 0xFFFFFFFF, 'b'}; + std::u32string expected{'A', 0xFFFFFFFF, 'B'}; + std::u32string result = unicode::toupper(u32); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -145,41 +145,41 @@ TEST(Tolower32, ascii) { - try { - std::u32string u32{'A', 'B', 'C'}; - std::u32string expected{'a', 'b', 'c'}; - std::u32string result = unicode::tolower(u32); + try { + std::u32string u32{'A', 'B', 'C'}; + std::u32string expected{'a', 'b', 'c'}; + std::u32string result = unicode::tolower(u32); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Tolower32, valid) { - try { - std::u32string u32{U'Ä', U'Ç', U'Ë'}; - std::u32string expected{U'ä', U'ç', U'ë'}; - std::u32string result = unicode::tolower(u32); + try { + std::u32string u32{U'Ä', U'Ç', U'Ë'}; + std::u32string expected{U'ä', U'ç', U'ë'}; + std::u32string result = unicode::tolower(u32); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Tolower32, invalid) { - try { - std::u32string u32{'A', 0xFFFFFFFF, 'B'}; - std::u32string expected{'a', 0xFFFFFFFF, 'b'}; - std::u32string result = unicode::tolower(u32); + try { + std::u32string u32{'A', 0xFFFFFFFF, 'B'}; + std::u32string expected{'a', 0xFFFFFFFF, 'b'}; + std::u32string result = unicode::tolower(u32); - ASSERT_EQ(expected, result); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(expected, result); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -189,33 +189,33 @@ TEST(Toupper8, ascii) { - try { - std::string s{"abc"}; - std::string r = unicode::toupper(s); + try { + std::string s{"abc"}; + std::string r = unicode::toupper(s); - ASSERT_EQ("ABC", r); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("ABC", r); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Toupper8, valid) { - try { - std::string s{u8"aéc"}; - std::string r = unicode::toupper(s); + try { + std::string s{u8"aéc"}; + std::string r = unicode::toupper(s); - ASSERT_EQ(u8"AÉC", r); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(u8"AÉC", r); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Toupper8, invalid) { - std::string s{"a" "\xFF""b"}; + std::string s{"a" "\xFF""b"}; - ASSERT_ANY_THROW(unicode::toupper(s)); + ASSERT_ANY_THROW(unicode::toupper(s)); } /* @@ -225,33 +225,33 @@ TEST(Tolower8, ascii) { - try { - std::string s{"ABC"}; - std::string r = unicode::tolower(s); + try { + std::string s{"ABC"}; + std::string r = unicode::tolower(s); - ASSERT_EQ("abc", r); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("abc", r); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Tolower8, valid) { - try { - std::string s{u8"AÉC"}; - std::string r = unicode::tolower(s); + try { + std::string s{u8"AÉC"}; + std::string r = unicode::tolower(s); - ASSERT_EQ(u8"aéc", r); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(u8"aéc", r); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Tolower8, invalid) { - std::string s{"A" "\xFF""B"}; + std::string s{"A" "\xFF""B"}; - ASSERT_ANY_THROW(unicode::tolower(s)); + ASSERT_ANY_THROW(unicode::tolower(s)); } /* @@ -261,30 +261,30 @@ TEST(Check, isspace) { - ASSERT_TRUE(unicode::isspace(' ')); - ASSERT_FALSE(unicode::isspace(/* é */ 233)); + ASSERT_TRUE(unicode::isspace(' ')); + ASSERT_FALSE(unicode::isspace(/* é */ 233)); } TEST(Check, isalpha) { - ASSERT_TRUE(unicode::isalpha(U'é')); - ASSERT_FALSE(unicode::isalpha(U'€')); + ASSERT_TRUE(unicode::isalpha(U'é')); + ASSERT_FALSE(unicode::isalpha(U'€')); } TEST(Check, isupper) { - ASSERT_FALSE(unicode::isupper('a')); - ASSERT_FALSE(unicode::isupper(U'é')); - ASSERT_TRUE(unicode::isupper('A')); - ASSERT_TRUE(unicode::isupper(U'É')); + ASSERT_FALSE(unicode::isupper('a')); + ASSERT_FALSE(unicode::isupper(U'é')); + ASSERT_TRUE(unicode::isupper('A')); + ASSERT_TRUE(unicode::isupper(U'É')); } TEST(Check, islower) { - ASSERT_TRUE(unicode::islower('a')); - ASSERT_TRUE(unicode::islower(U'é')); - ASSERT_FALSE(unicode::islower('A')); - ASSERT_FALSE(unicode::islower(U'É')); + ASSERT_TRUE(unicode::islower('a')); + ASSERT_TRUE(unicode::islower(U'é')); + ASSERT_FALSE(unicode::islower('A')); + ASSERT_FALSE(unicode::islower(U'É')); } /* @@ -294,56 +294,56 @@ TEST(Misc, nbytesPoint) { - ASSERT_EQ(1, unicode::nbytesPoint('a')); - ASSERT_EQ(2, unicode::nbytesPoint(U'é')); - ASSERT_EQ(3, unicode::nbytesPoint(U'€')); - ASSERT_EQ(4, unicode::nbytesPoint(U'𠀀')); + ASSERT_EQ(1, unicode::nbytesPoint('a')); + ASSERT_EQ(2, unicode::nbytesPoint(U'é')); + ASSERT_EQ(3, unicode::nbytesPoint(U'€')); + ASSERT_EQ(4, unicode::nbytesPoint(U'𠀀')); } TEST(Misc, nbytesUtf8) { - std::string s1{u8"a"}; - std::string s2{u8"é"}; - std::string s3{u8"€"}; - std::string s4{u8"𠀀"}; + std::string s1{u8"a"}; + std::string s2{u8"é"}; + std::string s3{u8"€"}; + std::string s4{u8"𠀀"}; - ASSERT_EQ(1, unicode::nbytesUtf8(s1[0])); - ASSERT_EQ(2, unicode::nbytesUtf8(s2[0])); - ASSERT_EQ(3, unicode::nbytesUtf8(s3[0])); - ASSERT_EQ(4, unicode::nbytesUtf8(s4[0])); + ASSERT_EQ(1, unicode::nbytesUtf8(s1[0])); + ASSERT_EQ(2, unicode::nbytesUtf8(s2[0])); + ASSERT_EQ(3, unicode::nbytesUtf8(s3[0])); + ASSERT_EQ(4, unicode::nbytesUtf8(s4[0])); } TEST(Misc, forEach) { - std::string s{u8"aé€𠀀"}; - int current = 0; + std::string s{u8"aé€𠀀"}; + int current = 0; - unicode::forEach(s, [&] (char32_t code) { - if (current == 0) - ASSERT_EQ(U'a', code); - else if (current == 1) - ASSERT_EQ(U'é', code); - else if (current == 2) - ASSERT_EQ(U'€', code); - else if (current == 3) - ASSERT_EQ(U'𠀀', code); + unicode::forEach(s, [&] (char32_t code) { + if (current == 0) + ASSERT_EQ(U'a', code); + else if (current == 1) + ASSERT_EQ(U'é', code); + else if (current == 2) + ASSERT_EQ(U'€', code); + else if (current == 3) + ASSERT_EQ(U'𠀀', code); - current++; - }); + current++; + }); - ASSERT_EQ(4, current); + ASSERT_EQ(4, current); } TEST(Misc, forEachInvalid) { - std::string s{"a" "\xFF" "b"}; + std::string s{"a" "\xFF" "b"}; - ASSERT_ANY_THROW(unicode::forEach(s, [&] (char32_t) { })); + ASSERT_ANY_THROW(unicode::forEach(s, [&] (char32_t) { })); } int main(int argc, char **argv) { - InitGoogleTest(&argc, argv); + InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/unicode/unicode.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/unicode.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -31,24 +31,24 @@ const char32_t *rbsearch(char32_t c, const char32_t *t, int n, int ne) noexcept { - const char32_t *p; - int m; + const char32_t *p; + int m; - while (n > 1) { - m = n >> 1; - p = t + m * ne; + while (n > 1) { + m = n >> 1; + p = t + m * ne; - if (c >= p[0]) { - t = p; - n = n - m; - } else - n = m; - } + if (c >= p[0]) { + t = p; + n = n - m; + } else + n = m; + } - if (n && c >= t[0]) - return t; + if (n && c >= t[0]) + return t; - return nullptr; + return nullptr; } } // !namespace @@ -56,533 +56,533 @@ namespace { const char32_t isspacer[] = { - 0x0009, 0x000d, - 0x0020, 0x0020, - 0x0085, 0x0085, - 0x00a0, 0x00a0, - 0x1680, 0x1680, - 0x2000, 0x200a, - 0x2028, 0x2029, - 0x202f, 0x202f, - 0x205f, 0x205f, - 0x3000, 0x3000, - 0xfeff, 0xfeff, + 0x0009, 0x000d, + 0x0020, 0x0020, + 0x0085, 0x0085, + 0x00a0, 0x00a0, + 0x1680, 0x1680, + 0x2000, 0x200a, + 0x2028, 0x2029, + 0x202f, 0x202f, + 0x205f, 0x205f, + 0x3000, 0x3000, + 0xfeff, 0xfeff, }; } // !namespace bool isspace(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, isspacer, nelem (isspacer)/2, 2); + p = rbsearch(c, isspacer, nelem (isspacer)/2, 2); - if (p && c >= p[0] && c <= p[1]) - return true; + if (p && c >= p[0] && c <= p[1]) + return true; - return false; + return false; } namespace { const char32_t isdigitr[] = { - 0x0030, 0x0039, - 0x0660, 0x0669, - 0x06f0, 0x06f9, - 0x07c0, 0x07c9, - 0x0966, 0x096f, - 0x09e6, 0x09ef, - 0x0a66, 0x0a6f, - 0x0ae6, 0x0aef, - 0x0b66, 0x0b6f, - 0x0be6, 0x0bef, - 0x0c66, 0x0c6f, - 0x0ce6, 0x0cef, - 0x0d66, 0x0d6f, - 0x0de6, 0x0def, - 0x0e50, 0x0e59, - 0x0ed0, 0x0ed9, - 0x0f20, 0x0f29, - 0x1040, 0x1049, - 0x1090, 0x1099, - 0x17e0, 0x17e9, - 0x1810, 0x1819, - 0x1946, 0x194f, - 0x19d0, 0x19d9, - 0x1a80, 0x1a89, - 0x1a90, 0x1a99, - 0x1b50, 0x1b59, - 0x1bb0, 0x1bb9, - 0x1c40, 0x1c49, - 0x1c50, 0x1c59, - 0xa620, 0xa629, - 0xa8d0, 0xa8d9, - 0xa900, 0xa909, - 0xa9d0, 0xa9d9, - 0xa9f0, 0xa9f9, - 0xaa50, 0xaa59, - 0xabf0, 0xabf9, - 0xff10, 0xff19, - 0x104a0, 0x104a9, - 0x11066, 0x1106f, - 0x110f0, 0x110f9, - 0x11136, 0x1113f, - 0x111d0, 0x111d9, - 0x112f0, 0x112f9, - 0x114d0, 0x114d9, - 0x11650, 0x11659, - 0x116c0, 0x116c9, - 0x118e0, 0x118e9, - 0x16a60, 0x16a69, - 0x16b50, 0x16b59, - 0x1d7ce, 0x1d7ff, + 0x0030, 0x0039, + 0x0660, 0x0669, + 0x06f0, 0x06f9, + 0x07c0, 0x07c9, + 0x0966, 0x096f, + 0x09e6, 0x09ef, + 0x0a66, 0x0a6f, + 0x0ae6, 0x0aef, + 0x0b66, 0x0b6f, + 0x0be6, 0x0bef, + 0x0c66, 0x0c6f, + 0x0ce6, 0x0cef, + 0x0d66, 0x0d6f, + 0x0de6, 0x0def, + 0x0e50, 0x0e59, + 0x0ed0, 0x0ed9, + 0x0f20, 0x0f29, + 0x1040, 0x1049, + 0x1090, 0x1099, + 0x17e0, 0x17e9, + 0x1810, 0x1819, + 0x1946, 0x194f, + 0x19d0, 0x19d9, + 0x1a80, 0x1a89, + 0x1a90, 0x1a99, + 0x1b50, 0x1b59, + 0x1bb0, 0x1bb9, + 0x1c40, 0x1c49, + 0x1c50, 0x1c59, + 0xa620, 0xa629, + 0xa8d0, 0xa8d9, + 0xa900, 0xa909, + 0xa9d0, 0xa9d9, + 0xa9f0, 0xa9f9, + 0xaa50, 0xaa59, + 0xabf0, 0xabf9, + 0xff10, 0xff19, + 0x104a0, 0x104a9, + 0x11066, 0x1106f, + 0x110f0, 0x110f9, + 0x11136, 0x1113f, + 0x111d0, 0x111d9, + 0x112f0, 0x112f9, + 0x114d0, 0x114d9, + 0x11650, 0x11659, + 0x116c0, 0x116c9, + 0x118e0, 0x118e9, + 0x16a60, 0x16a69, + 0x16b50, 0x16b59, + 0x1d7ce, 0x1d7ff, }; } // !namespace bool isdigit(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, isdigitr, nelem (isdigitr)/2, 2); + p = rbsearch(c, isdigitr, nelem (isdigitr)/2, 2); - if (p && c >= p[0] && c <= p[1]) - return true; + if (p && c >= p[0] && c <= p[1]) + return true; - return false; + return false; } namespace { const char32_t isalphar[] = { - 0x0041, 0x005a, - 0x0061, 0x007a, - 0x00c0, 0x00d6, - 0x00d8, 0x00f6, - 0x00f8, 0x02c1, - 0x02c6, 0x02d1, - 0x02e0, 0x02e4, - 0x0370, 0x0374, - 0x0376, 0x0377, - 0x037a, 0x037d, - 0x0388, 0x038a, - 0x038e, 0x03a1, - 0x03a3, 0x03f5, - 0x03f7, 0x0481, - 0x048a, 0x052f, - 0x0531, 0x0556, - 0x0561, 0x0587, - 0x05d0, 0x05ea, - 0x05f0, 0x05f2, - 0x0620, 0x064a, - 0x066e, 0x066f, - 0x0671, 0x06d3, - 0x06e5, 0x06e6, - 0x06ee, 0x06ef, - 0x06fa, 0x06fc, - 0x0712, 0x072f, - 0x074d, 0x07a5, - 0x07ca, 0x07ea, - 0x07f4, 0x07f5, - 0x0800, 0x0815, - 0x0840, 0x0858, - 0x08a0, 0x08b2, - 0x0904, 0x0939, - 0x0958, 0x0961, - 0x0971, 0x0980, - 0x0985, 0x098c, - 0x098f, 0x0990, - 0x0993, 0x09a8, - 0x09aa, 0x09b0, - 0x09b6, 0x09b9, - 0x09dc, 0x09dd, - 0x09df, 0x09e1, - 0x09f0, 0x09f1, - 0x0a05, 0x0a0a, - 0x0a0f, 0x0a10, - 0x0a13, 0x0a28, - 0x0a2a, 0x0a30, - 0x0a32, 0x0a33, - 0x0a35, 0x0a36, - 0x0a38, 0x0a39, - 0x0a59, 0x0a5c, - 0x0a72, 0x0a74, - 0x0a85, 0x0a8d, - 0x0a8f, 0x0a91, - 0x0a93, 0x0aa8, - 0x0aaa, 0x0ab0, - 0x0ab2, 0x0ab3, - 0x0ab5, 0x0ab9, - 0x0ae0, 0x0ae1, - 0x0b05, 0x0b0c, - 0x0b0f, 0x0b10, - 0x0b13, 0x0b28, - 0x0b2a, 0x0b30, - 0x0b32, 0x0b33, - 0x0b35, 0x0b39, - 0x0b5c, 0x0b5d, - 0x0b5f, 0x0b61, - 0x0b85, 0x0b8a, - 0x0b8e, 0x0b90, - 0x0b92, 0x0b95, - 0x0b99, 0x0b9a, - 0x0b9e, 0x0b9f, - 0x0ba3, 0x0ba4, - 0x0ba8, 0x0baa, - 0x0bae, 0x0bb9, - 0x0c05, 0x0c0c, - 0x0c0e, 0x0c10, - 0x0c12, 0x0c28, - 0x0c2a, 0x0c39, - 0x0c58, 0x0c59, - 0x0c60, 0x0c61, - 0x0c85, 0x0c8c, - 0x0c8e, 0x0c90, - 0x0c92, 0x0ca8, - 0x0caa, 0x0cb3, - 0x0cb5, 0x0cb9, - 0x0ce0, 0x0ce1, - 0x0cf1, 0x0cf2, - 0x0d05, 0x0d0c, - 0x0d0e, 0x0d10, - 0x0d12, 0x0d3a, - 0x0d60, 0x0d61, - 0x0d7a, 0x0d7f, - 0x0d85, 0x0d96, - 0x0d9a, 0x0db1, - 0x0db3, 0x0dbb, - 0x0dc0, 0x0dc6, - 0x0e01, 0x0e30, - 0x0e32, 0x0e33, - 0x0e40, 0x0e46, - 0x0e81, 0x0e82, - 0x0e87, 0x0e88, - 0x0e94, 0x0e97, - 0x0e99, 0x0e9f, - 0x0ea1, 0x0ea3, - 0x0eaa, 0x0eab, - 0x0ead, 0x0eb0, - 0x0eb2, 0x0eb3, - 0x0ec0, 0x0ec4, - 0x0edc, 0x0edf, - 0x0f40, 0x0f47, - 0x0f49, 0x0f6c, - 0x0f88, 0x0f8c, - 0x1000, 0x102a, - 0x1050, 0x1055, - 0x105a, 0x105d, - 0x1065, 0x1066, - 0x106e, 0x1070, - 0x1075, 0x1081, - 0x10a0, 0x10c5, - 0x10d0, 0x10fa, - 0x10fc, 0x1248, - 0x124a, 0x124d, - 0x1250, 0x1256, - 0x125a, 0x125d, - 0x1260, 0x1288, - 0x128a, 0x128d, - 0x1290, 0x12b0, - 0x12b2, 0x12b5, - 0x12b8, 0x12be, - 0x12c2, 0x12c5, - 0x12c8, 0x12d6, - 0x12d8, 0x1310, - 0x1312, 0x1315, - 0x1318, 0x135a, - 0x1380, 0x138f, - 0x13a0, 0x13f4, - 0x1401, 0x166c, - 0x166f, 0x167f, - 0x1681, 0x169a, - 0x16a0, 0x16ea, - 0x16f1, 0x16f8, - 0x1700, 0x170c, - 0x170e, 0x1711, - 0x1720, 0x1731, - 0x1740, 0x1751, - 0x1760, 0x176c, - 0x176e, 0x1770, - 0x1780, 0x17b3, - 0x1820, 0x1877, - 0x1880, 0x18a8, - 0x18b0, 0x18f5, - 0x1900, 0x191e, - 0x1950, 0x196d, - 0x1970, 0x1974, - 0x1980, 0x19ab, - 0x19c1, 0x19c7, - 0x1a00, 0x1a16, - 0x1a20, 0x1a54, - 0x1b05, 0x1b33, - 0x1b45, 0x1b4b, - 0x1b83, 0x1ba0, - 0x1bae, 0x1baf, - 0x1bba, 0x1be5, - 0x1c00, 0x1c23, - 0x1c4d, 0x1c4f, - 0x1c5a, 0x1c7d, - 0x1ce9, 0x1cec, - 0x1cee, 0x1cf1, - 0x1cf5, 0x1cf6, - 0x1d00, 0x1dbf, - 0x1e00, 0x1f15, - 0x1f18, 0x1f1d, - 0x1f20, 0x1f45, - 0x1f48, 0x1f4d, - 0x1f50, 0x1f57, - 0x1f5f, 0x1f7d, - 0x1f80, 0x1fb4, - 0x1fb6, 0x1fbc, - 0x1fc2, 0x1fc4, - 0x1fc6, 0x1fcc, - 0x1fd0, 0x1fd3, - 0x1fd6, 0x1fdb, - 0x1fe0, 0x1fec, - 0x1ff2, 0x1ff4, - 0x1ff6, 0x1ffc, - 0x2090, 0x209c, - 0x210a, 0x2113, - 0x2119, 0x211d, - 0x212a, 0x212d, - 0x212f, 0x2139, - 0x213c, 0x213f, - 0x2145, 0x2149, - 0x2183, 0x2184, - 0x2c00, 0x2c2e, - 0x2c30, 0x2c5e, - 0x2c60, 0x2ce4, - 0x2ceb, 0x2cee, - 0x2cf2, 0x2cf3, - 0x2d00, 0x2d25, - 0x2d30, 0x2d67, - 0x2d80, 0x2d96, - 0x2da0, 0x2da6, - 0x2da8, 0x2dae, - 0x2db0, 0x2db6, - 0x2db8, 0x2dbe, - 0x2dc0, 0x2dc6, - 0x2dc8, 0x2dce, - 0x2dd0, 0x2dd6, - 0x2dd8, 0x2dde, - 0x3005, 0x3006, - 0x3031, 0x3035, - 0x303b, 0x303c, - 0x3041, 0x3096, - 0x309d, 0x309f, - 0x30a1, 0x30fa, - 0x30fc, 0x30ff, - 0x3105, 0x312d, - 0x3131, 0x318e, - 0x31a0, 0x31ba, - 0x31f0, 0x31ff, - 0x3400, 0x4db5, - 0x4e00, 0x9fcc, - 0xa000, 0xa48c, - 0xa4d0, 0xa4fd, - 0xa500, 0xa60c, - 0xa610, 0xa61f, - 0xa62a, 0xa62b, - 0xa640, 0xa66e, - 0xa67f, 0xa69d, - 0xa6a0, 0xa6e5, - 0xa717, 0xa71f, - 0xa722, 0xa788, - 0xa78b, 0xa78e, - 0xa790, 0xa7ad, - 0xa7b0, 0xa7b1, - 0xa7f7, 0xa801, - 0xa803, 0xa805, - 0xa807, 0xa80a, - 0xa80c, 0xa822, - 0xa840, 0xa873, - 0xa882, 0xa8b3, - 0xa8f2, 0xa8f7, - 0xa90a, 0xa925, - 0xa930, 0xa946, - 0xa960, 0xa97c, - 0xa984, 0xa9b2, - 0xa9e0, 0xa9e4, - 0xa9e6, 0xa9ef, - 0xa9fa, 0xa9fe, - 0xaa00, 0xaa28, - 0xaa40, 0xaa42, - 0xaa44, 0xaa4b, - 0xaa60, 0xaa76, - 0xaa7e, 0xaaaf, - 0xaab5, 0xaab6, - 0xaab9, 0xaabd, - 0xaadb, 0xaadd, - 0xaae0, 0xaaea, - 0xaaf2, 0xaaf4, - 0xab01, 0xab06, - 0xab09, 0xab0e, - 0xab11, 0xab16, - 0xab20, 0xab26, - 0xab28, 0xab2e, - 0xab30, 0xab5a, - 0xab5c, 0xab5f, - 0xab64, 0xab65, - 0xabc0, 0xabe2, - 0xac00, 0xd7a3, - 0xd7b0, 0xd7c6, - 0xd7cb, 0xd7fb, - 0xf900, 0xfa6d, - 0xfa70, 0xfad9, - 0xfb00, 0xfb06, - 0xfb13, 0xfb17, - 0xfb1f, 0xfb28, - 0xfb2a, 0xfb36, - 0xfb38, 0xfb3c, - 0xfb40, 0xfb41, - 0xfb43, 0xfb44, - 0xfb46, 0xfbb1, - 0xfbd3, 0xfd3d, - 0xfd50, 0xfd8f, - 0xfd92, 0xfdc7, - 0xfdf0, 0xfdfb, - 0xfe70, 0xfe74, - 0xfe76, 0xfefc, - 0xff21, 0xff3a, - 0xff41, 0xff5a, - 0xff66, 0xffbe, - 0xffc2, 0xffc7, - 0xffca, 0xffcf, - 0xffd2, 0xffd7, - 0xffda, 0xffdc, - 0x10000, 0x1000b, - 0x1000d, 0x10026, - 0x10028, 0x1003a, - 0x1003c, 0x1003d, - 0x1003f, 0x1004d, - 0x10050, 0x1005d, - 0x10080, 0x100fa, - 0x10280, 0x1029c, - 0x102a0, 0x102d0, - 0x10300, 0x1031f, - 0x10330, 0x10340, - 0x10342, 0x10349, - 0x10350, 0x10375, - 0x10380, 0x1039d, - 0x103a0, 0x103c3, - 0x103c8, 0x103cf, - 0x10400, 0x1049d, - 0x10500, 0x10527, - 0x10530, 0x10563, - 0x10600, 0x10736, - 0x10740, 0x10755, - 0x10760, 0x10767, - 0x10800, 0x10805, - 0x1080a, 0x10835, - 0x10837, 0x10838, - 0x1083f, 0x10855, - 0x10860, 0x10876, - 0x10880, 0x1089e, - 0x10900, 0x10915, - 0x10920, 0x10939, - 0x10980, 0x109b7, - 0x109be, 0x109bf, - 0x10a10, 0x10a13, - 0x10a15, 0x10a17, - 0x10a19, 0x10a33, - 0x10a60, 0x10a7c, - 0x10a80, 0x10a9c, - 0x10ac0, 0x10ac7, - 0x10ac9, 0x10ae4, - 0x10b00, 0x10b35, - 0x10b40, 0x10b55, - 0x10b60, 0x10b72, - 0x10b80, 0x10b91, - 0x10c00, 0x10c48, - 0x11003, 0x11037, - 0x11083, 0x110af, - 0x110d0, 0x110e8, - 0x11103, 0x11126, - 0x11150, 0x11172, - 0x11183, 0x111b2, - 0x111c1, 0x111c4, - 0x11200, 0x11211, - 0x11213, 0x1122b, - 0x112b0, 0x112de, - 0x11305, 0x1130c, - 0x1130f, 0x11310, - 0x11313, 0x11328, - 0x1132a, 0x11330, - 0x11332, 0x11333, - 0x11335, 0x11339, - 0x1135d, 0x11361, - 0x11480, 0x114af, - 0x114c4, 0x114c5, - 0x11580, 0x115ae, - 0x11600, 0x1162f, - 0x11680, 0x116aa, - 0x118a0, 0x118df, - 0x11ac0, 0x11af8, - 0x12000, 0x12398, - 0x13000, 0x1342e, - 0x16800, 0x16a38, - 0x16a40, 0x16a5e, - 0x16ad0, 0x16aed, - 0x16b00, 0x16b2f, - 0x16b40, 0x16b43, - 0x16b63, 0x16b77, - 0x16b7d, 0x16b8f, - 0x16f00, 0x16f44, - 0x16f93, 0x16f9f, - 0x1b000, 0x1b001, - 0x1bc00, 0x1bc6a, - 0x1bc70, 0x1bc7c, - 0x1bc80, 0x1bc88, - 0x1bc90, 0x1bc99, - 0x1d400, 0x1d454, - 0x1d456, 0x1d49c, - 0x1d49e, 0x1d49f, - 0x1d4a5, 0x1d4a6, - 0x1d4a9, 0x1d4ac, - 0x1d4ae, 0x1d4b9, - 0x1d4bd, 0x1d4c3, - 0x1d4c5, 0x1d505, - 0x1d507, 0x1d50a, - 0x1d50d, 0x1d514, - 0x1d516, 0x1d51c, - 0x1d51e, 0x1d539, - 0x1d53b, 0x1d53e, - 0x1d540, 0x1d544, - 0x1d54a, 0x1d550, - 0x1d552, 0x1d6a5, - 0x1d6a8, 0x1d6c0, - 0x1d6c2, 0x1d6da, - 0x1d6dc, 0x1d6fa, - 0x1d6fc, 0x1d714, - 0x1d716, 0x1d734, - 0x1d736, 0x1d74e, - 0x1d750, 0x1d76e, - 0x1d770, 0x1d788, - 0x1d78a, 0x1d7a8, - 0x1d7aa, 0x1d7c2, - 0x1d7c4, 0x1d7cb, - 0x1e800, 0x1e8c4, - 0x1ee00, 0x1ee03, - 0x1ee05, 0x1ee1f, - 0x1ee21, 0x1ee22, - 0x1ee29, 0x1ee32, - 0x1ee34, 0x1ee37, - 0x1ee4d, 0x1ee4f, - 0x1ee51, 0x1ee52, - 0x1ee61, 0x1ee62, - 0x1ee67, 0x1ee6a, - 0x1ee6c, 0x1ee72, - 0x1ee74, 0x1ee77, - 0x1ee79, 0x1ee7c, - 0x1ee80, 0x1ee89, - 0x1ee8b, 0x1ee9b, - 0x1eea1, 0x1eea3, - 0x1eea5, 0x1eea9, - 0x1eeab, 0x1eebb, - 0x20000, 0x2a6d6, - 0x2a700, 0x2b734, - 0x2b740, 0x2b81d, - 0x2f800, 0x2fa1d, + 0x0041, 0x005a, + 0x0061, 0x007a, + 0x00c0, 0x00d6, + 0x00d8, 0x00f6, + 0x00f8, 0x02c1, + 0x02c6, 0x02d1, + 0x02e0, 0x02e4, + 0x0370, 0x0374, + 0x0376, 0x0377, + 0x037a, 0x037d, + 0x0388, 0x038a, + 0x038e, 0x03a1, + 0x03a3, 0x03f5, + 0x03f7, 0x0481, + 0x048a, 0x052f, + 0x0531, 0x0556, + 0x0561, 0x0587, + 0x05d0, 0x05ea, + 0x05f0, 0x05f2, + 0x0620, 0x064a, + 0x066e, 0x066f, + 0x0671, 0x06d3, + 0x06e5, 0x06e6, + 0x06ee, 0x06ef, + 0x06fa, 0x06fc, + 0x0712, 0x072f, + 0x074d, 0x07a5, + 0x07ca, 0x07ea, + 0x07f4, 0x07f5, + 0x0800, 0x0815, + 0x0840, 0x0858, + 0x08a0, 0x08b2, + 0x0904, 0x0939, + 0x0958, 0x0961, + 0x0971, 0x0980, + 0x0985, 0x098c, + 0x098f, 0x0990, + 0x0993, 0x09a8, + 0x09aa, 0x09b0, + 0x09b6, 0x09b9, + 0x09dc, 0x09dd, + 0x09df, 0x09e1, + 0x09f0, 0x09f1, + 0x0a05, 0x0a0a, + 0x0a0f, 0x0a10, + 0x0a13, 0x0a28, + 0x0a2a, 0x0a30, + 0x0a32, 0x0a33, + 0x0a35, 0x0a36, + 0x0a38, 0x0a39, + 0x0a59, 0x0a5c, + 0x0a72, 0x0a74, + 0x0a85, 0x0a8d, + 0x0a8f, 0x0a91, + 0x0a93, 0x0aa8, + 0x0aaa, 0x0ab0, + 0x0ab2, 0x0ab3, + 0x0ab5, 0x0ab9, + 0x0ae0, 0x0ae1, + 0x0b05, 0x0b0c, + 0x0b0f, 0x0b10, + 0x0b13, 0x0b28, + 0x0b2a, 0x0b30, + 0x0b32, 0x0b33, + 0x0b35, 0x0b39, + 0x0b5c, 0x0b5d, + 0x0b5f, 0x0b61, + 0x0b85, 0x0b8a, + 0x0b8e, 0x0b90, + 0x0b92, 0x0b95, + 0x0b99, 0x0b9a, + 0x0b9e, 0x0b9f, + 0x0ba3, 0x0ba4, + 0x0ba8, 0x0baa, + 0x0bae, 0x0bb9, + 0x0c05, 0x0c0c, + 0x0c0e, 0x0c10, + 0x0c12, 0x0c28, + 0x0c2a, 0x0c39, + 0x0c58, 0x0c59, + 0x0c60, 0x0c61, + 0x0c85, 0x0c8c, + 0x0c8e, 0x0c90, + 0x0c92, 0x0ca8, + 0x0caa, 0x0cb3, + 0x0cb5, 0x0cb9, + 0x0ce0, 0x0ce1, + 0x0cf1, 0x0cf2, + 0x0d05, 0x0d0c, + 0x0d0e, 0x0d10, + 0x0d12, 0x0d3a, + 0x0d60, 0x0d61, + 0x0d7a, 0x0d7f, + 0x0d85, 0x0d96, + 0x0d9a, 0x0db1, + 0x0db3, 0x0dbb, + 0x0dc0, 0x0dc6, + 0x0e01, 0x0e30, + 0x0e32, 0x0e33, + 0x0e40, 0x0e46, + 0x0e81, 0x0e82, + 0x0e87, 0x0e88, + 0x0e94, 0x0e97, + 0x0e99, 0x0e9f, + 0x0ea1, 0x0ea3, + 0x0eaa, 0x0eab, + 0x0ead, 0x0eb0, + 0x0eb2, 0x0eb3, + 0x0ec0, 0x0ec4, + 0x0edc, 0x0edf, + 0x0f40, 0x0f47, + 0x0f49, 0x0f6c, + 0x0f88, 0x0f8c, + 0x1000, 0x102a, + 0x1050, 0x1055, + 0x105a, 0x105d, + 0x1065, 0x1066, + 0x106e, 0x1070, + 0x1075, 0x1081, + 0x10a0, 0x10c5, + 0x10d0, 0x10fa, + 0x10fc, 0x1248, + 0x124a, 0x124d, + 0x1250, 0x1256, + 0x125a, 0x125d, + 0x1260, 0x1288, + 0x128a, 0x128d, + 0x1290, 0x12b0, + 0x12b2, 0x12b5, + 0x12b8, 0x12be, + 0x12c2, 0x12c5, + 0x12c8, 0x12d6, + 0x12d8, 0x1310, + 0x1312, 0x1315, + 0x1318, 0x135a, + 0x1380, 0x138f, + 0x13a0, 0x13f4, + 0x1401, 0x166c, + 0x166f, 0x167f, + 0x1681, 0x169a, + 0x16a0, 0x16ea, + 0x16f1, 0x16f8, + 0x1700, 0x170c, + 0x170e, 0x1711, + 0x1720, 0x1731, + 0x1740, 0x1751, + 0x1760, 0x176c, + 0x176e, 0x1770, + 0x1780, 0x17b3, + 0x1820, 0x1877, + 0x1880, 0x18a8, + 0x18b0, 0x18f5, + 0x1900, 0x191e, + 0x1950, 0x196d, + 0x1970, 0x1974, + 0x1980, 0x19ab, + 0x19c1, 0x19c7, + 0x1a00, 0x1a16, + 0x1a20, 0x1a54, + 0x1b05, 0x1b33, + 0x1b45, 0x1b4b, + 0x1b83, 0x1ba0, + 0x1bae, 0x1baf, + 0x1bba, 0x1be5, + 0x1c00, 0x1c23, + 0x1c4d, 0x1c4f, + 0x1c5a, 0x1c7d, + 0x1ce9, 0x1cec, + 0x1cee, 0x1cf1, + 0x1cf5, 0x1cf6, + 0x1d00, 0x1dbf, + 0x1e00, 0x1f15, + 0x1f18, 0x1f1d, + 0x1f20, 0x1f45, + 0x1f48, 0x1f4d, + 0x1f50, 0x1f57, + 0x1f5f, 0x1f7d, + 0x1f80, 0x1fb4, + 0x1fb6, 0x1fbc, + 0x1fc2, 0x1fc4, + 0x1fc6, 0x1fcc, + 0x1fd0, 0x1fd3, + 0x1fd6, 0x1fdb, + 0x1fe0, 0x1fec, + 0x1ff2, 0x1ff4, + 0x1ff6, 0x1ffc, + 0x2090, 0x209c, + 0x210a, 0x2113, + 0x2119, 0x211d, + 0x212a, 0x212d, + 0x212f, 0x2139, + 0x213c, 0x213f, + 0x2145, 0x2149, + 0x2183, 0x2184, + 0x2c00, 0x2c2e, + 0x2c30, 0x2c5e, + 0x2c60, 0x2ce4, + 0x2ceb, 0x2cee, + 0x2cf2, 0x2cf3, + 0x2d00, 0x2d25, + 0x2d30, 0x2d67, + 0x2d80, 0x2d96, + 0x2da0, 0x2da6, + 0x2da8, 0x2dae, + 0x2db0, 0x2db6, + 0x2db8, 0x2dbe, + 0x2dc0, 0x2dc6, + 0x2dc8, 0x2dce, + 0x2dd0, 0x2dd6, + 0x2dd8, 0x2dde, + 0x3005, 0x3006, + 0x3031, 0x3035, + 0x303b, 0x303c, + 0x3041, 0x3096, + 0x309d, 0x309f, + 0x30a1, 0x30fa, + 0x30fc, 0x30ff, + 0x3105, 0x312d, + 0x3131, 0x318e, + 0x31a0, 0x31ba, + 0x31f0, 0x31ff, + 0x3400, 0x4db5, + 0x4e00, 0x9fcc, + 0xa000, 0xa48c, + 0xa4d0, 0xa4fd, + 0xa500, 0xa60c, + 0xa610, 0xa61f, + 0xa62a, 0xa62b, + 0xa640, 0xa66e, + 0xa67f, 0xa69d, + 0xa6a0, 0xa6e5, + 0xa717, 0xa71f, + 0xa722, 0xa788, + 0xa78b, 0xa78e, + 0xa790, 0xa7ad, + 0xa7b0, 0xa7b1, + 0xa7f7, 0xa801, + 0xa803, 0xa805, + 0xa807, 0xa80a, + 0xa80c, 0xa822, + 0xa840, 0xa873, + 0xa882, 0xa8b3, + 0xa8f2, 0xa8f7, + 0xa90a, 0xa925, + 0xa930, 0xa946, + 0xa960, 0xa97c, + 0xa984, 0xa9b2, + 0xa9e0, 0xa9e4, + 0xa9e6, 0xa9ef, + 0xa9fa, 0xa9fe, + 0xaa00, 0xaa28, + 0xaa40, 0xaa42, + 0xaa44, 0xaa4b, + 0xaa60, 0xaa76, + 0xaa7e, 0xaaaf, + 0xaab5, 0xaab6, + 0xaab9, 0xaabd, + 0xaadb, 0xaadd, + 0xaae0, 0xaaea, + 0xaaf2, 0xaaf4, + 0xab01, 0xab06, + 0xab09, 0xab0e, + 0xab11, 0xab16, + 0xab20, 0xab26, + 0xab28, 0xab2e, + 0xab30, 0xab5a, + 0xab5c, 0xab5f, + 0xab64, 0xab65, + 0xabc0, 0xabe2, + 0xac00, 0xd7a3, + 0xd7b0, 0xd7c6, + 0xd7cb, 0xd7fb, + 0xf900, 0xfa6d, + 0xfa70, 0xfad9, + 0xfb00, 0xfb06, + 0xfb13, 0xfb17, + 0xfb1f, 0xfb28, + 0xfb2a, 0xfb36, + 0xfb38, 0xfb3c, + 0xfb40, 0xfb41, + 0xfb43, 0xfb44, + 0xfb46, 0xfbb1, + 0xfbd3, 0xfd3d, + 0xfd50, 0xfd8f, + 0xfd92, 0xfdc7, + 0xfdf0, 0xfdfb, + 0xfe70, 0xfe74, + 0xfe76, 0xfefc, + 0xff21, 0xff3a, + 0xff41, 0xff5a, + 0xff66, 0xffbe, + 0xffc2, 0xffc7, + 0xffca, 0xffcf, + 0xffd2, 0xffd7, + 0xffda, 0xffdc, + 0x10000, 0x1000b, + 0x1000d, 0x10026, + 0x10028, 0x1003a, + 0x1003c, 0x1003d, + 0x1003f, 0x1004d, + 0x10050, 0x1005d, + 0x10080, 0x100fa, + 0x10280, 0x1029c, + 0x102a0, 0x102d0, + 0x10300, 0x1031f, + 0x10330, 0x10340, + 0x10342, 0x10349, + 0x10350, 0x10375, + 0x10380, 0x1039d, + 0x103a0, 0x103c3, + 0x103c8, 0x103cf, + 0x10400, 0x1049d, + 0x10500, 0x10527, + 0x10530, 0x10563, + 0x10600, 0x10736, + 0x10740, 0x10755, + 0x10760, 0x10767, + 0x10800, 0x10805, + 0x1080a, 0x10835, + 0x10837, 0x10838, + 0x1083f, 0x10855, + 0x10860, 0x10876, + 0x10880, 0x1089e, + 0x10900, 0x10915, + 0x10920, 0x10939, + 0x10980, 0x109b7, + 0x109be, 0x109bf, + 0x10a10, 0x10a13, + 0x10a15, 0x10a17, + 0x10a19, 0x10a33, + 0x10a60, 0x10a7c, + 0x10a80, 0x10a9c, + 0x10ac0, 0x10ac7, + 0x10ac9, 0x10ae4, + 0x10b00, 0x10b35, + 0x10b40, 0x10b55, + 0x10b60, 0x10b72, + 0x10b80, 0x10b91, + 0x10c00, 0x10c48, + 0x11003, 0x11037, + 0x11083, 0x110af, + 0x110d0, 0x110e8, + 0x11103, 0x11126, + 0x11150, 0x11172, + 0x11183, 0x111b2, + 0x111c1, 0x111c4, + 0x11200, 0x11211, + 0x11213, 0x1122b, + 0x112b0, 0x112de, + 0x11305, 0x1130c, + 0x1130f, 0x11310, + 0x11313, 0x11328, + 0x1132a, 0x11330, + 0x11332, 0x11333, + 0x11335, 0x11339, + 0x1135d, 0x11361, + 0x11480, 0x114af, + 0x114c4, 0x114c5, + 0x11580, 0x115ae, + 0x11600, 0x1162f, + 0x11680, 0x116aa, + 0x118a0, 0x118df, + 0x11ac0, 0x11af8, + 0x12000, 0x12398, + 0x13000, 0x1342e, + 0x16800, 0x16a38, + 0x16a40, 0x16a5e, + 0x16ad0, 0x16aed, + 0x16b00, 0x16b2f, + 0x16b40, 0x16b43, + 0x16b63, 0x16b77, + 0x16b7d, 0x16b8f, + 0x16f00, 0x16f44, + 0x16f93, 0x16f9f, + 0x1b000, 0x1b001, + 0x1bc00, 0x1bc6a, + 0x1bc70, 0x1bc7c, + 0x1bc80, 0x1bc88, + 0x1bc90, 0x1bc99, + 0x1d400, 0x1d454, + 0x1d456, 0x1d49c, + 0x1d49e, 0x1d49f, + 0x1d4a5, 0x1d4a6, + 0x1d4a9, 0x1d4ac, + 0x1d4ae, 0x1d4b9, + 0x1d4bd, 0x1d4c3, + 0x1d4c5, 0x1d505, + 0x1d507, 0x1d50a, + 0x1d50d, 0x1d514, + 0x1d516, 0x1d51c, + 0x1d51e, 0x1d539, + 0x1d53b, 0x1d53e, + 0x1d540, 0x1d544, + 0x1d54a, 0x1d550, + 0x1d552, 0x1d6a5, + 0x1d6a8, 0x1d6c0, + 0x1d6c2, 0x1d6da, + 0x1d6dc, 0x1d6fa, + 0x1d6fc, 0x1d714, + 0x1d716, 0x1d734, + 0x1d736, 0x1d74e, + 0x1d750, 0x1d76e, + 0x1d770, 0x1d788, + 0x1d78a, 0x1d7a8, + 0x1d7aa, 0x1d7c2, + 0x1d7c4, 0x1d7cb, + 0x1e800, 0x1e8c4, + 0x1ee00, 0x1ee03, + 0x1ee05, 0x1ee1f, + 0x1ee21, 0x1ee22, + 0x1ee29, 0x1ee32, + 0x1ee34, 0x1ee37, + 0x1ee4d, 0x1ee4f, + 0x1ee51, 0x1ee52, + 0x1ee61, 0x1ee62, + 0x1ee67, 0x1ee6a, + 0x1ee6c, 0x1ee72, + 0x1ee74, 0x1ee77, + 0x1ee79, 0x1ee7c, + 0x1ee80, 0x1ee89, + 0x1ee8b, 0x1ee9b, + 0x1eea1, 0x1eea3, + 0x1eea5, 0x1eea9, + 0x1eeab, 0x1eebb, + 0x20000, 0x2a6d6, + 0x2a700, 0x2b734, + 0x2b740, 0x2b81d, + 0x2f800, 0x2fa1d, }; } // !namespace @@ -590,228 +590,228 @@ namespace { const char32_t isalphas[] = { - 0x00aa, - 0x00b5, - 0x00ba, - 0x02ec, - 0x02ee, - 0x037f, - 0x0386, - 0x038c, - 0x0559, - 0x06d5, - 0x06ff, - 0x0710, - 0x07b1, - 0x07fa, - 0x081a, - 0x0824, - 0x0828, - 0x093d, - 0x0950, - 0x09b2, - 0x09bd, - 0x09ce, - 0x0a5e, - 0x0abd, - 0x0ad0, - 0x0b3d, - 0x0b71, - 0x0b83, - 0x0b9c, - 0x0bd0, - 0x0c3d, - 0x0cbd, - 0x0cde, - 0x0d3d, - 0x0d4e, - 0x0dbd, - 0x0e84, - 0x0e8a, - 0x0e8d, - 0x0ea5, - 0x0ea7, - 0x0ebd, - 0x0ec6, - 0x0f00, - 0x103f, - 0x1061, - 0x108e, - 0x10c7, - 0x10cd, - 0x1258, - 0x12c0, - 0x17d7, - 0x17dc, - 0x18aa, - 0x1aa7, - 0x1f59, - 0x1f5b, - 0x1f5d, - 0x1fbe, - 0x2071, - 0x207f, - 0x2102, - 0x2107, - 0x2115, - 0x2124, - 0x2126, - 0x2128, - 0x214e, - 0x2d27, - 0x2d2d, - 0x2d6f, - 0x2e2f, - 0xa8fb, - 0xa9cf, - 0xaa7a, - 0xaab1, - 0xaac0, - 0xaac2, - 0xfb1d, - 0xfb3e, - 0x10808, - 0x1083c, - 0x10a00, - 0x11176, - 0x111da, - 0x1133d, - 0x114c7, - 0x11644, - 0x118ff, - 0x16f50, - 0x1d4a2, - 0x1d4bb, - 0x1d546, - 0x1ee24, - 0x1ee27, - 0x1ee39, - 0x1ee3b, - 0x1ee42, - 0x1ee47, - 0x1ee49, - 0x1ee4b, - 0x1ee54, - 0x1ee57, - 0x1ee59, - 0x1ee5b, - 0x1ee5d, - 0x1ee5f, - 0x1ee64, - 0x1ee7e, + 0x00aa, + 0x00b5, + 0x00ba, + 0x02ec, + 0x02ee, + 0x037f, + 0x0386, + 0x038c, + 0x0559, + 0x06d5, + 0x06ff, + 0x0710, + 0x07b1, + 0x07fa, + 0x081a, + 0x0824, + 0x0828, + 0x093d, + 0x0950, + 0x09b2, + 0x09bd, + 0x09ce, + 0x0a5e, + 0x0abd, + 0x0ad0, + 0x0b3d, + 0x0b71, + 0x0b83, + 0x0b9c, + 0x0bd0, + 0x0c3d, + 0x0cbd, + 0x0cde, + 0x0d3d, + 0x0d4e, + 0x0dbd, + 0x0e84, + 0x0e8a, + 0x0e8d, + 0x0ea5, + 0x0ea7, + 0x0ebd, + 0x0ec6, + 0x0f00, + 0x103f, + 0x1061, + 0x108e, + 0x10c7, + 0x10cd, + 0x1258, + 0x12c0, + 0x17d7, + 0x17dc, + 0x18aa, + 0x1aa7, + 0x1f59, + 0x1f5b, + 0x1f5d, + 0x1fbe, + 0x2071, + 0x207f, + 0x2102, + 0x2107, + 0x2115, + 0x2124, + 0x2126, + 0x2128, + 0x214e, + 0x2d27, + 0x2d2d, + 0x2d6f, + 0x2e2f, + 0xa8fb, + 0xa9cf, + 0xaa7a, + 0xaab1, + 0xaac0, + 0xaac2, + 0xfb1d, + 0xfb3e, + 0x10808, + 0x1083c, + 0x10a00, + 0x11176, + 0x111da, + 0x1133d, + 0x114c7, + 0x11644, + 0x118ff, + 0x16f50, + 0x1d4a2, + 0x1d4bb, + 0x1d546, + 0x1ee24, + 0x1ee27, + 0x1ee39, + 0x1ee3b, + 0x1ee42, + 0x1ee47, + 0x1ee49, + 0x1ee4b, + 0x1ee54, + 0x1ee57, + 0x1ee59, + 0x1ee5b, + 0x1ee5d, + 0x1ee5f, + 0x1ee64, + 0x1ee7e, }; } // !namespace bool isalpha(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, isalphar, nelem (isalphar)/2, 2); + p = rbsearch(c, isalphar, nelem (isalphar)/2, 2); - if (p && c >= p[0] && c <= p[1]) - return true; + if (p && c >= p[0] && c <= p[1]) + return true; - p = rbsearch(c, isalphas, nelem (isalphas), 1); + p = rbsearch(c, isalphas, nelem (isalphas), 1); - if (p && c == p[0]) - return true; + if (p && c == p[0]) + return true; - return false; + return false; } namespace { const char32_t isupperr[] = { - 0x0041, 0x005a, - 0x00c0, 0x00d6, - 0x00d8, 0x00de, - 0x0178, 0x0179, - 0x0181, 0x0182, - 0x0186, 0x0187, - 0x0189, 0x018b, - 0x018e, 0x0191, - 0x0193, 0x0194, - 0x0196, 0x0198, - 0x019c, 0x019d, - 0x019f, 0x01a0, - 0x01a6, 0x01a7, - 0x01ae, 0x01af, - 0x01b1, 0x01b3, - 0x01b7, 0x01b8, - 0x01f6, 0x01f8, - 0x023a, 0x023b, - 0x023d, 0x023e, - 0x0243, 0x0246, - 0x0388, 0x038a, - 0x038e, 0x038f, - 0x0391, 0x03a1, - 0x03a3, 0x03ab, - 0x03d2, 0x03d4, - 0x03f9, 0x03fa, - 0x03fd, 0x042f, - 0x04c0, 0x04c1, - 0x0531, 0x0556, - 0x10a0, 0x10c5, - 0x1f08, 0x1f0f, - 0x1f18, 0x1f1d, - 0x1f28, 0x1f2f, - 0x1f38, 0x1f3f, - 0x1f48, 0x1f4d, - 0x1f68, 0x1f6f, - 0x1f88, 0x1f8f, - 0x1f98, 0x1f9f, - 0x1fa8, 0x1faf, - 0x1fb8, 0x1fbc, - 0x1fc8, 0x1fcc, - 0x1fd8, 0x1fdb, - 0x1fe8, 0x1fec, - 0x1ff8, 0x1ffc, - 0x210b, 0x210d, - 0x2110, 0x2112, - 0x2119, 0x211d, - 0x212a, 0x212d, - 0x2130, 0x2133, - 0x213e, 0x213f, - 0x2160, 0x216f, - 0x24b6, 0x24cf, - 0x2c00, 0x2c2e, - 0x2c62, 0x2c64, - 0x2c6d, 0x2c70, - 0x2c7e, 0x2c80, - 0xa77d, 0xa77e, - 0xa7aa, 0xa7ad, - 0xa7b0, 0xa7b1, - 0xff21, 0xff3a, - 0x10400, 0x10427, - 0x118a0, 0x118bf, - 0x1d400, 0x1d419, - 0x1d434, 0x1d44d, - 0x1d468, 0x1d481, - 0x1d49e, 0x1d49f, - 0x1d4a5, 0x1d4a6, - 0x1d4a9, 0x1d4ac, - 0x1d4ae, 0x1d4b5, - 0x1d4d0, 0x1d4e9, - 0x1d504, 0x1d505, - 0x1d507, 0x1d50a, - 0x1d50d, 0x1d514, - 0x1d516, 0x1d51c, - 0x1d538, 0x1d539, - 0x1d53b, 0x1d53e, - 0x1d540, 0x1d544, - 0x1d54a, 0x1d550, - 0x1d56c, 0x1d585, - 0x1d5a0, 0x1d5b9, - 0x1d5d4, 0x1d5ed, - 0x1d608, 0x1d621, - 0x1d63c, 0x1d655, - 0x1d670, 0x1d689, - 0x1d6a8, 0x1d6c0, - 0x1d6e2, 0x1d6fa, - 0x1d71c, 0x1d734, - 0x1d756, 0x1d76e, - 0x1d790, 0x1d7a8, + 0x0041, 0x005a, + 0x00c0, 0x00d6, + 0x00d8, 0x00de, + 0x0178, 0x0179, + 0x0181, 0x0182, + 0x0186, 0x0187, + 0x0189, 0x018b, + 0x018e, 0x0191, + 0x0193, 0x0194, + 0x0196, 0x0198, + 0x019c, 0x019d, + 0x019f, 0x01a0, + 0x01a6, 0x01a7, + 0x01ae, 0x01af, + 0x01b1, 0x01b3, + 0x01b7, 0x01b8, + 0x01f6, 0x01f8, + 0x023a, 0x023b, + 0x023d, 0x023e, + 0x0243, 0x0246, + 0x0388, 0x038a, + 0x038e, 0x038f, + 0x0391, 0x03a1, + 0x03a3, 0x03ab, + 0x03d2, 0x03d4, + 0x03f9, 0x03fa, + 0x03fd, 0x042f, + 0x04c0, 0x04c1, + 0x0531, 0x0556, + 0x10a0, 0x10c5, + 0x1f08, 0x1f0f, + 0x1f18, 0x1f1d, + 0x1f28, 0x1f2f, + 0x1f38, 0x1f3f, + 0x1f48, 0x1f4d, + 0x1f68, 0x1f6f, + 0x1f88, 0x1f8f, + 0x1f98, 0x1f9f, + 0x1fa8, 0x1faf, + 0x1fb8, 0x1fbc, + 0x1fc8, 0x1fcc, + 0x1fd8, 0x1fdb, + 0x1fe8, 0x1fec, + 0x1ff8, 0x1ffc, + 0x210b, 0x210d, + 0x2110, 0x2112, + 0x2119, 0x211d, + 0x212a, 0x212d, + 0x2130, 0x2133, + 0x213e, 0x213f, + 0x2160, 0x216f, + 0x24b6, 0x24cf, + 0x2c00, 0x2c2e, + 0x2c62, 0x2c64, + 0x2c6d, 0x2c70, + 0x2c7e, 0x2c80, + 0xa77d, 0xa77e, + 0xa7aa, 0xa7ad, + 0xa7b0, 0xa7b1, + 0xff21, 0xff3a, + 0x10400, 0x10427, + 0x118a0, 0x118bf, + 0x1d400, 0x1d419, + 0x1d434, 0x1d44d, + 0x1d468, 0x1d481, + 0x1d49e, 0x1d49f, + 0x1d4a5, 0x1d4a6, + 0x1d4a9, 0x1d4ac, + 0x1d4ae, 0x1d4b5, + 0x1d4d0, 0x1d4e9, + 0x1d504, 0x1d505, + 0x1d507, 0x1d50a, + 0x1d50d, 0x1d514, + 0x1d516, 0x1d51c, + 0x1d538, 0x1d539, + 0x1d53b, 0x1d53e, + 0x1d540, 0x1d544, + 0x1d54a, 0x1d550, + 0x1d56c, 0x1d585, + 0x1d5a0, 0x1d5b9, + 0x1d5d4, 0x1d5ed, + 0x1d608, 0x1d621, + 0x1d63c, 0x1d655, + 0x1d670, 0x1d689, + 0x1d6a8, 0x1d6c0, + 0x1d6e2, 0x1d6fa, + 0x1d71c, 0x1d734, + 0x1d756, 0x1d76e, + 0x1d790, 0x1d7a8, }; } // !namespace @@ -819,665 +819,665 @@ namespace { const char32_t isuppers[] = { - 0x0100, - 0x0102, - 0x0104, - 0x0106, - 0x0108, - 0x010a, - 0x010c, - 0x010e, - 0x0110, - 0x0112, - 0x0114, - 0x0116, - 0x0118, - 0x011a, - 0x011c, - 0x011e, - 0x0120, - 0x0122, - 0x0124, - 0x0126, - 0x0128, - 0x012a, - 0x012c, - 0x012e, - 0x0130, - 0x0132, - 0x0134, - 0x0136, - 0x0139, - 0x013b, - 0x013d, - 0x013f, - 0x0141, - 0x0143, - 0x0145, - 0x0147, - 0x014a, - 0x014c, - 0x014e, - 0x0150, - 0x0152, - 0x0154, - 0x0156, - 0x0158, - 0x015a, - 0x015c, - 0x015e, - 0x0160, - 0x0162, - 0x0164, - 0x0166, - 0x0168, - 0x016a, - 0x016c, - 0x016e, - 0x0170, - 0x0172, - 0x0174, - 0x0176, - 0x017b, - 0x017d, - 0x0184, - 0x01a2, - 0x01a4, - 0x01a9, - 0x01ac, - 0x01b5, - 0x01bc, - 0x01c4, - 0x01c7, - 0x01ca, - 0x01cd, - 0x01cf, - 0x01d1, - 0x01d3, - 0x01d5, - 0x01d7, - 0x01d9, - 0x01db, - 0x01de, - 0x01e0, - 0x01e2, - 0x01e4, - 0x01e6, - 0x01e8, - 0x01ea, - 0x01ec, - 0x01ee, - 0x01f1, - 0x01f4, - 0x01fa, - 0x01fc, - 0x01fe, - 0x0200, - 0x0202, - 0x0204, - 0x0206, - 0x0208, - 0x020a, - 0x020c, - 0x020e, - 0x0210, - 0x0212, - 0x0214, - 0x0216, - 0x0218, - 0x021a, - 0x021c, - 0x021e, - 0x0220, - 0x0222, - 0x0224, - 0x0226, - 0x0228, - 0x022a, - 0x022c, - 0x022e, - 0x0230, - 0x0232, - 0x0241, - 0x0248, - 0x024a, - 0x024c, - 0x024e, - 0x0370, - 0x0372, - 0x0376, - 0x037f, - 0x0386, - 0x038c, - 0x03cf, - 0x03d8, - 0x03da, - 0x03dc, - 0x03de, - 0x03e0, - 0x03e2, - 0x03e4, - 0x03e6, - 0x03e8, - 0x03ea, - 0x03ec, - 0x03ee, - 0x03f4, - 0x03f7, - 0x0460, - 0x0462, - 0x0464, - 0x0466, - 0x0468, - 0x046a, - 0x046c, - 0x046e, - 0x0470, - 0x0472, - 0x0474, - 0x0476, - 0x0478, - 0x047a, - 0x047c, - 0x047e, - 0x0480, - 0x048a, - 0x048c, - 0x048e, - 0x0490, - 0x0492, - 0x0494, - 0x0496, - 0x0498, - 0x049a, - 0x049c, - 0x049e, - 0x04a0, - 0x04a2, - 0x04a4, - 0x04a6, - 0x04a8, - 0x04aa, - 0x04ac, - 0x04ae, - 0x04b0, - 0x04b2, - 0x04b4, - 0x04b6, - 0x04b8, - 0x04ba, - 0x04bc, - 0x04be, - 0x04c3, - 0x04c5, - 0x04c7, - 0x04c9, - 0x04cb, - 0x04cd, - 0x04d0, - 0x04d2, - 0x04d4, - 0x04d6, - 0x04d8, - 0x04da, - 0x04dc, - 0x04de, - 0x04e0, - 0x04e2, - 0x04e4, - 0x04e6, - 0x04e8, - 0x04ea, - 0x04ec, - 0x04ee, - 0x04f0, - 0x04f2, - 0x04f4, - 0x04f6, - 0x04f8, - 0x04fa, - 0x04fc, - 0x04fe, - 0x0500, - 0x0502, - 0x0504, - 0x0506, - 0x0508, - 0x050a, - 0x050c, - 0x050e, - 0x0510, - 0x0512, - 0x0514, - 0x0516, - 0x0518, - 0x051a, - 0x051c, - 0x051e, - 0x0520, - 0x0522, - 0x0524, - 0x0526, - 0x0528, - 0x052a, - 0x052c, - 0x052e, - 0x10c7, - 0x10cd, - 0x1e00, - 0x1e02, - 0x1e04, - 0x1e06, - 0x1e08, - 0x1e0a, - 0x1e0c, - 0x1e0e, - 0x1e10, - 0x1e12, - 0x1e14, - 0x1e16, - 0x1e18, - 0x1e1a, - 0x1e1c, - 0x1e1e, - 0x1e20, - 0x1e22, - 0x1e24, - 0x1e26, - 0x1e28, - 0x1e2a, - 0x1e2c, - 0x1e2e, - 0x1e30, - 0x1e32, - 0x1e34, - 0x1e36, - 0x1e38, - 0x1e3a, - 0x1e3c, - 0x1e3e, - 0x1e40, - 0x1e42, - 0x1e44, - 0x1e46, - 0x1e48, - 0x1e4a, - 0x1e4c, - 0x1e4e, - 0x1e50, - 0x1e52, - 0x1e54, - 0x1e56, - 0x1e58, - 0x1e5a, - 0x1e5c, - 0x1e5e, - 0x1e60, - 0x1e62, - 0x1e64, - 0x1e66, - 0x1e68, - 0x1e6a, - 0x1e6c, - 0x1e6e, - 0x1e70, - 0x1e72, - 0x1e74, - 0x1e76, - 0x1e78, - 0x1e7a, - 0x1e7c, - 0x1e7e, - 0x1e80, - 0x1e82, - 0x1e84, - 0x1e86, - 0x1e88, - 0x1e8a, - 0x1e8c, - 0x1e8e, - 0x1e90, - 0x1e92, - 0x1e94, - 0x1e9e, - 0x1ea0, - 0x1ea2, - 0x1ea4, - 0x1ea6, - 0x1ea8, - 0x1eaa, - 0x1eac, - 0x1eae, - 0x1eb0, - 0x1eb2, - 0x1eb4, - 0x1eb6, - 0x1eb8, - 0x1eba, - 0x1ebc, - 0x1ebe, - 0x1ec0, - 0x1ec2, - 0x1ec4, - 0x1ec6, - 0x1ec8, - 0x1eca, - 0x1ecc, - 0x1ece, - 0x1ed0, - 0x1ed2, - 0x1ed4, - 0x1ed6, - 0x1ed8, - 0x1eda, - 0x1edc, - 0x1ede, - 0x1ee0, - 0x1ee2, - 0x1ee4, - 0x1ee6, - 0x1ee8, - 0x1eea, - 0x1eec, - 0x1eee, - 0x1ef0, - 0x1ef2, - 0x1ef4, - 0x1ef6, - 0x1ef8, - 0x1efa, - 0x1efc, - 0x1efe, - 0x1f59, - 0x1f5b, - 0x1f5d, - 0x1f5f, - 0x2102, - 0x2107, - 0x2115, - 0x2124, - 0x2126, - 0x2128, - 0x2145, - 0x2183, - 0x2c60, - 0x2c67, - 0x2c69, - 0x2c6b, - 0x2c72, - 0x2c75, - 0x2c82, - 0x2c84, - 0x2c86, - 0x2c88, - 0x2c8a, - 0x2c8c, - 0x2c8e, - 0x2c90, - 0x2c92, - 0x2c94, - 0x2c96, - 0x2c98, - 0x2c9a, - 0x2c9c, - 0x2c9e, - 0x2ca0, - 0x2ca2, - 0x2ca4, - 0x2ca6, - 0x2ca8, - 0x2caa, - 0x2cac, - 0x2cae, - 0x2cb0, - 0x2cb2, - 0x2cb4, - 0x2cb6, - 0x2cb8, - 0x2cba, - 0x2cbc, - 0x2cbe, - 0x2cc0, - 0x2cc2, - 0x2cc4, - 0x2cc6, - 0x2cc8, - 0x2cca, - 0x2ccc, - 0x2cce, - 0x2cd0, - 0x2cd2, - 0x2cd4, - 0x2cd6, - 0x2cd8, - 0x2cda, - 0x2cdc, - 0x2cde, - 0x2ce0, - 0x2ce2, - 0x2ceb, - 0x2ced, - 0x2cf2, - 0xa640, - 0xa642, - 0xa644, - 0xa646, - 0xa648, - 0xa64a, - 0xa64c, - 0xa64e, - 0xa650, - 0xa652, - 0xa654, - 0xa656, - 0xa658, - 0xa65a, - 0xa65c, - 0xa65e, - 0xa660, - 0xa662, - 0xa664, - 0xa666, - 0xa668, - 0xa66a, - 0xa66c, - 0xa680, - 0xa682, - 0xa684, - 0xa686, - 0xa688, - 0xa68a, - 0xa68c, - 0xa68e, - 0xa690, - 0xa692, - 0xa694, - 0xa696, - 0xa698, - 0xa69a, - 0xa722, - 0xa724, - 0xa726, - 0xa728, - 0xa72a, - 0xa72c, - 0xa72e, - 0xa732, - 0xa734, - 0xa736, - 0xa738, - 0xa73a, - 0xa73c, - 0xa73e, - 0xa740, - 0xa742, - 0xa744, - 0xa746, - 0xa748, - 0xa74a, - 0xa74c, - 0xa74e, - 0xa750, - 0xa752, - 0xa754, - 0xa756, - 0xa758, - 0xa75a, - 0xa75c, - 0xa75e, - 0xa760, - 0xa762, - 0xa764, - 0xa766, - 0xa768, - 0xa76a, - 0xa76c, - 0xa76e, - 0xa779, - 0xa77b, - 0xa780, - 0xa782, - 0xa784, - 0xa786, - 0xa78b, - 0xa78d, - 0xa790, - 0xa792, - 0xa796, - 0xa798, - 0xa79a, - 0xa79c, - 0xa79e, - 0xa7a0, - 0xa7a2, - 0xa7a4, - 0xa7a6, - 0xa7a8, - 0x1d49c, - 0x1d4a2, - 0x1d546, - 0x1d7ca, + 0x0100, + 0x0102, + 0x0104, + 0x0106, + 0x0108, + 0x010a, + 0x010c, + 0x010e, + 0x0110, + 0x0112, + 0x0114, + 0x0116, + 0x0118, + 0x011a, + 0x011c, + 0x011e, + 0x0120, + 0x0122, + 0x0124, + 0x0126, + 0x0128, + 0x012a, + 0x012c, + 0x012e, + 0x0130, + 0x0132, + 0x0134, + 0x0136, + 0x0139, + 0x013b, + 0x013d, + 0x013f, + 0x0141, + 0x0143, + 0x0145, + 0x0147, + 0x014a, + 0x014c, + 0x014e, + 0x0150, + 0x0152, + 0x0154, + 0x0156, + 0x0158, + 0x015a, + 0x015c, + 0x015e, + 0x0160, + 0x0162, + 0x0164, + 0x0166, + 0x0168, + 0x016a, + 0x016c, + 0x016e, + 0x0170, + 0x0172, + 0x0174, + 0x0176, + 0x017b, + 0x017d, + 0x0184, + 0x01a2, + 0x01a4, + 0x01a9, + 0x01ac, + 0x01b5, + 0x01bc, + 0x01c4, + 0x01c7, + 0x01ca, + 0x01cd, + 0x01cf, + 0x01d1, + 0x01d3, + 0x01d5, + 0x01d7, + 0x01d9, + 0x01db, + 0x01de, + 0x01e0, + 0x01e2, + 0x01e4, + 0x01e6, + 0x01e8, + 0x01ea, + 0x01ec, + 0x01ee, + 0x01f1, + 0x01f4, + 0x01fa, + 0x01fc, + 0x01fe, + 0x0200, + 0x0202, + 0x0204, + 0x0206, + 0x0208, + 0x020a, + 0x020c, + 0x020e, + 0x0210, + 0x0212, + 0x0214, + 0x0216, + 0x0218, + 0x021a, + 0x021c, + 0x021e, + 0x0220, + 0x0222, + 0x0224, + 0x0226, + 0x0228, + 0x022a, + 0x022c, + 0x022e, + 0x0230, + 0x0232, + 0x0241, + 0x0248, + 0x024a, + 0x024c, + 0x024e, + 0x0370, + 0x0372, + 0x0376, + 0x037f, + 0x0386, + 0x038c, + 0x03cf, + 0x03d8, + 0x03da, + 0x03dc, + 0x03de, + 0x03e0, + 0x03e2, + 0x03e4, + 0x03e6, + 0x03e8, + 0x03ea, + 0x03ec, + 0x03ee, + 0x03f4, + 0x03f7, + 0x0460, + 0x0462, + 0x0464, + 0x0466, + 0x0468, + 0x046a, + 0x046c, + 0x046e, + 0x0470, + 0x0472, + 0x0474, + 0x0476, + 0x0478, + 0x047a, + 0x047c, + 0x047e, + 0x0480, + 0x048a, + 0x048c, + 0x048e, + 0x0490, + 0x0492, + 0x0494, + 0x0496, + 0x0498, + 0x049a, + 0x049c, + 0x049e, + 0x04a0, + 0x04a2, + 0x04a4, + 0x04a6, + 0x04a8, + 0x04aa, + 0x04ac, + 0x04ae, + 0x04b0, + 0x04b2, + 0x04b4, + 0x04b6, + 0x04b8, + 0x04ba, + 0x04bc, + 0x04be, + 0x04c3, + 0x04c5, + 0x04c7, + 0x04c9, + 0x04cb, + 0x04cd, + 0x04d0, + 0x04d2, + 0x04d4, + 0x04d6, + 0x04d8, + 0x04da, + 0x04dc, + 0x04de, + 0x04e0, + 0x04e2, + 0x04e4, + 0x04e6, + 0x04e8, + 0x04ea, + 0x04ec, + 0x04ee, + 0x04f0, + 0x04f2, + 0x04f4, + 0x04f6, + 0x04f8, + 0x04fa, + 0x04fc, + 0x04fe, + 0x0500, + 0x0502, + 0x0504, + 0x0506, + 0x0508, + 0x050a, + 0x050c, + 0x050e, + 0x0510, + 0x0512, + 0x0514, + 0x0516, + 0x0518, + 0x051a, + 0x051c, + 0x051e, + 0x0520, + 0x0522, + 0x0524, + 0x0526, + 0x0528, + 0x052a, + 0x052c, + 0x052e, + 0x10c7, + 0x10cd, + 0x1e00, + 0x1e02, + 0x1e04, + 0x1e06, + 0x1e08, + 0x1e0a, + 0x1e0c, + 0x1e0e, + 0x1e10, + 0x1e12, + 0x1e14, + 0x1e16, + 0x1e18, + 0x1e1a, + 0x1e1c, + 0x1e1e, + 0x1e20, + 0x1e22, + 0x1e24, + 0x1e26, + 0x1e28, + 0x1e2a, + 0x1e2c, + 0x1e2e, + 0x1e30, + 0x1e32, + 0x1e34, + 0x1e36, + 0x1e38, + 0x1e3a, + 0x1e3c, + 0x1e3e, + 0x1e40, + 0x1e42, + 0x1e44, + 0x1e46, + 0x1e48, + 0x1e4a, + 0x1e4c, + 0x1e4e, + 0x1e50, + 0x1e52, + 0x1e54, + 0x1e56, + 0x1e58, + 0x1e5a, + 0x1e5c, + 0x1e5e, + 0x1e60, + 0x1e62, + 0x1e64, + 0x1e66, + 0x1e68, + 0x1e6a, + 0x1e6c, + 0x1e6e, + 0x1e70, + 0x1e72, + 0x1e74, + 0x1e76, + 0x1e78, + 0x1e7a, + 0x1e7c, + 0x1e7e, + 0x1e80, + 0x1e82, + 0x1e84, + 0x1e86, + 0x1e88, + 0x1e8a, + 0x1e8c, + 0x1e8e, + 0x1e90, + 0x1e92, + 0x1e94, + 0x1e9e, + 0x1ea0, + 0x1ea2, + 0x1ea4, + 0x1ea6, + 0x1ea8, + 0x1eaa, + 0x1eac, + 0x1eae, + 0x1eb0, + 0x1eb2, + 0x1eb4, + 0x1eb6, + 0x1eb8, + 0x1eba, + 0x1ebc, + 0x1ebe, + 0x1ec0, + 0x1ec2, + 0x1ec4, + 0x1ec6, + 0x1ec8, + 0x1eca, + 0x1ecc, + 0x1ece, + 0x1ed0, + 0x1ed2, + 0x1ed4, + 0x1ed6, + 0x1ed8, + 0x1eda, + 0x1edc, + 0x1ede, + 0x1ee0, + 0x1ee2, + 0x1ee4, + 0x1ee6, + 0x1ee8, + 0x1eea, + 0x1eec, + 0x1eee, + 0x1ef0, + 0x1ef2, + 0x1ef4, + 0x1ef6, + 0x1ef8, + 0x1efa, + 0x1efc, + 0x1efe, + 0x1f59, + 0x1f5b, + 0x1f5d, + 0x1f5f, + 0x2102, + 0x2107, + 0x2115, + 0x2124, + 0x2126, + 0x2128, + 0x2145, + 0x2183, + 0x2c60, + 0x2c67, + 0x2c69, + 0x2c6b, + 0x2c72, + 0x2c75, + 0x2c82, + 0x2c84, + 0x2c86, + 0x2c88, + 0x2c8a, + 0x2c8c, + 0x2c8e, + 0x2c90, + 0x2c92, + 0x2c94, + 0x2c96, + 0x2c98, + 0x2c9a, + 0x2c9c, + 0x2c9e, + 0x2ca0, + 0x2ca2, + 0x2ca4, + 0x2ca6, + 0x2ca8, + 0x2caa, + 0x2cac, + 0x2cae, + 0x2cb0, + 0x2cb2, + 0x2cb4, + 0x2cb6, + 0x2cb8, + 0x2cba, + 0x2cbc, + 0x2cbe, + 0x2cc0, + 0x2cc2, + 0x2cc4, + 0x2cc6, + 0x2cc8, + 0x2cca, + 0x2ccc, + 0x2cce, + 0x2cd0, + 0x2cd2, + 0x2cd4, + 0x2cd6, + 0x2cd8, + 0x2cda, + 0x2cdc, + 0x2cde, + 0x2ce0, + 0x2ce2, + 0x2ceb, + 0x2ced, + 0x2cf2, + 0xa640, + 0xa642, + 0xa644, + 0xa646, + 0xa648, + 0xa64a, + 0xa64c, + 0xa64e, + 0xa650, + 0xa652, + 0xa654, + 0xa656, + 0xa658, + 0xa65a, + 0xa65c, + 0xa65e, + 0xa660, + 0xa662, + 0xa664, + 0xa666, + 0xa668, + 0xa66a, + 0xa66c, + 0xa680, + 0xa682, + 0xa684, + 0xa686, + 0xa688, + 0xa68a, + 0xa68c, + 0xa68e, + 0xa690, + 0xa692, + 0xa694, + 0xa696, + 0xa698, + 0xa69a, + 0xa722, + 0xa724, + 0xa726, + 0xa728, + 0xa72a, + 0xa72c, + 0xa72e, + 0xa732, + 0xa734, + 0xa736, + 0xa738, + 0xa73a, + 0xa73c, + 0xa73e, + 0xa740, + 0xa742, + 0xa744, + 0xa746, + 0xa748, + 0xa74a, + 0xa74c, + 0xa74e, + 0xa750, + 0xa752, + 0xa754, + 0xa756, + 0xa758, + 0xa75a, + 0xa75c, + 0xa75e, + 0xa760, + 0xa762, + 0xa764, + 0xa766, + 0xa768, + 0xa76a, + 0xa76c, + 0xa76e, + 0xa779, + 0xa77b, + 0xa780, + 0xa782, + 0xa784, + 0xa786, + 0xa78b, + 0xa78d, + 0xa790, + 0xa792, + 0xa796, + 0xa798, + 0xa79a, + 0xa79c, + 0xa79e, + 0xa7a0, + 0xa7a2, + 0xa7a4, + 0xa7a6, + 0xa7a8, + 0x1d49c, + 0x1d4a2, + 0x1d546, + 0x1d7ca, }; } // !namespace bool isupper(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, isupperr, nelem (isupperr)/2, 2); + p = rbsearch(c, isupperr, nelem (isupperr)/2, 2); - if (p && c >= p[0] && c <= p[1]) - return true; + if (p && c >= p[0] && c <= p[1]) + return true; - p = rbsearch(c, isuppers, nelem (isuppers), 1); + p = rbsearch(c, isuppers, nelem (isuppers), 1); - if (p && c == p[0]) - return true; + if (p && c == p[0]) + return true; - return false; + return false; } namespace { const char32_t islowerr[] = { - 0x0061, 0x007a, - 0x00df, 0x00f6, - 0x00f8, 0x00ff, - 0x0137, 0x0138, - 0x0148, 0x0149, - 0x017e, 0x0180, - 0x018c, 0x018d, - 0x0199, 0x019b, - 0x01aa, 0x01ab, - 0x01b9, 0x01ba, - 0x01bd, 0x01bf, - 0x01dc, 0x01dd, - 0x01ef, 0x01f0, - 0x0233, 0x0239, - 0x023f, 0x0240, - 0x024f, 0x0293, - 0x0295, 0x02af, - 0x037b, 0x037d, - 0x03ac, 0x03ce, - 0x03d0, 0x03d1, - 0x03d5, 0x03d7, - 0x03ef, 0x03f3, - 0x03fb, 0x03fc, - 0x0430, 0x045f, - 0x04ce, 0x04cf, - 0x0561, 0x0587, - 0x1d00, 0x1d2b, - 0x1d6b, 0x1d77, - 0x1d79, 0x1d9a, - 0x1e95, 0x1e9d, - 0x1eff, 0x1f07, - 0x1f10, 0x1f15, - 0x1f20, 0x1f27, - 0x1f30, 0x1f37, - 0x1f40, 0x1f45, - 0x1f50, 0x1f57, - 0x1f60, 0x1f67, - 0x1f70, 0x1f7d, - 0x1f80, 0x1f87, - 0x1f90, 0x1f97, - 0x1fa0, 0x1fa7, - 0x1fb0, 0x1fb4, - 0x1fb6, 0x1fb7, - 0x1fc2, 0x1fc4, - 0x1fc6, 0x1fc7, - 0x1fd0, 0x1fd3, - 0x1fd6, 0x1fd7, - 0x1fe0, 0x1fe7, - 0x1ff2, 0x1ff4, - 0x1ff6, 0x1ff7, - 0x210e, 0x210f, - 0x213c, 0x213d, - 0x2146, 0x2149, - 0x2170, 0x217f, - 0x24d0, 0x24e9, - 0x2c30, 0x2c5e, - 0x2c65, 0x2c66, - 0x2c73, 0x2c74, - 0x2c76, 0x2c7b, - 0x2ce3, 0x2ce4, - 0x2d00, 0x2d25, - 0xa72f, 0xa731, - 0xa771, 0xa778, - 0xa793, 0xa795, - 0xab30, 0xab5a, - 0xab64, 0xab65, - 0xfb00, 0xfb06, - 0xfb13, 0xfb17, - 0xff41, 0xff5a, - 0x10428, 0x1044f, - 0x118c0, 0x118df, - 0x1d41a, 0x1d433, - 0x1d44e, 0x1d454, - 0x1d456, 0x1d467, - 0x1d482, 0x1d49b, - 0x1d4b6, 0x1d4b9, - 0x1d4bd, 0x1d4c3, - 0x1d4c5, 0x1d4cf, - 0x1d4ea, 0x1d503, - 0x1d51e, 0x1d537, - 0x1d552, 0x1d56b, - 0x1d586, 0x1d59f, - 0x1d5ba, 0x1d5d3, - 0x1d5ee, 0x1d607, - 0x1d622, 0x1d63b, - 0x1d656, 0x1d66f, - 0x1d68a, 0x1d6a5, - 0x1d6c2, 0x1d6da, - 0x1d6dc, 0x1d6e1, - 0x1d6fc, 0x1d714, - 0x1d716, 0x1d71b, - 0x1d736, 0x1d74e, - 0x1d750, 0x1d755, - 0x1d770, 0x1d788, - 0x1d78a, 0x1d78f, - 0x1d7aa, 0x1d7c2, - 0x1d7c4, 0x1d7c9, + 0x0061, 0x007a, + 0x00df, 0x00f6, + 0x00f8, 0x00ff, + 0x0137, 0x0138, + 0x0148, 0x0149, + 0x017e, 0x0180, + 0x018c, 0x018d, + 0x0199, 0x019b, + 0x01aa, 0x01ab, + 0x01b9, 0x01ba, + 0x01bd, 0x01bf, + 0x01dc, 0x01dd, + 0x01ef, 0x01f0, + 0x0233, 0x0239, + 0x023f, 0x0240, + 0x024f, 0x0293, + 0x0295, 0x02af, + 0x037b, 0x037d, + 0x03ac, 0x03ce, + 0x03d0, 0x03d1, + 0x03d5, 0x03d7, + 0x03ef, 0x03f3, + 0x03fb, 0x03fc, + 0x0430, 0x045f, + 0x04ce, 0x04cf, + 0x0561, 0x0587, + 0x1d00, 0x1d2b, + 0x1d6b, 0x1d77, + 0x1d79, 0x1d9a, + 0x1e95, 0x1e9d, + 0x1eff, 0x1f07, + 0x1f10, 0x1f15, + 0x1f20, 0x1f27, + 0x1f30, 0x1f37, + 0x1f40, 0x1f45, + 0x1f50, 0x1f57, + 0x1f60, 0x1f67, + 0x1f70, 0x1f7d, + 0x1f80, 0x1f87, + 0x1f90, 0x1f97, + 0x1fa0, 0x1fa7, + 0x1fb0, 0x1fb4, + 0x1fb6, 0x1fb7, + 0x1fc2, 0x1fc4, + 0x1fc6, 0x1fc7, + 0x1fd0, 0x1fd3, + 0x1fd6, 0x1fd7, + 0x1fe0, 0x1fe7, + 0x1ff2, 0x1ff4, + 0x1ff6, 0x1ff7, + 0x210e, 0x210f, + 0x213c, 0x213d, + 0x2146, 0x2149, + 0x2170, 0x217f, + 0x24d0, 0x24e9, + 0x2c30, 0x2c5e, + 0x2c65, 0x2c66, + 0x2c73, 0x2c74, + 0x2c76, 0x2c7b, + 0x2ce3, 0x2ce4, + 0x2d00, 0x2d25, + 0xa72f, 0xa731, + 0xa771, 0xa778, + 0xa793, 0xa795, + 0xab30, 0xab5a, + 0xab64, 0xab65, + 0xfb00, 0xfb06, + 0xfb13, 0xfb17, + 0xff41, 0xff5a, + 0x10428, 0x1044f, + 0x118c0, 0x118df, + 0x1d41a, 0x1d433, + 0x1d44e, 0x1d454, + 0x1d456, 0x1d467, + 0x1d482, 0x1d49b, + 0x1d4b6, 0x1d4b9, + 0x1d4bd, 0x1d4c3, + 0x1d4c5, 0x1d4cf, + 0x1d4ea, 0x1d503, + 0x1d51e, 0x1d537, + 0x1d552, 0x1d56b, + 0x1d586, 0x1d59f, + 0x1d5ba, 0x1d5d3, + 0x1d5ee, 0x1d607, + 0x1d622, 0x1d63b, + 0x1d656, 0x1d66f, + 0x1d68a, 0x1d6a5, + 0x1d6c2, 0x1d6da, + 0x1d6dc, 0x1d6e1, + 0x1d6fc, 0x1d714, + 0x1d716, 0x1d71b, + 0x1d736, 0x1d74e, + 0x1d750, 0x1d755, + 0x1d770, 0x1d788, + 0x1d78a, 0x1d78f, + 0x1d7aa, 0x1d7c2, + 0x1d7c4, 0x1d7c9, }; } // !namespace @@ -1485,615 +1485,615 @@ namespace { const char32_t islowers[] = { - 0x00b5, - 0x0101, - 0x0103, - 0x0105, - 0x0107, - 0x0109, - 0x010b, - 0x010d, - 0x010f, - 0x0111, - 0x0113, - 0x0115, - 0x0117, - 0x0119, - 0x011b, - 0x011d, - 0x011f, - 0x0121, - 0x0123, - 0x0125, - 0x0127, - 0x0129, - 0x012b, - 0x012d, - 0x012f, - 0x0131, - 0x0133, - 0x0135, - 0x013a, - 0x013c, - 0x013e, - 0x0140, - 0x0142, - 0x0144, - 0x0146, - 0x014b, - 0x014d, - 0x014f, - 0x0151, - 0x0153, - 0x0155, - 0x0157, - 0x0159, - 0x015b, - 0x015d, - 0x015f, - 0x0161, - 0x0163, - 0x0165, - 0x0167, - 0x0169, - 0x016b, - 0x016d, - 0x016f, - 0x0171, - 0x0173, - 0x0175, - 0x0177, - 0x017a, - 0x017c, - 0x0183, - 0x0185, - 0x0188, - 0x0192, - 0x0195, - 0x019e, - 0x01a1, - 0x01a3, - 0x01a5, - 0x01a8, - 0x01ad, - 0x01b0, - 0x01b4, - 0x01b6, - 0x01c6, - 0x01c9, - 0x01cc, - 0x01ce, - 0x01d0, - 0x01d2, - 0x01d4, - 0x01d6, - 0x01d8, - 0x01da, - 0x01df, - 0x01e1, - 0x01e3, - 0x01e5, - 0x01e7, - 0x01e9, - 0x01eb, - 0x01ed, - 0x01f3, - 0x01f5, - 0x01f9, - 0x01fb, - 0x01fd, - 0x01ff, - 0x0201, - 0x0203, - 0x0205, - 0x0207, - 0x0209, - 0x020b, - 0x020d, - 0x020f, - 0x0211, - 0x0213, - 0x0215, - 0x0217, - 0x0219, - 0x021b, - 0x021d, - 0x021f, - 0x0221, - 0x0223, - 0x0225, - 0x0227, - 0x0229, - 0x022b, - 0x022d, - 0x022f, - 0x0231, - 0x023c, - 0x0242, - 0x0247, - 0x0249, - 0x024b, - 0x024d, - 0x0371, - 0x0373, - 0x0377, - 0x0390, - 0x03d9, - 0x03db, - 0x03dd, - 0x03df, - 0x03e1, - 0x03e3, - 0x03e5, - 0x03e7, - 0x03e9, - 0x03eb, - 0x03ed, - 0x03f5, - 0x03f8, - 0x0461, - 0x0463, - 0x0465, - 0x0467, - 0x0469, - 0x046b, - 0x046d, - 0x046f, - 0x0471, - 0x0473, - 0x0475, - 0x0477, - 0x0479, - 0x047b, - 0x047d, - 0x047f, - 0x0481, - 0x048b, - 0x048d, - 0x048f, - 0x0491, - 0x0493, - 0x0495, - 0x0497, - 0x0499, - 0x049b, - 0x049d, - 0x049f, - 0x04a1, - 0x04a3, - 0x04a5, - 0x04a7, - 0x04a9, - 0x04ab, - 0x04ad, - 0x04af, - 0x04b1, - 0x04b3, - 0x04b5, - 0x04b7, - 0x04b9, - 0x04bb, - 0x04bd, - 0x04bf, - 0x04c2, - 0x04c4, - 0x04c6, - 0x04c8, - 0x04ca, - 0x04cc, - 0x04d1, - 0x04d3, - 0x04d5, - 0x04d7, - 0x04d9, - 0x04db, - 0x04dd, - 0x04df, - 0x04e1, - 0x04e3, - 0x04e5, - 0x04e7, - 0x04e9, - 0x04eb, - 0x04ed, - 0x04ef, - 0x04f1, - 0x04f3, - 0x04f5, - 0x04f7, - 0x04f9, - 0x04fb, - 0x04fd, - 0x04ff, - 0x0501, - 0x0503, - 0x0505, - 0x0507, - 0x0509, - 0x050b, - 0x050d, - 0x050f, - 0x0511, - 0x0513, - 0x0515, - 0x0517, - 0x0519, - 0x051b, - 0x051d, - 0x051f, - 0x0521, - 0x0523, - 0x0525, - 0x0527, - 0x0529, - 0x052b, - 0x052d, - 0x052f, - 0x1e01, - 0x1e03, - 0x1e05, - 0x1e07, - 0x1e09, - 0x1e0b, - 0x1e0d, - 0x1e0f, - 0x1e11, - 0x1e13, - 0x1e15, - 0x1e17, - 0x1e19, - 0x1e1b, - 0x1e1d, - 0x1e1f, - 0x1e21, - 0x1e23, - 0x1e25, - 0x1e27, - 0x1e29, - 0x1e2b, - 0x1e2d, - 0x1e2f, - 0x1e31, - 0x1e33, - 0x1e35, - 0x1e37, - 0x1e39, - 0x1e3b, - 0x1e3d, - 0x1e3f, - 0x1e41, - 0x1e43, - 0x1e45, - 0x1e47, - 0x1e49, - 0x1e4b, - 0x1e4d, - 0x1e4f, - 0x1e51, - 0x1e53, - 0x1e55, - 0x1e57, - 0x1e59, - 0x1e5b, - 0x1e5d, - 0x1e5f, - 0x1e61, - 0x1e63, - 0x1e65, - 0x1e67, - 0x1e69, - 0x1e6b, - 0x1e6d, - 0x1e6f, - 0x1e71, - 0x1e73, - 0x1e75, - 0x1e77, - 0x1e79, - 0x1e7b, - 0x1e7d, - 0x1e7f, - 0x1e81, - 0x1e83, - 0x1e85, - 0x1e87, - 0x1e89, - 0x1e8b, - 0x1e8d, - 0x1e8f, - 0x1e91, - 0x1e93, - 0x1e9f, - 0x1ea1, - 0x1ea3, - 0x1ea5, - 0x1ea7, - 0x1ea9, - 0x1eab, - 0x1ead, - 0x1eaf, - 0x1eb1, - 0x1eb3, - 0x1eb5, - 0x1eb7, - 0x1eb9, - 0x1ebb, - 0x1ebd, - 0x1ebf, - 0x1ec1, - 0x1ec3, - 0x1ec5, - 0x1ec7, - 0x1ec9, - 0x1ecb, - 0x1ecd, - 0x1ecf, - 0x1ed1, - 0x1ed3, - 0x1ed5, - 0x1ed7, - 0x1ed9, - 0x1edb, - 0x1edd, - 0x1edf, - 0x1ee1, - 0x1ee3, - 0x1ee5, - 0x1ee7, - 0x1ee9, - 0x1eeb, - 0x1eed, - 0x1eef, - 0x1ef1, - 0x1ef3, - 0x1ef5, - 0x1ef7, - 0x1ef9, - 0x1efb, - 0x1efd, - 0x1fbe, - 0x210a, - 0x2113, - 0x212f, - 0x2134, - 0x2139, - 0x214e, - 0x2184, - 0x2c61, - 0x2c68, - 0x2c6a, - 0x2c6c, - 0x2c71, - 0x2c81, - 0x2c83, - 0x2c85, - 0x2c87, - 0x2c89, - 0x2c8b, - 0x2c8d, - 0x2c8f, - 0x2c91, - 0x2c93, - 0x2c95, - 0x2c97, - 0x2c99, - 0x2c9b, - 0x2c9d, - 0x2c9f, - 0x2ca1, - 0x2ca3, - 0x2ca5, - 0x2ca7, - 0x2ca9, - 0x2cab, - 0x2cad, - 0x2caf, - 0x2cb1, - 0x2cb3, - 0x2cb5, - 0x2cb7, - 0x2cb9, - 0x2cbb, - 0x2cbd, - 0x2cbf, - 0x2cc1, - 0x2cc3, - 0x2cc5, - 0x2cc7, - 0x2cc9, - 0x2ccb, - 0x2ccd, - 0x2ccf, - 0x2cd1, - 0x2cd3, - 0x2cd5, - 0x2cd7, - 0x2cd9, - 0x2cdb, - 0x2cdd, - 0x2cdf, - 0x2ce1, - 0x2cec, - 0x2cee, - 0x2cf3, - 0x2d27, - 0x2d2d, - 0xa641, - 0xa643, - 0xa645, - 0xa647, - 0xa649, - 0xa64b, - 0xa64d, - 0xa64f, - 0xa651, - 0xa653, - 0xa655, - 0xa657, - 0xa659, - 0xa65b, - 0xa65d, - 0xa65f, - 0xa661, - 0xa663, - 0xa665, - 0xa667, - 0xa669, - 0xa66b, - 0xa66d, - 0xa681, - 0xa683, - 0xa685, - 0xa687, - 0xa689, - 0xa68b, - 0xa68d, - 0xa68f, - 0xa691, - 0xa693, - 0xa695, - 0xa697, - 0xa699, - 0xa69b, - 0xa723, - 0xa725, - 0xa727, - 0xa729, - 0xa72b, - 0xa72d, - 0xa733, - 0xa735, - 0xa737, - 0xa739, - 0xa73b, - 0xa73d, - 0xa73f, - 0xa741, - 0xa743, - 0xa745, - 0xa747, - 0xa749, - 0xa74b, - 0xa74d, - 0xa74f, - 0xa751, - 0xa753, - 0xa755, - 0xa757, - 0xa759, - 0xa75b, - 0xa75d, - 0xa75f, - 0xa761, - 0xa763, - 0xa765, - 0xa767, - 0xa769, - 0xa76b, - 0xa76d, - 0xa76f, - 0xa77a, - 0xa77c, - 0xa77f, - 0xa781, - 0xa783, - 0xa785, - 0xa787, - 0xa78c, - 0xa78e, - 0xa791, - 0xa797, - 0xa799, - 0xa79b, - 0xa79d, - 0xa79f, - 0xa7a1, - 0xa7a3, - 0xa7a5, - 0xa7a7, - 0xa7a9, - 0xa7fa, - 0x1d4bb, - 0x1d7cb, + 0x00b5, + 0x0101, + 0x0103, + 0x0105, + 0x0107, + 0x0109, + 0x010b, + 0x010d, + 0x010f, + 0x0111, + 0x0113, + 0x0115, + 0x0117, + 0x0119, + 0x011b, + 0x011d, + 0x011f, + 0x0121, + 0x0123, + 0x0125, + 0x0127, + 0x0129, + 0x012b, + 0x012d, + 0x012f, + 0x0131, + 0x0133, + 0x0135, + 0x013a, + 0x013c, + 0x013e, + 0x0140, + 0x0142, + 0x0144, + 0x0146, + 0x014b, + 0x014d, + 0x014f, + 0x0151, + 0x0153, + 0x0155, + 0x0157, + 0x0159, + 0x015b, + 0x015d, + 0x015f, + 0x0161, + 0x0163, + 0x0165, + 0x0167, + 0x0169, + 0x016b, + 0x016d, + 0x016f, + 0x0171, + 0x0173, + 0x0175, + 0x0177, + 0x017a, + 0x017c, + 0x0183, + 0x0185, + 0x0188, + 0x0192, + 0x0195, + 0x019e, + 0x01a1, + 0x01a3, + 0x01a5, + 0x01a8, + 0x01ad, + 0x01b0, + 0x01b4, + 0x01b6, + 0x01c6, + 0x01c9, + 0x01cc, + 0x01ce, + 0x01d0, + 0x01d2, + 0x01d4, + 0x01d6, + 0x01d8, + 0x01da, + 0x01df, + 0x01e1, + 0x01e3, + 0x01e5, + 0x01e7, + 0x01e9, + 0x01eb, + 0x01ed, + 0x01f3, + 0x01f5, + 0x01f9, + 0x01fb, + 0x01fd, + 0x01ff, + 0x0201, + 0x0203, + 0x0205, + 0x0207, + 0x0209, + 0x020b, + 0x020d, + 0x020f, + 0x0211, + 0x0213, + 0x0215, + 0x0217, + 0x0219, + 0x021b, + 0x021d, + 0x021f, + 0x0221, + 0x0223, + 0x0225, + 0x0227, + 0x0229, + 0x022b, + 0x022d, + 0x022f, + 0x0231, + 0x023c, + 0x0242, + 0x0247, + 0x0249, + 0x024b, + 0x024d, + 0x0371, + 0x0373, + 0x0377, + 0x0390, + 0x03d9, + 0x03db, + 0x03dd, + 0x03df, + 0x03e1, + 0x03e3, + 0x03e5, + 0x03e7, + 0x03e9, + 0x03eb, + 0x03ed, + 0x03f5, + 0x03f8, + 0x0461, + 0x0463, + 0x0465, + 0x0467, + 0x0469, + 0x046b, + 0x046d, + 0x046f, + 0x0471, + 0x0473, + 0x0475, + 0x0477, + 0x0479, + 0x047b, + 0x047d, + 0x047f, + 0x0481, + 0x048b, + 0x048d, + 0x048f, + 0x0491, + 0x0493, + 0x0495, + 0x0497, + 0x0499, + 0x049b, + 0x049d, + 0x049f, + 0x04a1, + 0x04a3, + 0x04a5, + 0x04a7, + 0x04a9, + 0x04ab, + 0x04ad, + 0x04af, + 0x04b1, + 0x04b3, + 0x04b5, + 0x04b7, + 0x04b9, + 0x04bb, + 0x04bd, + 0x04bf, + 0x04c2, + 0x04c4, + 0x04c6, + 0x04c8, + 0x04ca, + 0x04cc, + 0x04d1, + 0x04d3, + 0x04d5, + 0x04d7, + 0x04d9, + 0x04db, + 0x04dd, + 0x04df, + 0x04e1, + 0x04e3, + 0x04e5, + 0x04e7, + 0x04e9, + 0x04eb, + 0x04ed, + 0x04ef, + 0x04f1, + 0x04f3, + 0x04f5, + 0x04f7, + 0x04f9, + 0x04fb, + 0x04fd, + 0x04ff, + 0x0501, + 0x0503, + 0x0505, + 0x0507, + 0x0509, + 0x050b, + 0x050d, + 0x050f, + 0x0511, + 0x0513, + 0x0515, + 0x0517, + 0x0519, + 0x051b, + 0x051d, + 0x051f, + 0x0521, + 0x0523, + 0x0525, + 0x0527, + 0x0529, + 0x052b, + 0x052d, + 0x052f, + 0x1e01, + 0x1e03, + 0x1e05, + 0x1e07, + 0x1e09, + 0x1e0b, + 0x1e0d, + 0x1e0f, + 0x1e11, + 0x1e13, + 0x1e15, + 0x1e17, + 0x1e19, + 0x1e1b, + 0x1e1d, + 0x1e1f, + 0x1e21, + 0x1e23, + 0x1e25, + 0x1e27, + 0x1e29, + 0x1e2b, + 0x1e2d, + 0x1e2f, + 0x1e31, + 0x1e33, + 0x1e35, + 0x1e37, + 0x1e39, + 0x1e3b, + 0x1e3d, + 0x1e3f, + 0x1e41, + 0x1e43, + 0x1e45, + 0x1e47, + 0x1e49, + 0x1e4b, + 0x1e4d, + 0x1e4f, + 0x1e51, + 0x1e53, + 0x1e55, + 0x1e57, + 0x1e59, + 0x1e5b, + 0x1e5d, + 0x1e5f, + 0x1e61, + 0x1e63, + 0x1e65, + 0x1e67, + 0x1e69, + 0x1e6b, + 0x1e6d, + 0x1e6f, + 0x1e71, + 0x1e73, + 0x1e75, + 0x1e77, + 0x1e79, + 0x1e7b, + 0x1e7d, + 0x1e7f, + 0x1e81, + 0x1e83, + 0x1e85, + 0x1e87, + 0x1e89, + 0x1e8b, + 0x1e8d, + 0x1e8f, + 0x1e91, + 0x1e93, + 0x1e9f, + 0x1ea1, + 0x1ea3, + 0x1ea5, + 0x1ea7, + 0x1ea9, + 0x1eab, + 0x1ead, + 0x1eaf, + 0x1eb1, + 0x1eb3, + 0x1eb5, + 0x1eb7, + 0x1eb9, + 0x1ebb, + 0x1ebd, + 0x1ebf, + 0x1ec1, + 0x1ec3, + 0x1ec5, + 0x1ec7, + 0x1ec9, + 0x1ecb, + 0x1ecd, + 0x1ecf, + 0x1ed1, + 0x1ed3, + 0x1ed5, + 0x1ed7, + 0x1ed9, + 0x1edb, + 0x1edd, + 0x1edf, + 0x1ee1, + 0x1ee3, + 0x1ee5, + 0x1ee7, + 0x1ee9, + 0x1eeb, + 0x1eed, + 0x1eef, + 0x1ef1, + 0x1ef3, + 0x1ef5, + 0x1ef7, + 0x1ef9, + 0x1efb, + 0x1efd, + 0x1fbe, + 0x210a, + 0x2113, + 0x212f, + 0x2134, + 0x2139, + 0x214e, + 0x2184, + 0x2c61, + 0x2c68, + 0x2c6a, + 0x2c6c, + 0x2c71, + 0x2c81, + 0x2c83, + 0x2c85, + 0x2c87, + 0x2c89, + 0x2c8b, + 0x2c8d, + 0x2c8f, + 0x2c91, + 0x2c93, + 0x2c95, + 0x2c97, + 0x2c99, + 0x2c9b, + 0x2c9d, + 0x2c9f, + 0x2ca1, + 0x2ca3, + 0x2ca5, + 0x2ca7, + 0x2ca9, + 0x2cab, + 0x2cad, + 0x2caf, + 0x2cb1, + 0x2cb3, + 0x2cb5, + 0x2cb7, + 0x2cb9, + 0x2cbb, + 0x2cbd, + 0x2cbf, + 0x2cc1, + 0x2cc3, + 0x2cc5, + 0x2cc7, + 0x2cc9, + 0x2ccb, + 0x2ccd, + 0x2ccf, + 0x2cd1, + 0x2cd3, + 0x2cd5, + 0x2cd7, + 0x2cd9, + 0x2cdb, + 0x2cdd, + 0x2cdf, + 0x2ce1, + 0x2cec, + 0x2cee, + 0x2cf3, + 0x2d27, + 0x2d2d, + 0xa641, + 0xa643, + 0xa645, + 0xa647, + 0xa649, + 0xa64b, + 0xa64d, + 0xa64f, + 0xa651, + 0xa653, + 0xa655, + 0xa657, + 0xa659, + 0xa65b, + 0xa65d, + 0xa65f, + 0xa661, + 0xa663, + 0xa665, + 0xa667, + 0xa669, + 0xa66b, + 0xa66d, + 0xa681, + 0xa683, + 0xa685, + 0xa687, + 0xa689, + 0xa68b, + 0xa68d, + 0xa68f, + 0xa691, + 0xa693, + 0xa695, + 0xa697, + 0xa699, + 0xa69b, + 0xa723, + 0xa725, + 0xa727, + 0xa729, + 0xa72b, + 0xa72d, + 0xa733, + 0xa735, + 0xa737, + 0xa739, + 0xa73b, + 0xa73d, + 0xa73f, + 0xa741, + 0xa743, + 0xa745, + 0xa747, + 0xa749, + 0xa74b, + 0xa74d, + 0xa74f, + 0xa751, + 0xa753, + 0xa755, + 0xa757, + 0xa759, + 0xa75b, + 0xa75d, + 0xa75f, + 0xa761, + 0xa763, + 0xa765, + 0xa767, + 0xa769, + 0xa76b, + 0xa76d, + 0xa76f, + 0xa77a, + 0xa77c, + 0xa77f, + 0xa781, + 0xa783, + 0xa785, + 0xa787, + 0xa78c, + 0xa78e, + 0xa791, + 0xa797, + 0xa799, + 0xa79b, + 0xa79d, + 0xa79f, + 0xa7a1, + 0xa7a3, + 0xa7a5, + 0xa7a7, + 0xa7a9, + 0xa7fa, + 0x1d4bb, + 0x1d7cb, }; } // !namespace bool islower(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, islowerr, nelem (islowerr)/2, 2); + p = rbsearch(c, islowerr, nelem (islowerr)/2, 2); - if (p && c >= p[0] && c <= p[1]) - return true; + if (p && c >= p[0] && c <= p[1]) + return true; - p = rbsearch(c, islowers, nelem (islowers), 1); + p = rbsearch(c, islowers, nelem (islowers), 1); - if (p && c == p[0]) - return true; + if (p && c == p[0]) + return true; - return false; + return false; } namespace { const char32_t istitler[] = { - 0x0041, 0x005a, - 0x00c0, 0x00d6, - 0x00d8, 0x00de, - 0x0178, 0x0179, - 0x0181, 0x0182, - 0x0186, 0x0187, - 0x0189, 0x018b, - 0x018e, 0x0191, - 0x0193, 0x0194, - 0x0196, 0x0198, - 0x019c, 0x019d, - 0x019f, 0x01a0, - 0x01a6, 0x01a7, - 0x01ae, 0x01af, - 0x01b1, 0x01b3, - 0x01b7, 0x01b8, - 0x01f6, 0x01f8, - 0x023a, 0x023b, - 0x023d, 0x023e, - 0x0243, 0x0246, - 0x0388, 0x038a, - 0x038e, 0x038f, - 0x0391, 0x03a1, - 0x03a3, 0x03ab, - 0x03f9, 0x03fa, - 0x03fd, 0x042f, - 0x04c0, 0x04c1, - 0x0531, 0x0556, - 0x10a0, 0x10c5, - 0x1f08, 0x1f0f, - 0x1f18, 0x1f1d, - 0x1f28, 0x1f2f, - 0x1f38, 0x1f3f, - 0x1f48, 0x1f4d, - 0x1f68, 0x1f6f, - 0x1f88, 0x1f8f, - 0x1f98, 0x1f9f, - 0x1fa8, 0x1faf, - 0x1fb8, 0x1fbc, - 0x1fc8, 0x1fcc, - 0x1fd8, 0x1fdb, - 0x1fe8, 0x1fec, - 0x1ff8, 0x1ffc, - 0x2160, 0x216f, - 0x24b6, 0x24cf, - 0x2c00, 0x2c2e, - 0x2c62, 0x2c64, - 0x2c6d, 0x2c70, - 0x2c7e, 0x2c80, - 0xa77d, 0xa77e, - 0xa7aa, 0xa7ad, - 0xa7b0, 0xa7b1, - 0xff21, 0xff3a, - 0x10400, 0x10427, - 0x118a0, 0x118bf, + 0x0041, 0x005a, + 0x00c0, 0x00d6, + 0x00d8, 0x00de, + 0x0178, 0x0179, + 0x0181, 0x0182, + 0x0186, 0x0187, + 0x0189, 0x018b, + 0x018e, 0x0191, + 0x0193, 0x0194, + 0x0196, 0x0198, + 0x019c, 0x019d, + 0x019f, 0x01a0, + 0x01a6, 0x01a7, + 0x01ae, 0x01af, + 0x01b1, 0x01b3, + 0x01b7, 0x01b8, + 0x01f6, 0x01f8, + 0x023a, 0x023b, + 0x023d, 0x023e, + 0x0243, 0x0246, + 0x0388, 0x038a, + 0x038e, 0x038f, + 0x0391, 0x03a1, + 0x03a3, 0x03ab, + 0x03f9, 0x03fa, + 0x03fd, 0x042f, + 0x04c0, 0x04c1, + 0x0531, 0x0556, + 0x10a0, 0x10c5, + 0x1f08, 0x1f0f, + 0x1f18, 0x1f1d, + 0x1f28, 0x1f2f, + 0x1f38, 0x1f3f, + 0x1f48, 0x1f4d, + 0x1f68, 0x1f6f, + 0x1f88, 0x1f8f, + 0x1f98, 0x1f9f, + 0x1fa8, 0x1faf, + 0x1fb8, 0x1fbc, + 0x1fc8, 0x1fcc, + 0x1fd8, 0x1fdb, + 0x1fe8, 0x1fec, + 0x1ff8, 0x1ffc, + 0x2160, 0x216f, + 0x24b6, 0x24cf, + 0x2c00, 0x2c2e, + 0x2c62, 0x2c64, + 0x2c6d, 0x2c70, + 0x2c7e, 0x2c80, + 0xa77d, 0xa77e, + 0xa7aa, 0xa7ad, + 0xa7b0, 0xa7b1, + 0xff21, 0xff3a, + 0x10400, 0x10427, + 0x118a0, 0x118bf, }; } // !namespace @@ -2101,594 +2101,594 @@ namespace { const char32_t istitles[] = { - 0x0100, - 0x0102, - 0x0104, - 0x0106, - 0x0108, - 0x010a, - 0x010c, - 0x010e, - 0x0110, - 0x0112, - 0x0114, - 0x0116, - 0x0118, - 0x011a, - 0x011c, - 0x011e, - 0x0120, - 0x0122, - 0x0124, - 0x0126, - 0x0128, - 0x012a, - 0x012c, - 0x012e, - 0x0132, - 0x0134, - 0x0136, - 0x0139, - 0x013b, - 0x013d, - 0x013f, - 0x0141, - 0x0143, - 0x0145, - 0x0147, - 0x014a, - 0x014c, - 0x014e, - 0x0150, - 0x0152, - 0x0154, - 0x0156, - 0x0158, - 0x015a, - 0x015c, - 0x015e, - 0x0160, - 0x0162, - 0x0164, - 0x0166, - 0x0168, - 0x016a, - 0x016c, - 0x016e, - 0x0170, - 0x0172, - 0x0174, - 0x0176, - 0x017b, - 0x017d, - 0x0184, - 0x01a2, - 0x01a4, - 0x01a9, - 0x01ac, - 0x01b5, - 0x01bc, - 0x01c5, - 0x01c8, - 0x01cb, - 0x01cd, - 0x01cf, - 0x01d1, - 0x01d3, - 0x01d5, - 0x01d7, - 0x01d9, - 0x01db, - 0x01de, - 0x01e0, - 0x01e2, - 0x01e4, - 0x01e6, - 0x01e8, - 0x01ea, - 0x01ec, - 0x01ee, - 0x01f2, - 0x01f4, - 0x01fa, - 0x01fc, - 0x01fe, - 0x0200, - 0x0202, - 0x0204, - 0x0206, - 0x0208, - 0x020a, - 0x020c, - 0x020e, - 0x0210, - 0x0212, - 0x0214, - 0x0216, - 0x0218, - 0x021a, - 0x021c, - 0x021e, - 0x0220, - 0x0222, - 0x0224, - 0x0226, - 0x0228, - 0x022a, - 0x022c, - 0x022e, - 0x0230, - 0x0232, - 0x0241, - 0x0248, - 0x024a, - 0x024c, - 0x024e, - 0x0370, - 0x0372, - 0x0376, - 0x037f, - 0x0386, - 0x038c, - 0x03cf, - 0x03d8, - 0x03da, - 0x03dc, - 0x03de, - 0x03e0, - 0x03e2, - 0x03e4, - 0x03e6, - 0x03e8, - 0x03ea, - 0x03ec, - 0x03ee, - 0x03f7, - 0x0460, - 0x0462, - 0x0464, - 0x0466, - 0x0468, - 0x046a, - 0x046c, - 0x046e, - 0x0470, - 0x0472, - 0x0474, - 0x0476, - 0x0478, - 0x047a, - 0x047c, - 0x047e, - 0x0480, - 0x048a, - 0x048c, - 0x048e, - 0x0490, - 0x0492, - 0x0494, - 0x0496, - 0x0498, - 0x049a, - 0x049c, - 0x049e, - 0x04a0, - 0x04a2, - 0x04a4, - 0x04a6, - 0x04a8, - 0x04aa, - 0x04ac, - 0x04ae, - 0x04b0, - 0x04b2, - 0x04b4, - 0x04b6, - 0x04b8, - 0x04ba, - 0x04bc, - 0x04be, - 0x04c3, - 0x04c5, - 0x04c7, - 0x04c9, - 0x04cb, - 0x04cd, - 0x04d0, - 0x04d2, - 0x04d4, - 0x04d6, - 0x04d8, - 0x04da, - 0x04dc, - 0x04de, - 0x04e0, - 0x04e2, - 0x04e4, - 0x04e6, - 0x04e8, - 0x04ea, - 0x04ec, - 0x04ee, - 0x04f0, - 0x04f2, - 0x04f4, - 0x04f6, - 0x04f8, - 0x04fa, - 0x04fc, - 0x04fe, - 0x0500, - 0x0502, - 0x0504, - 0x0506, - 0x0508, - 0x050a, - 0x050c, - 0x050e, - 0x0510, - 0x0512, - 0x0514, - 0x0516, - 0x0518, - 0x051a, - 0x051c, - 0x051e, - 0x0520, - 0x0522, - 0x0524, - 0x0526, - 0x0528, - 0x052a, - 0x052c, - 0x052e, - 0x10c7, - 0x10cd, - 0x1e00, - 0x1e02, - 0x1e04, - 0x1e06, - 0x1e08, - 0x1e0a, - 0x1e0c, - 0x1e0e, - 0x1e10, - 0x1e12, - 0x1e14, - 0x1e16, - 0x1e18, - 0x1e1a, - 0x1e1c, - 0x1e1e, - 0x1e20, - 0x1e22, - 0x1e24, - 0x1e26, - 0x1e28, - 0x1e2a, - 0x1e2c, - 0x1e2e, - 0x1e30, - 0x1e32, - 0x1e34, - 0x1e36, - 0x1e38, - 0x1e3a, - 0x1e3c, - 0x1e3e, - 0x1e40, - 0x1e42, - 0x1e44, - 0x1e46, - 0x1e48, - 0x1e4a, - 0x1e4c, - 0x1e4e, - 0x1e50, - 0x1e52, - 0x1e54, - 0x1e56, - 0x1e58, - 0x1e5a, - 0x1e5c, - 0x1e5e, - 0x1e60, - 0x1e62, - 0x1e64, - 0x1e66, - 0x1e68, - 0x1e6a, - 0x1e6c, - 0x1e6e, - 0x1e70, - 0x1e72, - 0x1e74, - 0x1e76, - 0x1e78, - 0x1e7a, - 0x1e7c, - 0x1e7e, - 0x1e80, - 0x1e82, - 0x1e84, - 0x1e86, - 0x1e88, - 0x1e8a, - 0x1e8c, - 0x1e8e, - 0x1e90, - 0x1e92, - 0x1e94, - 0x1ea0, - 0x1ea2, - 0x1ea4, - 0x1ea6, - 0x1ea8, - 0x1eaa, - 0x1eac, - 0x1eae, - 0x1eb0, - 0x1eb2, - 0x1eb4, - 0x1eb6, - 0x1eb8, - 0x1eba, - 0x1ebc, - 0x1ebe, - 0x1ec0, - 0x1ec2, - 0x1ec4, - 0x1ec6, - 0x1ec8, - 0x1eca, - 0x1ecc, - 0x1ece, - 0x1ed0, - 0x1ed2, - 0x1ed4, - 0x1ed6, - 0x1ed8, - 0x1eda, - 0x1edc, - 0x1ede, - 0x1ee0, - 0x1ee2, - 0x1ee4, - 0x1ee6, - 0x1ee8, - 0x1eea, - 0x1eec, - 0x1eee, - 0x1ef0, - 0x1ef2, - 0x1ef4, - 0x1ef6, - 0x1ef8, - 0x1efa, - 0x1efc, - 0x1efe, - 0x1f59, - 0x1f5b, - 0x1f5d, - 0x1f5f, - 0x2132, - 0x2183, - 0x2c60, - 0x2c67, - 0x2c69, - 0x2c6b, - 0x2c72, - 0x2c75, - 0x2c82, - 0x2c84, - 0x2c86, - 0x2c88, - 0x2c8a, - 0x2c8c, - 0x2c8e, - 0x2c90, - 0x2c92, - 0x2c94, - 0x2c96, - 0x2c98, - 0x2c9a, - 0x2c9c, - 0x2c9e, - 0x2ca0, - 0x2ca2, - 0x2ca4, - 0x2ca6, - 0x2ca8, - 0x2caa, - 0x2cac, - 0x2cae, - 0x2cb0, - 0x2cb2, - 0x2cb4, - 0x2cb6, - 0x2cb8, - 0x2cba, - 0x2cbc, - 0x2cbe, - 0x2cc0, - 0x2cc2, - 0x2cc4, - 0x2cc6, - 0x2cc8, - 0x2cca, - 0x2ccc, - 0x2cce, - 0x2cd0, - 0x2cd2, - 0x2cd4, - 0x2cd6, - 0x2cd8, - 0x2cda, - 0x2cdc, - 0x2cde, - 0x2ce0, - 0x2ce2, - 0x2ceb, - 0x2ced, - 0x2cf2, - 0xa640, - 0xa642, - 0xa644, - 0xa646, - 0xa648, - 0xa64a, - 0xa64c, - 0xa64e, - 0xa650, - 0xa652, - 0xa654, - 0xa656, - 0xa658, - 0xa65a, - 0xa65c, - 0xa65e, - 0xa660, - 0xa662, - 0xa664, - 0xa666, - 0xa668, - 0xa66a, - 0xa66c, - 0xa680, - 0xa682, - 0xa684, - 0xa686, - 0xa688, - 0xa68a, - 0xa68c, - 0xa68e, - 0xa690, - 0xa692, - 0xa694, - 0xa696, - 0xa698, - 0xa69a, - 0xa722, - 0xa724, - 0xa726, - 0xa728, - 0xa72a, - 0xa72c, - 0xa72e, - 0xa732, - 0xa734, - 0xa736, - 0xa738, - 0xa73a, - 0xa73c, - 0xa73e, - 0xa740, - 0xa742, - 0xa744, - 0xa746, - 0xa748, - 0xa74a, - 0xa74c, - 0xa74e, - 0xa750, - 0xa752, - 0xa754, - 0xa756, - 0xa758, - 0xa75a, - 0xa75c, - 0xa75e, - 0xa760, - 0xa762, - 0xa764, - 0xa766, - 0xa768, - 0xa76a, - 0xa76c, - 0xa76e, - 0xa779, - 0xa77b, - 0xa780, - 0xa782, - 0xa784, - 0xa786, - 0xa78b, - 0xa78d, - 0xa790, - 0xa792, - 0xa796, - 0xa798, - 0xa79a, - 0xa79c, - 0xa79e, - 0xa7a0, - 0xa7a2, - 0xa7a4, - 0xa7a6, - 0xa7a8, + 0x0100, + 0x0102, + 0x0104, + 0x0106, + 0x0108, + 0x010a, + 0x010c, + 0x010e, + 0x0110, + 0x0112, + 0x0114, + 0x0116, + 0x0118, + 0x011a, + 0x011c, + 0x011e, + 0x0120, + 0x0122, + 0x0124, + 0x0126, + 0x0128, + 0x012a, + 0x012c, + 0x012e, + 0x0132, + 0x0134, + 0x0136, + 0x0139, + 0x013b, + 0x013d, + 0x013f, + 0x0141, + 0x0143, + 0x0145, + 0x0147, + 0x014a, + 0x014c, + 0x014e, + 0x0150, + 0x0152, + 0x0154, + 0x0156, + 0x0158, + 0x015a, + 0x015c, + 0x015e, + 0x0160, + 0x0162, + 0x0164, + 0x0166, + 0x0168, + 0x016a, + 0x016c, + 0x016e, + 0x0170, + 0x0172, + 0x0174, + 0x0176, + 0x017b, + 0x017d, + 0x0184, + 0x01a2, + 0x01a4, + 0x01a9, + 0x01ac, + 0x01b5, + 0x01bc, + 0x01c5, + 0x01c8, + 0x01cb, + 0x01cd, + 0x01cf, + 0x01d1, + 0x01d3, + 0x01d5, + 0x01d7, + 0x01d9, + 0x01db, + 0x01de, + 0x01e0, + 0x01e2, + 0x01e4, + 0x01e6, + 0x01e8, + 0x01ea, + 0x01ec, + 0x01ee, + 0x01f2, + 0x01f4, + 0x01fa, + 0x01fc, + 0x01fe, + 0x0200, + 0x0202, + 0x0204, + 0x0206, + 0x0208, + 0x020a, + 0x020c, + 0x020e, + 0x0210, + 0x0212, + 0x0214, + 0x0216, + 0x0218, + 0x021a, + 0x021c, + 0x021e, + 0x0220, + 0x0222, + 0x0224, + 0x0226, + 0x0228, + 0x022a, + 0x022c, + 0x022e, + 0x0230, + 0x0232, + 0x0241, + 0x0248, + 0x024a, + 0x024c, + 0x024e, + 0x0370, + 0x0372, + 0x0376, + 0x037f, + 0x0386, + 0x038c, + 0x03cf, + 0x03d8, + 0x03da, + 0x03dc, + 0x03de, + 0x03e0, + 0x03e2, + 0x03e4, + 0x03e6, + 0x03e8, + 0x03ea, + 0x03ec, + 0x03ee, + 0x03f7, + 0x0460, + 0x0462, + 0x0464, + 0x0466, + 0x0468, + 0x046a, + 0x046c, + 0x046e, + 0x0470, + 0x0472, + 0x0474, + 0x0476, + 0x0478, + 0x047a, + 0x047c, + 0x047e, + 0x0480, + 0x048a, + 0x048c, + 0x048e, + 0x0490, + 0x0492, + 0x0494, + 0x0496, + 0x0498, + 0x049a, + 0x049c, + 0x049e, + 0x04a0, + 0x04a2, + 0x04a4, + 0x04a6, + 0x04a8, + 0x04aa, + 0x04ac, + 0x04ae, + 0x04b0, + 0x04b2, + 0x04b4, + 0x04b6, + 0x04b8, + 0x04ba, + 0x04bc, + 0x04be, + 0x04c3, + 0x04c5, + 0x04c7, + 0x04c9, + 0x04cb, + 0x04cd, + 0x04d0, + 0x04d2, + 0x04d4, + 0x04d6, + 0x04d8, + 0x04da, + 0x04dc, + 0x04de, + 0x04e0, + 0x04e2, + 0x04e4, + 0x04e6, + 0x04e8, + 0x04ea, + 0x04ec, + 0x04ee, + 0x04f0, + 0x04f2, + 0x04f4, + 0x04f6, + 0x04f8, + 0x04fa, + 0x04fc, + 0x04fe, + 0x0500, + 0x0502, + 0x0504, + 0x0506, + 0x0508, + 0x050a, + 0x050c, + 0x050e, + 0x0510, + 0x0512, + 0x0514, + 0x0516, + 0x0518, + 0x051a, + 0x051c, + 0x051e, + 0x0520, + 0x0522, + 0x0524, + 0x0526, + 0x0528, + 0x052a, + 0x052c, + 0x052e, + 0x10c7, + 0x10cd, + 0x1e00, + 0x1e02, + 0x1e04, + 0x1e06, + 0x1e08, + 0x1e0a, + 0x1e0c, + 0x1e0e, + 0x1e10, + 0x1e12, + 0x1e14, + 0x1e16, + 0x1e18, + 0x1e1a, + 0x1e1c, + 0x1e1e, + 0x1e20, + 0x1e22, + 0x1e24, + 0x1e26, + 0x1e28, + 0x1e2a, + 0x1e2c, + 0x1e2e, + 0x1e30, + 0x1e32, + 0x1e34, + 0x1e36, + 0x1e38, + 0x1e3a, + 0x1e3c, + 0x1e3e, + 0x1e40, + 0x1e42, + 0x1e44, + 0x1e46, + 0x1e48, + 0x1e4a, + 0x1e4c, + 0x1e4e, + 0x1e50, + 0x1e52, + 0x1e54, + 0x1e56, + 0x1e58, + 0x1e5a, + 0x1e5c, + 0x1e5e, + 0x1e60, + 0x1e62, + 0x1e64, + 0x1e66, + 0x1e68, + 0x1e6a, + 0x1e6c, + 0x1e6e, + 0x1e70, + 0x1e72, + 0x1e74, + 0x1e76, + 0x1e78, + 0x1e7a, + 0x1e7c, + 0x1e7e, + 0x1e80, + 0x1e82, + 0x1e84, + 0x1e86, + 0x1e88, + 0x1e8a, + 0x1e8c, + 0x1e8e, + 0x1e90, + 0x1e92, + 0x1e94, + 0x1ea0, + 0x1ea2, + 0x1ea4, + 0x1ea6, + 0x1ea8, + 0x1eaa, + 0x1eac, + 0x1eae, + 0x1eb0, + 0x1eb2, + 0x1eb4, + 0x1eb6, + 0x1eb8, + 0x1eba, + 0x1ebc, + 0x1ebe, + 0x1ec0, + 0x1ec2, + 0x1ec4, + 0x1ec6, + 0x1ec8, + 0x1eca, + 0x1ecc, + 0x1ece, + 0x1ed0, + 0x1ed2, + 0x1ed4, + 0x1ed6, + 0x1ed8, + 0x1eda, + 0x1edc, + 0x1ede, + 0x1ee0, + 0x1ee2, + 0x1ee4, + 0x1ee6, + 0x1ee8, + 0x1eea, + 0x1eec, + 0x1eee, + 0x1ef0, + 0x1ef2, + 0x1ef4, + 0x1ef6, + 0x1ef8, + 0x1efa, + 0x1efc, + 0x1efe, + 0x1f59, + 0x1f5b, + 0x1f5d, + 0x1f5f, + 0x2132, + 0x2183, + 0x2c60, + 0x2c67, + 0x2c69, + 0x2c6b, + 0x2c72, + 0x2c75, + 0x2c82, + 0x2c84, + 0x2c86, + 0x2c88, + 0x2c8a, + 0x2c8c, + 0x2c8e, + 0x2c90, + 0x2c92, + 0x2c94, + 0x2c96, + 0x2c98, + 0x2c9a, + 0x2c9c, + 0x2c9e, + 0x2ca0, + 0x2ca2, + 0x2ca4, + 0x2ca6, + 0x2ca8, + 0x2caa, + 0x2cac, + 0x2cae, + 0x2cb0, + 0x2cb2, + 0x2cb4, + 0x2cb6, + 0x2cb8, + 0x2cba, + 0x2cbc, + 0x2cbe, + 0x2cc0, + 0x2cc2, + 0x2cc4, + 0x2cc6, + 0x2cc8, + 0x2cca, + 0x2ccc, + 0x2cce, + 0x2cd0, + 0x2cd2, + 0x2cd4, + 0x2cd6, + 0x2cd8, + 0x2cda, + 0x2cdc, + 0x2cde, + 0x2ce0, + 0x2ce2, + 0x2ceb, + 0x2ced, + 0x2cf2, + 0xa640, + 0xa642, + 0xa644, + 0xa646, + 0xa648, + 0xa64a, + 0xa64c, + 0xa64e, + 0xa650, + 0xa652, + 0xa654, + 0xa656, + 0xa658, + 0xa65a, + 0xa65c, + 0xa65e, + 0xa660, + 0xa662, + 0xa664, + 0xa666, + 0xa668, + 0xa66a, + 0xa66c, + 0xa680, + 0xa682, + 0xa684, + 0xa686, + 0xa688, + 0xa68a, + 0xa68c, + 0xa68e, + 0xa690, + 0xa692, + 0xa694, + 0xa696, + 0xa698, + 0xa69a, + 0xa722, + 0xa724, + 0xa726, + 0xa728, + 0xa72a, + 0xa72c, + 0xa72e, + 0xa732, + 0xa734, + 0xa736, + 0xa738, + 0xa73a, + 0xa73c, + 0xa73e, + 0xa740, + 0xa742, + 0xa744, + 0xa746, + 0xa748, + 0xa74a, + 0xa74c, + 0xa74e, + 0xa750, + 0xa752, + 0xa754, + 0xa756, + 0xa758, + 0xa75a, + 0xa75c, + 0xa75e, + 0xa760, + 0xa762, + 0xa764, + 0xa766, + 0xa768, + 0xa76a, + 0xa76c, + 0xa76e, + 0xa779, + 0xa77b, + 0xa780, + 0xa782, + 0xa784, + 0xa786, + 0xa78b, + 0xa78d, + 0xa790, + 0xa792, + 0xa796, + 0xa798, + 0xa79a, + 0xa79c, + 0xa79e, + 0xa7a0, + 0xa7a2, + 0xa7a4, + 0xa7a6, + 0xa7a8, }; } // !namespace bool istitle(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, istitler, nelem (istitler)/2, 2); + p = rbsearch(c, istitler, nelem (istitler)/2, 2); - if (p && c >= p[0] && c <= p[1]) - return true; + if (p && c >= p[0] && c <= p[1]) + return true; - p = rbsearch(c, istitles, nelem (istitles), 1); + p = rbsearch(c, istitles, nelem (istitles), 1); - if (p && c == p[0]) - return true; + if (p && c == p[0]) + return true; - return false; + return false; } namespace { const char32_t toupperr[] = { - 0x0061, 0x007a, 1048544, - 0x00e0, 0x00f6, 1048544, - 0x00f8, 0x00fe, 1048544, - 0x023f, 0x0240, 1059391, - 0x0256, 0x0257, 1048371, - 0x028a, 0x028b, 1048359, - 0x037b, 0x037d, 1048706, - 0x03ad, 0x03af, 1048539, - 0x03b1, 0x03c1, 1048544, - 0x03c3, 0x03cb, 1048544, - 0x03cd, 0x03ce, 1048513, - 0x0430, 0x044f, 1048544, - 0x0450, 0x045f, 1048496, - 0x0561, 0x0586, 1048528, - 0x1f00, 0x1f07, 1048584, - 0x1f10, 0x1f15, 1048584, - 0x1f20, 0x1f27, 1048584, - 0x1f30, 0x1f37, 1048584, - 0x1f40, 0x1f45, 1048584, - 0x1f60, 0x1f67, 1048584, - 0x1f70, 0x1f71, 1048650, - 0x1f72, 0x1f75, 1048662, - 0x1f76, 0x1f77, 1048676, - 0x1f78, 0x1f79, 1048704, - 0x1f7a, 0x1f7b, 1048688, - 0x1f7c, 0x1f7d, 1048702, - 0x1f80, 0x1f87, 1048584, - 0x1f90, 0x1f97, 1048584, - 0x1fa0, 0x1fa7, 1048584, - 0x1fb0, 0x1fb1, 1048584, - 0x1fd0, 0x1fd1, 1048584, - 0x1fe0, 0x1fe1, 1048584, - 0x2170, 0x217f, 1048560, - 0x24d0, 0x24e9, 1048550, - 0x2c30, 0x2c5e, 1048528, - 0x2d00, 0x2d25, 1041312, - 0xff41, 0xff5a, 1048544, - 0x10428, 0x1044f, 1048536, - 0x118c0, 0x118df, 1048544, + 0x0061, 0x007a, 1048544, + 0x00e0, 0x00f6, 1048544, + 0x00f8, 0x00fe, 1048544, + 0x023f, 0x0240, 1059391, + 0x0256, 0x0257, 1048371, + 0x028a, 0x028b, 1048359, + 0x037b, 0x037d, 1048706, + 0x03ad, 0x03af, 1048539, + 0x03b1, 0x03c1, 1048544, + 0x03c3, 0x03cb, 1048544, + 0x03cd, 0x03ce, 1048513, + 0x0430, 0x044f, 1048544, + 0x0450, 0x045f, 1048496, + 0x0561, 0x0586, 1048528, + 0x1f00, 0x1f07, 1048584, + 0x1f10, 0x1f15, 1048584, + 0x1f20, 0x1f27, 1048584, + 0x1f30, 0x1f37, 1048584, + 0x1f40, 0x1f45, 1048584, + 0x1f60, 0x1f67, 1048584, + 0x1f70, 0x1f71, 1048650, + 0x1f72, 0x1f75, 1048662, + 0x1f76, 0x1f77, 1048676, + 0x1f78, 0x1f79, 1048704, + 0x1f7a, 0x1f7b, 1048688, + 0x1f7c, 0x1f7d, 1048702, + 0x1f80, 0x1f87, 1048584, + 0x1f90, 0x1f97, 1048584, + 0x1fa0, 0x1fa7, 1048584, + 0x1fb0, 0x1fb1, 1048584, + 0x1fd0, 0x1fd1, 1048584, + 0x1fe0, 0x1fe1, 1048584, + 0x2170, 0x217f, 1048560, + 0x24d0, 0x24e9, 1048550, + 0x2c30, 0x2c5e, 1048528, + 0x2d00, 0x2d25, 1041312, + 0xff41, 0xff5a, 1048544, + 0x10428, 0x1044f, 1048536, + 0x118c0, 0x118df, 1048544, }; } // !namespace @@ -2696,674 +2696,674 @@ namespace { const char32_t touppers[] = { - 0x00b5, 1049319, - 0x00ff, 1048697, - 0x0101, 1048575, - 0x0103, 1048575, - 0x0105, 1048575, - 0x0107, 1048575, - 0x0109, 1048575, - 0x010b, 1048575, - 0x010d, 1048575, - 0x010f, 1048575, - 0x0111, 1048575, - 0x0113, 1048575, - 0x0115, 1048575, - 0x0117, 1048575, - 0x0119, 1048575, - 0x011b, 1048575, - 0x011d, 1048575, - 0x011f, 1048575, - 0x0121, 1048575, - 0x0123, 1048575, - 0x0125, 1048575, - 0x0127, 1048575, - 0x0129, 1048575, - 0x012b, 1048575, - 0x012d, 1048575, - 0x012f, 1048575, - 0x0131, 1048344, - 0x0133, 1048575, - 0x0135, 1048575, - 0x0137, 1048575, - 0x013a, 1048575, - 0x013c, 1048575, - 0x013e, 1048575, - 0x0140, 1048575, - 0x0142, 1048575, - 0x0144, 1048575, - 0x0146, 1048575, - 0x0148, 1048575, - 0x014b, 1048575, - 0x014d, 1048575, - 0x014f, 1048575, - 0x0151, 1048575, - 0x0153, 1048575, - 0x0155, 1048575, - 0x0157, 1048575, - 0x0159, 1048575, - 0x015b, 1048575, - 0x015d, 1048575, - 0x015f, 1048575, - 0x0161, 1048575, - 0x0163, 1048575, - 0x0165, 1048575, - 0x0167, 1048575, - 0x0169, 1048575, - 0x016b, 1048575, - 0x016d, 1048575, - 0x016f, 1048575, - 0x0171, 1048575, - 0x0173, 1048575, - 0x0175, 1048575, - 0x0177, 1048575, - 0x017a, 1048575, - 0x017c, 1048575, - 0x017e, 1048575, - 0x017f, 1048276, - 0x0180, 1048771, - 0x0183, 1048575, - 0x0185, 1048575, - 0x0188, 1048575, - 0x018c, 1048575, - 0x0192, 1048575, - 0x0195, 1048673, - 0x0199, 1048575, - 0x019a, 1048739, - 0x019e, 1048706, - 0x01a1, 1048575, - 0x01a3, 1048575, - 0x01a5, 1048575, - 0x01a8, 1048575, - 0x01ad, 1048575, - 0x01b0, 1048575, - 0x01b4, 1048575, - 0x01b6, 1048575, - 0x01b9, 1048575, - 0x01bd, 1048575, - 0x01bf, 1048632, - 0x01c5, 1048575, - 0x01c6, 1048574, - 0x01c8, 1048575, - 0x01c9, 1048574, - 0x01cb, 1048575, - 0x01cc, 1048574, - 0x01ce, 1048575, - 0x01d0, 1048575, - 0x01d2, 1048575, - 0x01d4, 1048575, - 0x01d6, 1048575, - 0x01d8, 1048575, - 0x01da, 1048575, - 0x01dc, 1048575, - 0x01dd, 1048497, - 0x01df, 1048575, - 0x01e1, 1048575, - 0x01e3, 1048575, - 0x01e5, 1048575, - 0x01e7, 1048575, - 0x01e9, 1048575, - 0x01eb, 1048575, - 0x01ed, 1048575, - 0x01ef, 1048575, - 0x01f2, 1048575, - 0x01f3, 1048574, - 0x01f5, 1048575, - 0x01f9, 1048575, - 0x01fb, 1048575, - 0x01fd, 1048575, - 0x01ff, 1048575, - 0x0201, 1048575, - 0x0203, 1048575, - 0x0205, 1048575, - 0x0207, 1048575, - 0x0209, 1048575, - 0x020b, 1048575, - 0x020d, 1048575, - 0x020f, 1048575, - 0x0211, 1048575, - 0x0213, 1048575, - 0x0215, 1048575, - 0x0217, 1048575, - 0x0219, 1048575, - 0x021b, 1048575, - 0x021d, 1048575, - 0x021f, 1048575, - 0x0223, 1048575, - 0x0225, 1048575, - 0x0227, 1048575, - 0x0229, 1048575, - 0x022b, 1048575, - 0x022d, 1048575, - 0x022f, 1048575, - 0x0231, 1048575, - 0x0233, 1048575, - 0x023c, 1048575, - 0x0242, 1048575, - 0x0247, 1048575, - 0x0249, 1048575, - 0x024b, 1048575, - 0x024d, 1048575, - 0x024f, 1048575, - 0x0250, 1059359, - 0x0251, 1059356, - 0x0252, 1059358, - 0x0253, 1048366, - 0x0254, 1048370, - 0x0259, 1048374, - 0x025b, 1048373, - 0x025c, 1090895, - 0x0260, 1048371, - 0x0261, 1090891, - 0x0263, 1048369, - 0x0265, 1090856, - 0x0266, 1090884, - 0x0268, 1048367, - 0x0269, 1048365, - 0x026b, 1059319, - 0x026c, 1090881, - 0x026f, 1048365, - 0x0271, 1059325, - 0x0272, 1048363, - 0x0275, 1048362, - 0x027d, 1059303, - 0x0280, 1048358, - 0x0283, 1048358, - 0x0287, 1090858, - 0x0288, 1048358, - 0x0289, 1048507, - 0x028c, 1048505, - 0x0292, 1048357, - 0x029e, 1090834, - 0x0345, 1048660, - 0x0371, 1048575, - 0x0373, 1048575, - 0x0377, 1048575, - 0x03ac, 1048538, - 0x03c2, 1048545, - 0x03cc, 1048512, - 0x03d0, 1048514, - 0x03d1, 1048519, - 0x03d5, 1048529, - 0x03d6, 1048522, - 0x03d7, 1048568, - 0x03d9, 1048575, - 0x03db, 1048575, - 0x03dd, 1048575, - 0x03df, 1048575, - 0x03e1, 1048575, - 0x03e3, 1048575, - 0x03e5, 1048575, - 0x03e7, 1048575, - 0x03e9, 1048575, - 0x03eb, 1048575, - 0x03ed, 1048575, - 0x03ef, 1048575, - 0x03f0, 1048490, - 0x03f1, 1048496, - 0x03f2, 1048583, - 0x03f3, 1048460, - 0x03f5, 1048480, - 0x03f8, 1048575, - 0x03fb, 1048575, - 0x0461, 1048575, - 0x0463, 1048575, - 0x0465, 1048575, - 0x0467, 1048575, - 0x0469, 1048575, - 0x046b, 1048575, - 0x046d, 1048575, - 0x046f, 1048575, - 0x0471, 1048575, - 0x0473, 1048575, - 0x0475, 1048575, - 0x0477, 1048575, - 0x0479, 1048575, - 0x047b, 1048575, - 0x047d, 1048575, - 0x047f, 1048575, - 0x0481, 1048575, - 0x048b, 1048575, - 0x048d, 1048575, - 0x048f, 1048575, - 0x0491, 1048575, - 0x0493, 1048575, - 0x0495, 1048575, - 0x0497, 1048575, - 0x0499, 1048575, - 0x049b, 1048575, - 0x049d, 1048575, - 0x049f, 1048575, - 0x04a1, 1048575, - 0x04a3, 1048575, - 0x04a5, 1048575, - 0x04a7, 1048575, - 0x04a9, 1048575, - 0x04ab, 1048575, - 0x04ad, 1048575, - 0x04af, 1048575, - 0x04b1, 1048575, - 0x04b3, 1048575, - 0x04b5, 1048575, - 0x04b7, 1048575, - 0x04b9, 1048575, - 0x04bb, 1048575, - 0x04bd, 1048575, - 0x04bf, 1048575, - 0x04c2, 1048575, - 0x04c4, 1048575, - 0x04c6, 1048575, - 0x04c8, 1048575, - 0x04ca, 1048575, - 0x04cc, 1048575, - 0x04ce, 1048575, - 0x04cf, 1048561, - 0x04d1, 1048575, - 0x04d3, 1048575, - 0x04d5, 1048575, - 0x04d7, 1048575, - 0x04d9, 1048575, - 0x04db, 1048575, - 0x04dd, 1048575, - 0x04df, 1048575, - 0x04e1, 1048575, - 0x04e3, 1048575, - 0x04e5, 1048575, - 0x04e7, 1048575, - 0x04e9, 1048575, - 0x04eb, 1048575, - 0x04ed, 1048575, - 0x04ef, 1048575, - 0x04f1, 1048575, - 0x04f3, 1048575, - 0x04f5, 1048575, - 0x04f7, 1048575, - 0x04f9, 1048575, - 0x04fb, 1048575, - 0x04fd, 1048575, - 0x04ff, 1048575, - 0x0501, 1048575, - 0x0503, 1048575, - 0x0505, 1048575, - 0x0507, 1048575, - 0x0509, 1048575, - 0x050b, 1048575, - 0x050d, 1048575, - 0x050f, 1048575, - 0x0511, 1048575, - 0x0513, 1048575, - 0x0515, 1048575, - 0x0517, 1048575, - 0x0519, 1048575, - 0x051b, 1048575, - 0x051d, 1048575, - 0x051f, 1048575, - 0x0521, 1048575, - 0x0523, 1048575, - 0x0525, 1048575, - 0x0527, 1048575, - 0x0529, 1048575, - 0x052b, 1048575, - 0x052d, 1048575, - 0x052f, 1048575, - 0x1d79, 1083908, - 0x1d7d, 1052390, - 0x1e01, 1048575, - 0x1e03, 1048575, - 0x1e05, 1048575, - 0x1e07, 1048575, - 0x1e09, 1048575, - 0x1e0b, 1048575, - 0x1e0d, 1048575, - 0x1e0f, 1048575, - 0x1e11, 1048575, - 0x1e13, 1048575, - 0x1e15, 1048575, - 0x1e17, 1048575, - 0x1e19, 1048575, - 0x1e1b, 1048575, - 0x1e1d, 1048575, - 0x1e1f, 1048575, - 0x1e21, 1048575, - 0x1e23, 1048575, - 0x1e25, 1048575, - 0x1e27, 1048575, - 0x1e29, 1048575, - 0x1e2b, 1048575, - 0x1e2d, 1048575, - 0x1e2f, 1048575, - 0x1e31, 1048575, - 0x1e33, 1048575, - 0x1e35, 1048575, - 0x1e37, 1048575, - 0x1e39, 1048575, - 0x1e3b, 1048575, - 0x1e3d, 1048575, - 0x1e3f, 1048575, - 0x1e41, 1048575, - 0x1e43, 1048575, - 0x1e45, 1048575, - 0x1e47, 1048575, - 0x1e49, 1048575, - 0x1e4b, 1048575, - 0x1e4d, 1048575, - 0x1e4f, 1048575, - 0x1e51, 1048575, - 0x1e53, 1048575, - 0x1e55, 1048575, - 0x1e57, 1048575, - 0x1e59, 1048575, - 0x1e5b, 1048575, - 0x1e5d, 1048575, - 0x1e5f, 1048575, - 0x1e61, 1048575, - 0x1e63, 1048575, - 0x1e65, 1048575, - 0x1e67, 1048575, - 0x1e69, 1048575, - 0x1e6b, 1048575, - 0x1e6d, 1048575, - 0x1e6f, 1048575, - 0x1e71, 1048575, - 0x1e73, 1048575, - 0x1e75, 1048575, - 0x1e77, 1048575, - 0x1e79, 1048575, - 0x1e7b, 1048575, - 0x1e7d, 1048575, - 0x1e7f, 1048575, - 0x1e81, 1048575, - 0x1e83, 1048575, - 0x1e85, 1048575, - 0x1e87, 1048575, - 0x1e89, 1048575, - 0x1e8b, 1048575, - 0x1e8d, 1048575, - 0x1e8f, 1048575, - 0x1e91, 1048575, - 0x1e93, 1048575, - 0x1e95, 1048575, - 0x1e9b, 1048517, - 0x1ea1, 1048575, - 0x1ea3, 1048575, - 0x1ea5, 1048575, - 0x1ea7, 1048575, - 0x1ea9, 1048575, - 0x1eab, 1048575, - 0x1ead, 1048575, - 0x1eaf, 1048575, - 0x1eb1, 1048575, - 0x1eb3, 1048575, - 0x1eb5, 1048575, - 0x1eb7, 1048575, - 0x1eb9, 1048575, - 0x1ebb, 1048575, - 0x1ebd, 1048575, - 0x1ebf, 1048575, - 0x1ec1, 1048575, - 0x1ec3, 1048575, - 0x1ec5, 1048575, - 0x1ec7, 1048575, - 0x1ec9, 1048575, - 0x1ecb, 1048575, - 0x1ecd, 1048575, - 0x1ecf, 1048575, - 0x1ed1, 1048575, - 0x1ed3, 1048575, - 0x1ed5, 1048575, - 0x1ed7, 1048575, - 0x1ed9, 1048575, - 0x1edb, 1048575, - 0x1edd, 1048575, - 0x1edf, 1048575, - 0x1ee1, 1048575, - 0x1ee3, 1048575, - 0x1ee5, 1048575, - 0x1ee7, 1048575, - 0x1ee9, 1048575, - 0x1eeb, 1048575, - 0x1eed, 1048575, - 0x1eef, 1048575, - 0x1ef1, 1048575, - 0x1ef3, 1048575, - 0x1ef5, 1048575, - 0x1ef7, 1048575, - 0x1ef9, 1048575, - 0x1efb, 1048575, - 0x1efd, 1048575, - 0x1eff, 1048575, - 0x1f51, 1048584, - 0x1f53, 1048584, - 0x1f55, 1048584, - 0x1f57, 1048584, - 0x1fb3, 1048585, - 0x1fbe, 1041371, - 0x1fc3, 1048585, - 0x1fe5, 1048583, - 0x1ff3, 1048585, - 0x214e, 1048548, - 0x2184, 1048575, - 0x2c61, 1048575, - 0x2c65, 1037781, - 0x2c66, 1037784, - 0x2c68, 1048575, - 0x2c6a, 1048575, - 0x2c6c, 1048575, - 0x2c73, 1048575, - 0x2c76, 1048575, - 0x2c81, 1048575, - 0x2c83, 1048575, - 0x2c85, 1048575, - 0x2c87, 1048575, - 0x2c89, 1048575, - 0x2c8b, 1048575, - 0x2c8d, 1048575, - 0x2c8f, 1048575, - 0x2c91, 1048575, - 0x2c93, 1048575, - 0x2c95, 1048575, - 0x2c97, 1048575, - 0x2c99, 1048575, - 0x2c9b, 1048575, - 0x2c9d, 1048575, - 0x2c9f, 1048575, - 0x2ca1, 1048575, - 0x2ca3, 1048575, - 0x2ca5, 1048575, - 0x2ca7, 1048575, - 0x2ca9, 1048575, - 0x2cab, 1048575, - 0x2cad, 1048575, - 0x2caf, 1048575, - 0x2cb1, 1048575, - 0x2cb3, 1048575, - 0x2cb5, 1048575, - 0x2cb7, 1048575, - 0x2cb9, 1048575, - 0x2cbb, 1048575, - 0x2cbd, 1048575, - 0x2cbf, 1048575, - 0x2cc1, 1048575, - 0x2cc3, 1048575, - 0x2cc5, 1048575, - 0x2cc7, 1048575, - 0x2cc9, 1048575, - 0x2ccb, 1048575, - 0x2ccd, 1048575, - 0x2ccf, 1048575, - 0x2cd1, 1048575, - 0x2cd3, 1048575, - 0x2cd5, 1048575, - 0x2cd7, 1048575, - 0x2cd9, 1048575, - 0x2cdb, 1048575, - 0x2cdd, 1048575, - 0x2cdf, 1048575, - 0x2ce1, 1048575, - 0x2ce3, 1048575, - 0x2cec, 1048575, - 0x2cee, 1048575, - 0x2cf3, 1048575, - 0x2d27, 1041312, - 0x2d2d, 1041312, - 0xa641, 1048575, - 0xa643, 1048575, - 0xa645, 1048575, - 0xa647, 1048575, - 0xa649, 1048575, - 0xa64b, 1048575, - 0xa64d, 1048575, - 0xa64f, 1048575, - 0xa651, 1048575, - 0xa653, 1048575, - 0xa655, 1048575, - 0xa657, 1048575, - 0xa659, 1048575, - 0xa65b, 1048575, - 0xa65d, 1048575, - 0xa65f, 1048575, - 0xa661, 1048575, - 0xa663, 1048575, - 0xa665, 1048575, - 0xa667, 1048575, - 0xa669, 1048575, - 0xa66b, 1048575, - 0xa66d, 1048575, - 0xa681, 1048575, - 0xa683, 1048575, - 0xa685, 1048575, - 0xa687, 1048575, - 0xa689, 1048575, - 0xa68b, 1048575, - 0xa68d, 1048575, - 0xa68f, 1048575, - 0xa691, 1048575, - 0xa693, 1048575, - 0xa695, 1048575, - 0xa697, 1048575, - 0xa699, 1048575, - 0xa69b, 1048575, - 0xa723, 1048575, - 0xa725, 1048575, - 0xa727, 1048575, - 0xa729, 1048575, - 0xa72b, 1048575, - 0xa72d, 1048575, - 0xa72f, 1048575, - 0xa733, 1048575, - 0xa735, 1048575, - 0xa737, 1048575, - 0xa739, 1048575, - 0xa73b, 1048575, - 0xa73d, 1048575, - 0xa73f, 1048575, - 0xa741, 1048575, - 0xa743, 1048575, - 0xa745, 1048575, - 0xa747, 1048575, - 0xa749, 1048575, - 0xa74b, 1048575, - 0xa74d, 1048575, - 0xa74f, 1048575, - 0xa751, 1048575, - 0xa753, 1048575, - 0xa755, 1048575, - 0xa757, 1048575, - 0xa759, 1048575, - 0xa75b, 1048575, - 0xa75d, 1048575, - 0xa75f, 1048575, - 0xa761, 1048575, - 0xa763, 1048575, - 0xa765, 1048575, - 0xa767, 1048575, - 0xa769, 1048575, - 0xa76b, 1048575, - 0xa76d, 1048575, - 0xa76f, 1048575, - 0xa77a, 1048575, - 0xa77c, 1048575, - 0xa77f, 1048575, - 0xa781, 1048575, - 0xa783, 1048575, - 0xa785, 1048575, - 0xa787, 1048575, - 0xa78c, 1048575, - 0xa791, 1048575, - 0xa793, 1048575, - 0xa797, 1048575, - 0xa799, 1048575, - 0xa79b, 1048575, - 0xa79d, 1048575, - 0xa79f, 1048575, - 0xa7a1, 1048575, - 0xa7a3, 1048575, - 0xa7a5, 1048575, - 0xa7a7, 1048575, - 0xa7a9, 1048575, + 0x00b5, 1049319, + 0x00ff, 1048697, + 0x0101, 1048575, + 0x0103, 1048575, + 0x0105, 1048575, + 0x0107, 1048575, + 0x0109, 1048575, + 0x010b, 1048575, + 0x010d, 1048575, + 0x010f, 1048575, + 0x0111, 1048575, + 0x0113, 1048575, + 0x0115, 1048575, + 0x0117, 1048575, + 0x0119, 1048575, + 0x011b, 1048575, + 0x011d, 1048575, + 0x011f, 1048575, + 0x0121, 1048575, + 0x0123, 1048575, + 0x0125, 1048575, + 0x0127, 1048575, + 0x0129, 1048575, + 0x012b, 1048575, + 0x012d, 1048575, + 0x012f, 1048575, + 0x0131, 1048344, + 0x0133, 1048575, + 0x0135, 1048575, + 0x0137, 1048575, + 0x013a, 1048575, + 0x013c, 1048575, + 0x013e, 1048575, + 0x0140, 1048575, + 0x0142, 1048575, + 0x0144, 1048575, + 0x0146, 1048575, + 0x0148, 1048575, + 0x014b, 1048575, + 0x014d, 1048575, + 0x014f, 1048575, + 0x0151, 1048575, + 0x0153, 1048575, + 0x0155, 1048575, + 0x0157, 1048575, + 0x0159, 1048575, + 0x015b, 1048575, + 0x015d, 1048575, + 0x015f, 1048575, + 0x0161, 1048575, + 0x0163, 1048575, + 0x0165, 1048575, + 0x0167, 1048575, + 0x0169, 1048575, + 0x016b, 1048575, + 0x016d, 1048575, + 0x016f, 1048575, + 0x0171, 1048575, + 0x0173, 1048575, + 0x0175, 1048575, + 0x0177, 1048575, + 0x017a, 1048575, + 0x017c, 1048575, + 0x017e, 1048575, + 0x017f, 1048276, + 0x0180, 1048771, + 0x0183, 1048575, + 0x0185, 1048575, + 0x0188, 1048575, + 0x018c, 1048575, + 0x0192, 1048575, + 0x0195, 1048673, + 0x0199, 1048575, + 0x019a, 1048739, + 0x019e, 1048706, + 0x01a1, 1048575, + 0x01a3, 1048575, + 0x01a5, 1048575, + 0x01a8, 1048575, + 0x01ad, 1048575, + 0x01b0, 1048575, + 0x01b4, 1048575, + 0x01b6, 1048575, + 0x01b9, 1048575, + 0x01bd, 1048575, + 0x01bf, 1048632, + 0x01c5, 1048575, + 0x01c6, 1048574, + 0x01c8, 1048575, + 0x01c9, 1048574, + 0x01cb, 1048575, + 0x01cc, 1048574, + 0x01ce, 1048575, + 0x01d0, 1048575, + 0x01d2, 1048575, + 0x01d4, 1048575, + 0x01d6, 1048575, + 0x01d8, 1048575, + 0x01da, 1048575, + 0x01dc, 1048575, + 0x01dd, 1048497, + 0x01df, 1048575, + 0x01e1, 1048575, + 0x01e3, 1048575, + 0x01e5, 1048575, + 0x01e7, 1048575, + 0x01e9, 1048575, + 0x01eb, 1048575, + 0x01ed, 1048575, + 0x01ef, 1048575, + 0x01f2, 1048575, + 0x01f3, 1048574, + 0x01f5, 1048575, + 0x01f9, 1048575, + 0x01fb, 1048575, + 0x01fd, 1048575, + 0x01ff, 1048575, + 0x0201, 1048575, + 0x0203, 1048575, + 0x0205, 1048575, + 0x0207, 1048575, + 0x0209, 1048575, + 0x020b, 1048575, + 0x020d, 1048575, + 0x020f, 1048575, + 0x0211, 1048575, + 0x0213, 1048575, + 0x0215, 1048575, + 0x0217, 1048575, + 0x0219, 1048575, + 0x021b, 1048575, + 0x021d, 1048575, + 0x021f, 1048575, + 0x0223, 1048575, + 0x0225, 1048575, + 0x0227, 1048575, + 0x0229, 1048575, + 0x022b, 1048575, + 0x022d, 1048575, + 0x022f, 1048575, + 0x0231, 1048575, + 0x0233, 1048575, + 0x023c, 1048575, + 0x0242, 1048575, + 0x0247, 1048575, + 0x0249, 1048575, + 0x024b, 1048575, + 0x024d, 1048575, + 0x024f, 1048575, + 0x0250, 1059359, + 0x0251, 1059356, + 0x0252, 1059358, + 0x0253, 1048366, + 0x0254, 1048370, + 0x0259, 1048374, + 0x025b, 1048373, + 0x025c, 1090895, + 0x0260, 1048371, + 0x0261, 1090891, + 0x0263, 1048369, + 0x0265, 1090856, + 0x0266, 1090884, + 0x0268, 1048367, + 0x0269, 1048365, + 0x026b, 1059319, + 0x026c, 1090881, + 0x026f, 1048365, + 0x0271, 1059325, + 0x0272, 1048363, + 0x0275, 1048362, + 0x027d, 1059303, + 0x0280, 1048358, + 0x0283, 1048358, + 0x0287, 1090858, + 0x0288, 1048358, + 0x0289, 1048507, + 0x028c, 1048505, + 0x0292, 1048357, + 0x029e, 1090834, + 0x0345, 1048660, + 0x0371, 1048575, + 0x0373, 1048575, + 0x0377, 1048575, + 0x03ac, 1048538, + 0x03c2, 1048545, + 0x03cc, 1048512, + 0x03d0, 1048514, + 0x03d1, 1048519, + 0x03d5, 1048529, + 0x03d6, 1048522, + 0x03d7, 1048568, + 0x03d9, 1048575, + 0x03db, 1048575, + 0x03dd, 1048575, + 0x03df, 1048575, + 0x03e1, 1048575, + 0x03e3, 1048575, + 0x03e5, 1048575, + 0x03e7, 1048575, + 0x03e9, 1048575, + 0x03eb, 1048575, + 0x03ed, 1048575, + 0x03ef, 1048575, + 0x03f0, 1048490, + 0x03f1, 1048496, + 0x03f2, 1048583, + 0x03f3, 1048460, + 0x03f5, 1048480, + 0x03f8, 1048575, + 0x03fb, 1048575, + 0x0461, 1048575, + 0x0463, 1048575, + 0x0465, 1048575, + 0x0467, 1048575, + 0x0469, 1048575, + 0x046b, 1048575, + 0x046d, 1048575, + 0x046f, 1048575, + 0x0471, 1048575, + 0x0473, 1048575, + 0x0475, 1048575, + 0x0477, 1048575, + 0x0479, 1048575, + 0x047b, 1048575, + 0x047d, 1048575, + 0x047f, 1048575, + 0x0481, 1048575, + 0x048b, 1048575, + 0x048d, 1048575, + 0x048f, 1048575, + 0x0491, 1048575, + 0x0493, 1048575, + 0x0495, 1048575, + 0x0497, 1048575, + 0x0499, 1048575, + 0x049b, 1048575, + 0x049d, 1048575, + 0x049f, 1048575, + 0x04a1, 1048575, + 0x04a3, 1048575, + 0x04a5, 1048575, + 0x04a7, 1048575, + 0x04a9, 1048575, + 0x04ab, 1048575, + 0x04ad, 1048575, + 0x04af, 1048575, + 0x04b1, 1048575, + 0x04b3, 1048575, + 0x04b5, 1048575, + 0x04b7, 1048575, + 0x04b9, 1048575, + 0x04bb, 1048575, + 0x04bd, 1048575, + 0x04bf, 1048575, + 0x04c2, 1048575, + 0x04c4, 1048575, + 0x04c6, 1048575, + 0x04c8, 1048575, + 0x04ca, 1048575, + 0x04cc, 1048575, + 0x04ce, 1048575, + 0x04cf, 1048561, + 0x04d1, 1048575, + 0x04d3, 1048575, + 0x04d5, 1048575, + 0x04d7, 1048575, + 0x04d9, 1048575, + 0x04db, 1048575, + 0x04dd, 1048575, + 0x04df, 1048575, + 0x04e1, 1048575, + 0x04e3, 1048575, + 0x04e5, 1048575, + 0x04e7, 1048575, + 0x04e9, 1048575, + 0x04eb, 1048575, + 0x04ed, 1048575, + 0x04ef, 1048575, + 0x04f1, 1048575, + 0x04f3, 1048575, + 0x04f5, 1048575, + 0x04f7, 1048575, + 0x04f9, 1048575, + 0x04fb, 1048575, + 0x04fd, 1048575, + 0x04ff, 1048575, + 0x0501, 1048575, + 0x0503, 1048575, + 0x0505, 1048575, + 0x0507, 1048575, + 0x0509, 1048575, + 0x050b, 1048575, + 0x050d, 1048575, + 0x050f, 1048575, + 0x0511, 1048575, + 0x0513, 1048575, + 0x0515, 1048575, + 0x0517, 1048575, + 0x0519, 1048575, + 0x051b, 1048575, + 0x051d, 1048575, + 0x051f, 1048575, + 0x0521, 1048575, + 0x0523, 1048575, + 0x0525, 1048575, + 0x0527, 1048575, + 0x0529, 1048575, + 0x052b, 1048575, + 0x052d, 1048575, + 0x052f, 1048575, + 0x1d79, 1083908, + 0x1d7d, 1052390, + 0x1e01, 1048575, + 0x1e03, 1048575, + 0x1e05, 1048575, + 0x1e07, 1048575, + 0x1e09, 1048575, + 0x1e0b, 1048575, + 0x1e0d, 1048575, + 0x1e0f, 1048575, + 0x1e11, 1048575, + 0x1e13, 1048575, + 0x1e15, 1048575, + 0x1e17, 1048575, + 0x1e19, 1048575, + 0x1e1b, 1048575, + 0x1e1d, 1048575, + 0x1e1f, 1048575, + 0x1e21, 1048575, + 0x1e23, 1048575, + 0x1e25, 1048575, + 0x1e27, 1048575, + 0x1e29, 1048575, + 0x1e2b, 1048575, + 0x1e2d, 1048575, + 0x1e2f, 1048575, + 0x1e31, 1048575, + 0x1e33, 1048575, + 0x1e35, 1048575, + 0x1e37, 1048575, + 0x1e39, 1048575, + 0x1e3b, 1048575, + 0x1e3d, 1048575, + 0x1e3f, 1048575, + 0x1e41, 1048575, + 0x1e43, 1048575, + 0x1e45, 1048575, + 0x1e47, 1048575, + 0x1e49, 1048575, + 0x1e4b, 1048575, + 0x1e4d, 1048575, + 0x1e4f, 1048575, + 0x1e51, 1048575, + 0x1e53, 1048575, + 0x1e55, 1048575, + 0x1e57, 1048575, + 0x1e59, 1048575, + 0x1e5b, 1048575, + 0x1e5d, 1048575, + 0x1e5f, 1048575, + 0x1e61, 1048575, + 0x1e63, 1048575, + 0x1e65, 1048575, + 0x1e67, 1048575, + 0x1e69, 1048575, + 0x1e6b, 1048575, + 0x1e6d, 1048575, + 0x1e6f, 1048575, + 0x1e71, 1048575, + 0x1e73, 1048575, + 0x1e75, 1048575, + 0x1e77, 1048575, + 0x1e79, 1048575, + 0x1e7b, 1048575, + 0x1e7d, 1048575, + 0x1e7f, 1048575, + 0x1e81, 1048575, + 0x1e83, 1048575, + 0x1e85, 1048575, + 0x1e87, 1048575, + 0x1e89, 1048575, + 0x1e8b, 1048575, + 0x1e8d, 1048575, + 0x1e8f, 1048575, + 0x1e91, 1048575, + 0x1e93, 1048575, + 0x1e95, 1048575, + 0x1e9b, 1048517, + 0x1ea1, 1048575, + 0x1ea3, 1048575, + 0x1ea5, 1048575, + 0x1ea7, 1048575, + 0x1ea9, 1048575, + 0x1eab, 1048575, + 0x1ead, 1048575, + 0x1eaf, 1048575, + 0x1eb1, 1048575, + 0x1eb3, 1048575, + 0x1eb5, 1048575, + 0x1eb7, 1048575, + 0x1eb9, 1048575, + 0x1ebb, 1048575, + 0x1ebd, 1048575, + 0x1ebf, 1048575, + 0x1ec1, 1048575, + 0x1ec3, 1048575, + 0x1ec5, 1048575, + 0x1ec7, 1048575, + 0x1ec9, 1048575, + 0x1ecb, 1048575, + 0x1ecd, 1048575, + 0x1ecf, 1048575, + 0x1ed1, 1048575, + 0x1ed3, 1048575, + 0x1ed5, 1048575, + 0x1ed7, 1048575, + 0x1ed9, 1048575, + 0x1edb, 1048575, + 0x1edd, 1048575, + 0x1edf, 1048575, + 0x1ee1, 1048575, + 0x1ee3, 1048575, + 0x1ee5, 1048575, + 0x1ee7, 1048575, + 0x1ee9, 1048575, + 0x1eeb, 1048575, + 0x1eed, 1048575, + 0x1eef, 1048575, + 0x1ef1, 1048575, + 0x1ef3, 1048575, + 0x1ef5, 1048575, + 0x1ef7, 1048575, + 0x1ef9, 1048575, + 0x1efb, 1048575, + 0x1efd, 1048575, + 0x1eff, 1048575, + 0x1f51, 1048584, + 0x1f53, 1048584, + 0x1f55, 1048584, + 0x1f57, 1048584, + 0x1fb3, 1048585, + 0x1fbe, 1041371, + 0x1fc3, 1048585, + 0x1fe5, 1048583, + 0x1ff3, 1048585, + 0x214e, 1048548, + 0x2184, 1048575, + 0x2c61, 1048575, + 0x2c65, 1037781, + 0x2c66, 1037784, + 0x2c68, 1048575, + 0x2c6a, 1048575, + 0x2c6c, 1048575, + 0x2c73, 1048575, + 0x2c76, 1048575, + 0x2c81, 1048575, + 0x2c83, 1048575, + 0x2c85, 1048575, + 0x2c87, 1048575, + 0x2c89, 1048575, + 0x2c8b, 1048575, + 0x2c8d, 1048575, + 0x2c8f, 1048575, + 0x2c91, 1048575, + 0x2c93, 1048575, + 0x2c95, 1048575, + 0x2c97, 1048575, + 0x2c99, 1048575, + 0x2c9b, 1048575, + 0x2c9d, 1048575, + 0x2c9f, 1048575, + 0x2ca1, 1048575, + 0x2ca3, 1048575, + 0x2ca5, 1048575, + 0x2ca7, 1048575, + 0x2ca9, 1048575, + 0x2cab, 1048575, + 0x2cad, 1048575, + 0x2caf, 1048575, + 0x2cb1, 1048575, + 0x2cb3, 1048575, + 0x2cb5, 1048575, + 0x2cb7, 1048575, + 0x2cb9, 1048575, + 0x2cbb, 1048575, + 0x2cbd, 1048575, + 0x2cbf, 1048575, + 0x2cc1, 1048575, + 0x2cc3, 1048575, + 0x2cc5, 1048575, + 0x2cc7, 1048575, + 0x2cc9, 1048575, + 0x2ccb, 1048575, + 0x2ccd, 1048575, + 0x2ccf, 1048575, + 0x2cd1, 1048575, + 0x2cd3, 1048575, + 0x2cd5, 1048575, + 0x2cd7, 1048575, + 0x2cd9, 1048575, + 0x2cdb, 1048575, + 0x2cdd, 1048575, + 0x2cdf, 1048575, + 0x2ce1, 1048575, + 0x2ce3, 1048575, + 0x2cec, 1048575, + 0x2cee, 1048575, + 0x2cf3, 1048575, + 0x2d27, 1041312, + 0x2d2d, 1041312, + 0xa641, 1048575, + 0xa643, 1048575, + 0xa645, 1048575, + 0xa647, 1048575, + 0xa649, 1048575, + 0xa64b, 1048575, + 0xa64d, 1048575, + 0xa64f, 1048575, + 0xa651, 1048575, + 0xa653, 1048575, + 0xa655, 1048575, + 0xa657, 1048575, + 0xa659, 1048575, + 0xa65b, 1048575, + 0xa65d, 1048575, + 0xa65f, 1048575, + 0xa661, 1048575, + 0xa663, 1048575, + 0xa665, 1048575, + 0xa667, 1048575, + 0xa669, 1048575, + 0xa66b, 1048575, + 0xa66d, 1048575, + 0xa681, 1048575, + 0xa683, 1048575, + 0xa685, 1048575, + 0xa687, 1048575, + 0xa689, 1048575, + 0xa68b, 1048575, + 0xa68d, 1048575, + 0xa68f, 1048575, + 0xa691, 1048575, + 0xa693, 1048575, + 0xa695, 1048575, + 0xa697, 1048575, + 0xa699, 1048575, + 0xa69b, 1048575, + 0xa723, 1048575, + 0xa725, 1048575, + 0xa727, 1048575, + 0xa729, 1048575, + 0xa72b, 1048575, + 0xa72d, 1048575, + 0xa72f, 1048575, + 0xa733, 1048575, + 0xa735, 1048575, + 0xa737, 1048575, + 0xa739, 1048575, + 0xa73b, 1048575, + 0xa73d, 1048575, + 0xa73f, 1048575, + 0xa741, 1048575, + 0xa743, 1048575, + 0xa745, 1048575, + 0xa747, 1048575, + 0xa749, 1048575, + 0xa74b, 1048575, + 0xa74d, 1048575, + 0xa74f, 1048575, + 0xa751, 1048575, + 0xa753, 1048575, + 0xa755, 1048575, + 0xa757, 1048575, + 0xa759, 1048575, + 0xa75b, 1048575, + 0xa75d, 1048575, + 0xa75f, 1048575, + 0xa761, 1048575, + 0xa763, 1048575, + 0xa765, 1048575, + 0xa767, 1048575, + 0xa769, 1048575, + 0xa76b, 1048575, + 0xa76d, 1048575, + 0xa76f, 1048575, + 0xa77a, 1048575, + 0xa77c, 1048575, + 0xa77f, 1048575, + 0xa781, 1048575, + 0xa783, 1048575, + 0xa785, 1048575, + 0xa787, 1048575, + 0xa78c, 1048575, + 0xa791, 1048575, + 0xa793, 1048575, + 0xa797, 1048575, + 0xa799, 1048575, + 0xa79b, 1048575, + 0xa79d, 1048575, + 0xa79f, 1048575, + 0xa7a1, 1048575, + 0xa7a3, 1048575, + 0xa7a5, 1048575, + 0xa7a7, 1048575, + 0xa7a9, 1048575, }; } // !namespace char32_t toupper(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, toupperr, nelem (toupperr)/3, 3); + p = rbsearch(c, toupperr, nelem (toupperr)/3, 3); - if (p && c >= p[0] && c <= p[1]) - return c + p[2] - 1048576; + if (p && c >= p[0] && c <= p[1]) + return c + p[2] - 1048576; - p = rbsearch(c, touppers, nelem (touppers)/2, 2); + p = rbsearch(c, touppers, nelem (touppers)/2, 2); - if (p && c == p[0]) - return c + p[1] - 1048576; + if (p && c == p[0]) + return c + p[1] - 1048576; - return c; + return c; } namespace { const char32_t tolowerr[] = { - 0x0041, 0x005a, 1048608, - 0x00c0, 0x00d6, 1048608, - 0x00d8, 0x00de, 1048608, - 0x0189, 0x018a, 1048781, - 0x01b1, 0x01b2, 1048793, - 0x0388, 0x038a, 1048613, - 0x038e, 0x038f, 1048639, - 0x0391, 0x03a1, 1048608, - 0x03a3, 0x03ab, 1048608, - 0x03fd, 0x03ff, 1048446, - 0x0400, 0x040f, 1048656, - 0x0410, 0x042f, 1048608, - 0x0531, 0x0556, 1048624, - 0x10a0, 0x10c5, 1055840, - 0x1f08, 0x1f0f, 1048568, - 0x1f18, 0x1f1d, 1048568, - 0x1f28, 0x1f2f, 1048568, - 0x1f38, 0x1f3f, 1048568, - 0x1f48, 0x1f4d, 1048568, - 0x1f68, 0x1f6f, 1048568, - 0x1f88, 0x1f8f, 1048568, - 0x1f98, 0x1f9f, 1048568, - 0x1fa8, 0x1faf, 1048568, - 0x1fb8, 0x1fb9, 1048568, - 0x1fba, 0x1fbb, 1048502, - 0x1fc8, 0x1fcb, 1048490, - 0x1fd8, 0x1fd9, 1048568, - 0x1fda, 0x1fdb, 1048476, - 0x1fe8, 0x1fe9, 1048568, - 0x1fea, 0x1feb, 1048464, - 0x1ff8, 0x1ff9, 1048448, - 0x1ffa, 0x1ffb, 1048450, - 0x2160, 0x216f, 1048592, - 0x24b6, 0x24cf, 1048602, - 0x2c00, 0x2c2e, 1048624, - 0x2c7e, 0x2c7f, 1037761, - 0xff21, 0xff3a, 1048608, - 0x10400, 0x10427, 1048616, - 0x118a0, 0x118bf, 1048608, + 0x0041, 0x005a, 1048608, + 0x00c0, 0x00d6, 1048608, + 0x00d8, 0x00de, 1048608, + 0x0189, 0x018a, 1048781, + 0x01b1, 0x01b2, 1048793, + 0x0388, 0x038a, 1048613, + 0x038e, 0x038f, 1048639, + 0x0391, 0x03a1, 1048608, + 0x03a3, 0x03ab, 1048608, + 0x03fd, 0x03ff, 1048446, + 0x0400, 0x040f, 1048656, + 0x0410, 0x042f, 1048608, + 0x0531, 0x0556, 1048624, + 0x10a0, 0x10c5, 1055840, + 0x1f08, 0x1f0f, 1048568, + 0x1f18, 0x1f1d, 1048568, + 0x1f28, 0x1f2f, 1048568, + 0x1f38, 0x1f3f, 1048568, + 0x1f48, 0x1f4d, 1048568, + 0x1f68, 0x1f6f, 1048568, + 0x1f88, 0x1f8f, 1048568, + 0x1f98, 0x1f9f, 1048568, + 0x1fa8, 0x1faf, 1048568, + 0x1fb8, 0x1fb9, 1048568, + 0x1fba, 0x1fbb, 1048502, + 0x1fc8, 0x1fcb, 1048490, + 0x1fd8, 0x1fd9, 1048568, + 0x1fda, 0x1fdb, 1048476, + 0x1fe8, 0x1fe9, 1048568, + 0x1fea, 0x1feb, 1048464, + 0x1ff8, 0x1ff9, 1048448, + 0x1ffa, 0x1ffb, 1048450, + 0x2160, 0x216f, 1048592, + 0x24b6, 0x24cf, 1048602, + 0x2c00, 0x2c2e, 1048624, + 0x2c7e, 0x2c7f, 1037761, + 0xff21, 0xff3a, 1048608, + 0x10400, 0x10427, 1048616, + 0x118a0, 0x118bf, 1048608, }; } // !namespace @@ -3371,666 +3371,666 @@ namespace { const char32_t tolowers[] = { - 0x0100, 1048577, - 0x0102, 1048577, - 0x0104, 1048577, - 0x0106, 1048577, - 0x0108, 1048577, - 0x010a, 1048577, - 0x010c, 1048577, - 0x010e, 1048577, - 0x0110, 1048577, - 0x0112, 1048577, - 0x0114, 1048577, - 0x0116, 1048577, - 0x0118, 1048577, - 0x011a, 1048577, - 0x011c, 1048577, - 0x011e, 1048577, - 0x0120, 1048577, - 0x0122, 1048577, - 0x0124, 1048577, - 0x0126, 1048577, - 0x0128, 1048577, - 0x012a, 1048577, - 0x012c, 1048577, - 0x012e, 1048577, - 0x0130, 1048377, - 0x0132, 1048577, - 0x0134, 1048577, - 0x0136, 1048577, - 0x0139, 1048577, - 0x013b, 1048577, - 0x013d, 1048577, - 0x013f, 1048577, - 0x0141, 1048577, - 0x0143, 1048577, - 0x0145, 1048577, - 0x0147, 1048577, - 0x014a, 1048577, - 0x014c, 1048577, - 0x014e, 1048577, - 0x0150, 1048577, - 0x0152, 1048577, - 0x0154, 1048577, - 0x0156, 1048577, - 0x0158, 1048577, - 0x015a, 1048577, - 0x015c, 1048577, - 0x015e, 1048577, - 0x0160, 1048577, - 0x0162, 1048577, - 0x0164, 1048577, - 0x0166, 1048577, - 0x0168, 1048577, - 0x016a, 1048577, - 0x016c, 1048577, - 0x016e, 1048577, - 0x0170, 1048577, - 0x0172, 1048577, - 0x0174, 1048577, - 0x0176, 1048577, - 0x0178, 1048455, - 0x0179, 1048577, - 0x017b, 1048577, - 0x017d, 1048577, - 0x0181, 1048786, - 0x0182, 1048577, - 0x0184, 1048577, - 0x0186, 1048782, - 0x0187, 1048577, - 0x018b, 1048577, - 0x018e, 1048655, - 0x018f, 1048778, - 0x0190, 1048779, - 0x0191, 1048577, - 0x0193, 1048781, - 0x0194, 1048783, - 0x0196, 1048787, - 0x0197, 1048785, - 0x0198, 1048577, - 0x019c, 1048787, - 0x019d, 1048789, - 0x019f, 1048790, - 0x01a0, 1048577, - 0x01a2, 1048577, - 0x01a4, 1048577, - 0x01a6, 1048794, - 0x01a7, 1048577, - 0x01a9, 1048794, - 0x01ac, 1048577, - 0x01ae, 1048794, - 0x01af, 1048577, - 0x01b3, 1048577, - 0x01b5, 1048577, - 0x01b7, 1048795, - 0x01b8, 1048577, - 0x01bc, 1048577, - 0x01c4, 1048578, - 0x01c5, 1048577, - 0x01c7, 1048578, - 0x01c8, 1048577, - 0x01ca, 1048578, - 0x01cb, 1048577, - 0x01cd, 1048577, - 0x01cf, 1048577, - 0x01d1, 1048577, - 0x01d3, 1048577, - 0x01d5, 1048577, - 0x01d7, 1048577, - 0x01d9, 1048577, - 0x01db, 1048577, - 0x01de, 1048577, - 0x01e0, 1048577, - 0x01e2, 1048577, - 0x01e4, 1048577, - 0x01e6, 1048577, - 0x01e8, 1048577, - 0x01ea, 1048577, - 0x01ec, 1048577, - 0x01ee, 1048577, - 0x01f1, 1048578, - 0x01f2, 1048577, - 0x01f4, 1048577, - 0x01f6, 1048479, - 0x01f7, 1048520, - 0x01f8, 1048577, - 0x01fa, 1048577, - 0x01fc, 1048577, - 0x01fe, 1048577, - 0x0200, 1048577, - 0x0202, 1048577, - 0x0204, 1048577, - 0x0206, 1048577, - 0x0208, 1048577, - 0x020a, 1048577, - 0x020c, 1048577, - 0x020e, 1048577, - 0x0210, 1048577, - 0x0212, 1048577, - 0x0214, 1048577, - 0x0216, 1048577, - 0x0218, 1048577, - 0x021a, 1048577, - 0x021c, 1048577, - 0x021e, 1048577, - 0x0220, 1048446, - 0x0222, 1048577, - 0x0224, 1048577, - 0x0226, 1048577, - 0x0228, 1048577, - 0x022a, 1048577, - 0x022c, 1048577, - 0x022e, 1048577, - 0x0230, 1048577, - 0x0232, 1048577, - 0x023a, 1059371, - 0x023b, 1048577, - 0x023d, 1048413, - 0x023e, 1059368, - 0x0241, 1048577, - 0x0243, 1048381, - 0x0244, 1048645, - 0x0245, 1048647, - 0x0246, 1048577, - 0x0248, 1048577, - 0x024a, 1048577, - 0x024c, 1048577, - 0x024e, 1048577, - 0x0370, 1048577, - 0x0372, 1048577, - 0x0376, 1048577, - 0x037f, 1048692, - 0x0386, 1048614, - 0x038c, 1048640, - 0x03cf, 1048584, - 0x03d8, 1048577, - 0x03da, 1048577, - 0x03dc, 1048577, - 0x03de, 1048577, - 0x03e0, 1048577, - 0x03e2, 1048577, - 0x03e4, 1048577, - 0x03e6, 1048577, - 0x03e8, 1048577, - 0x03ea, 1048577, - 0x03ec, 1048577, - 0x03ee, 1048577, - 0x03f4, 1048516, - 0x03f7, 1048577, - 0x03f9, 1048569, - 0x03fa, 1048577, - 0x0460, 1048577, - 0x0462, 1048577, - 0x0464, 1048577, - 0x0466, 1048577, - 0x0468, 1048577, - 0x046a, 1048577, - 0x046c, 1048577, - 0x046e, 1048577, - 0x0470, 1048577, - 0x0472, 1048577, - 0x0474, 1048577, - 0x0476, 1048577, - 0x0478, 1048577, - 0x047a, 1048577, - 0x047c, 1048577, - 0x047e, 1048577, - 0x0480, 1048577, - 0x048a, 1048577, - 0x048c, 1048577, - 0x048e, 1048577, - 0x0490, 1048577, - 0x0492, 1048577, - 0x0494, 1048577, - 0x0496, 1048577, - 0x0498, 1048577, - 0x049a, 1048577, - 0x049c, 1048577, - 0x049e, 1048577, - 0x04a0, 1048577, - 0x04a2, 1048577, - 0x04a4, 1048577, - 0x04a6, 1048577, - 0x04a8, 1048577, - 0x04aa, 1048577, - 0x04ac, 1048577, - 0x04ae, 1048577, - 0x04b0, 1048577, - 0x04b2, 1048577, - 0x04b4, 1048577, - 0x04b6, 1048577, - 0x04b8, 1048577, - 0x04ba, 1048577, - 0x04bc, 1048577, - 0x04be, 1048577, - 0x04c0, 1048591, - 0x04c1, 1048577, - 0x04c3, 1048577, - 0x04c5, 1048577, - 0x04c7, 1048577, - 0x04c9, 1048577, - 0x04cb, 1048577, - 0x04cd, 1048577, - 0x04d0, 1048577, - 0x04d2, 1048577, - 0x04d4, 1048577, - 0x04d6, 1048577, - 0x04d8, 1048577, - 0x04da, 1048577, - 0x04dc, 1048577, - 0x04de, 1048577, - 0x04e0, 1048577, - 0x04e2, 1048577, - 0x04e4, 1048577, - 0x04e6, 1048577, - 0x04e8, 1048577, - 0x04ea, 1048577, - 0x04ec, 1048577, - 0x04ee, 1048577, - 0x04f0, 1048577, - 0x04f2, 1048577, - 0x04f4, 1048577, - 0x04f6, 1048577, - 0x04f8, 1048577, - 0x04fa, 1048577, - 0x04fc, 1048577, - 0x04fe, 1048577, - 0x0500, 1048577, - 0x0502, 1048577, - 0x0504, 1048577, - 0x0506, 1048577, - 0x0508, 1048577, - 0x050a, 1048577, - 0x050c, 1048577, - 0x050e, 1048577, - 0x0510, 1048577, - 0x0512, 1048577, - 0x0514, 1048577, - 0x0516, 1048577, - 0x0518, 1048577, - 0x051a, 1048577, - 0x051c, 1048577, - 0x051e, 1048577, - 0x0520, 1048577, - 0x0522, 1048577, - 0x0524, 1048577, - 0x0526, 1048577, - 0x0528, 1048577, - 0x052a, 1048577, - 0x052c, 1048577, - 0x052e, 1048577, - 0x10c7, 1055840, - 0x10cd, 1055840, - 0x1e00, 1048577, - 0x1e02, 1048577, - 0x1e04, 1048577, - 0x1e06, 1048577, - 0x1e08, 1048577, - 0x1e0a, 1048577, - 0x1e0c, 1048577, - 0x1e0e, 1048577, - 0x1e10, 1048577, - 0x1e12, 1048577, - 0x1e14, 1048577, - 0x1e16, 1048577, - 0x1e18, 1048577, - 0x1e1a, 1048577, - 0x1e1c, 1048577, - 0x1e1e, 1048577, - 0x1e20, 1048577, - 0x1e22, 1048577, - 0x1e24, 1048577, - 0x1e26, 1048577, - 0x1e28, 1048577, - 0x1e2a, 1048577, - 0x1e2c, 1048577, - 0x1e2e, 1048577, - 0x1e30, 1048577, - 0x1e32, 1048577, - 0x1e34, 1048577, - 0x1e36, 1048577, - 0x1e38, 1048577, - 0x1e3a, 1048577, - 0x1e3c, 1048577, - 0x1e3e, 1048577, - 0x1e40, 1048577, - 0x1e42, 1048577, - 0x1e44, 1048577, - 0x1e46, 1048577, - 0x1e48, 1048577, - 0x1e4a, 1048577, - 0x1e4c, 1048577, - 0x1e4e, 1048577, - 0x1e50, 1048577, - 0x1e52, 1048577, - 0x1e54, 1048577, - 0x1e56, 1048577, - 0x1e58, 1048577, - 0x1e5a, 1048577, - 0x1e5c, 1048577, - 0x1e5e, 1048577, - 0x1e60, 1048577, - 0x1e62, 1048577, - 0x1e64, 1048577, - 0x1e66, 1048577, - 0x1e68, 1048577, - 0x1e6a, 1048577, - 0x1e6c, 1048577, - 0x1e6e, 1048577, - 0x1e70, 1048577, - 0x1e72, 1048577, - 0x1e74, 1048577, - 0x1e76, 1048577, - 0x1e78, 1048577, - 0x1e7a, 1048577, - 0x1e7c, 1048577, - 0x1e7e, 1048577, - 0x1e80, 1048577, - 0x1e82, 1048577, - 0x1e84, 1048577, - 0x1e86, 1048577, - 0x1e88, 1048577, - 0x1e8a, 1048577, - 0x1e8c, 1048577, - 0x1e8e, 1048577, - 0x1e90, 1048577, - 0x1e92, 1048577, - 0x1e94, 1048577, - 0x1e9e, 1040961, - 0x1ea0, 1048577, - 0x1ea2, 1048577, - 0x1ea4, 1048577, - 0x1ea6, 1048577, - 0x1ea8, 1048577, - 0x1eaa, 1048577, - 0x1eac, 1048577, - 0x1eae, 1048577, - 0x1eb0, 1048577, - 0x1eb2, 1048577, - 0x1eb4, 1048577, - 0x1eb6, 1048577, - 0x1eb8, 1048577, - 0x1eba, 1048577, - 0x1ebc, 1048577, - 0x1ebe, 1048577, - 0x1ec0, 1048577, - 0x1ec2, 1048577, - 0x1ec4, 1048577, - 0x1ec6, 1048577, - 0x1ec8, 1048577, - 0x1eca, 1048577, - 0x1ecc, 1048577, - 0x1ece, 1048577, - 0x1ed0, 1048577, - 0x1ed2, 1048577, - 0x1ed4, 1048577, - 0x1ed6, 1048577, - 0x1ed8, 1048577, - 0x1eda, 1048577, - 0x1edc, 1048577, - 0x1ede, 1048577, - 0x1ee0, 1048577, - 0x1ee2, 1048577, - 0x1ee4, 1048577, - 0x1ee6, 1048577, - 0x1ee8, 1048577, - 0x1eea, 1048577, - 0x1eec, 1048577, - 0x1eee, 1048577, - 0x1ef0, 1048577, - 0x1ef2, 1048577, - 0x1ef4, 1048577, - 0x1ef6, 1048577, - 0x1ef8, 1048577, - 0x1efa, 1048577, - 0x1efc, 1048577, - 0x1efe, 1048577, - 0x1f59, 1048568, - 0x1f5b, 1048568, - 0x1f5d, 1048568, - 0x1f5f, 1048568, - 0x1fbc, 1048567, - 0x1fcc, 1048567, - 0x1fec, 1048569, - 0x1ffc, 1048567, - 0x2126, 1041059, - 0x212a, 1040193, - 0x212b, 1040314, - 0x2132, 1048604, - 0x2183, 1048577, - 0x2c60, 1048577, - 0x2c62, 1037833, - 0x2c63, 1044762, - 0x2c64, 1037849, - 0x2c67, 1048577, - 0x2c69, 1048577, - 0x2c6b, 1048577, - 0x2c6d, 1037796, - 0x2c6e, 1037827, - 0x2c6f, 1037793, - 0x2c70, 1037794, - 0x2c72, 1048577, - 0x2c75, 1048577, - 0x2c80, 1048577, - 0x2c82, 1048577, - 0x2c84, 1048577, - 0x2c86, 1048577, - 0x2c88, 1048577, - 0x2c8a, 1048577, - 0x2c8c, 1048577, - 0x2c8e, 1048577, - 0x2c90, 1048577, - 0x2c92, 1048577, - 0x2c94, 1048577, - 0x2c96, 1048577, - 0x2c98, 1048577, - 0x2c9a, 1048577, - 0x2c9c, 1048577, - 0x2c9e, 1048577, - 0x2ca0, 1048577, - 0x2ca2, 1048577, - 0x2ca4, 1048577, - 0x2ca6, 1048577, - 0x2ca8, 1048577, - 0x2caa, 1048577, - 0x2cac, 1048577, - 0x2cae, 1048577, - 0x2cb0, 1048577, - 0x2cb2, 1048577, - 0x2cb4, 1048577, - 0x2cb6, 1048577, - 0x2cb8, 1048577, - 0x2cba, 1048577, - 0x2cbc, 1048577, - 0x2cbe, 1048577, - 0x2cc0, 1048577, - 0x2cc2, 1048577, - 0x2cc4, 1048577, - 0x2cc6, 1048577, - 0x2cc8, 1048577, - 0x2cca, 1048577, - 0x2ccc, 1048577, - 0x2cce, 1048577, - 0x2cd0, 1048577, - 0x2cd2, 1048577, - 0x2cd4, 1048577, - 0x2cd6, 1048577, - 0x2cd8, 1048577, - 0x2cda, 1048577, - 0x2cdc, 1048577, - 0x2cde, 1048577, - 0x2ce0, 1048577, - 0x2ce2, 1048577, - 0x2ceb, 1048577, - 0x2ced, 1048577, - 0x2cf2, 1048577, - 0xa640, 1048577, - 0xa642, 1048577, - 0xa644, 1048577, - 0xa646, 1048577, - 0xa648, 1048577, - 0xa64a, 1048577, - 0xa64c, 1048577, - 0xa64e, 1048577, - 0xa650, 1048577, - 0xa652, 1048577, - 0xa654, 1048577, - 0xa656, 1048577, - 0xa658, 1048577, - 0xa65a, 1048577, - 0xa65c, 1048577, - 0xa65e, 1048577, - 0xa660, 1048577, - 0xa662, 1048577, - 0xa664, 1048577, - 0xa666, 1048577, - 0xa668, 1048577, - 0xa66a, 1048577, - 0xa66c, 1048577, - 0xa680, 1048577, - 0xa682, 1048577, - 0xa684, 1048577, - 0xa686, 1048577, - 0xa688, 1048577, - 0xa68a, 1048577, - 0xa68c, 1048577, - 0xa68e, 1048577, - 0xa690, 1048577, - 0xa692, 1048577, - 0xa694, 1048577, - 0xa696, 1048577, - 0xa698, 1048577, - 0xa69a, 1048577, - 0xa722, 1048577, - 0xa724, 1048577, - 0xa726, 1048577, - 0xa728, 1048577, - 0xa72a, 1048577, - 0xa72c, 1048577, - 0xa72e, 1048577, - 0xa732, 1048577, - 0xa734, 1048577, - 0xa736, 1048577, - 0xa738, 1048577, - 0xa73a, 1048577, - 0xa73c, 1048577, - 0xa73e, 1048577, - 0xa740, 1048577, - 0xa742, 1048577, - 0xa744, 1048577, - 0xa746, 1048577, - 0xa748, 1048577, - 0xa74a, 1048577, - 0xa74c, 1048577, - 0xa74e, 1048577, - 0xa750, 1048577, - 0xa752, 1048577, - 0xa754, 1048577, - 0xa756, 1048577, - 0xa758, 1048577, - 0xa75a, 1048577, - 0xa75c, 1048577, - 0xa75e, 1048577, - 0xa760, 1048577, - 0xa762, 1048577, - 0xa764, 1048577, - 0xa766, 1048577, - 0xa768, 1048577, - 0xa76a, 1048577, - 0xa76c, 1048577, - 0xa76e, 1048577, - 0xa779, 1048577, - 0xa77b, 1048577, - 0xa77d, 1013244, - 0xa77e, 1048577, - 0xa780, 1048577, - 0xa782, 1048577, - 0xa784, 1048577, - 0xa786, 1048577, - 0xa78b, 1048577, - 0xa78d, 1006296, - 0xa790, 1048577, - 0xa792, 1048577, - 0xa796, 1048577, - 0xa798, 1048577, - 0xa79a, 1048577, - 0xa79c, 1048577, - 0xa79e, 1048577, - 0xa7a0, 1048577, - 0xa7a2, 1048577, - 0xa7a4, 1048577, - 0xa7a6, 1048577, - 0xa7a8, 1048577, - 0xa7aa, 1006268, - 0xa7ab, 1006257, - 0xa7ac, 1006261, - 0xa7ad, 1006271, - 0xa7b0, 1006318, - 0xa7b1, 1006294, + 0x0100, 1048577, + 0x0102, 1048577, + 0x0104, 1048577, + 0x0106, 1048577, + 0x0108, 1048577, + 0x010a, 1048577, + 0x010c, 1048577, + 0x010e, 1048577, + 0x0110, 1048577, + 0x0112, 1048577, + 0x0114, 1048577, + 0x0116, 1048577, + 0x0118, 1048577, + 0x011a, 1048577, + 0x011c, 1048577, + 0x011e, 1048577, + 0x0120, 1048577, + 0x0122, 1048577, + 0x0124, 1048577, + 0x0126, 1048577, + 0x0128, 1048577, + 0x012a, 1048577, + 0x012c, 1048577, + 0x012e, 1048577, + 0x0130, 1048377, + 0x0132, 1048577, + 0x0134, 1048577, + 0x0136, 1048577, + 0x0139, 1048577, + 0x013b, 1048577, + 0x013d, 1048577, + 0x013f, 1048577, + 0x0141, 1048577, + 0x0143, 1048577, + 0x0145, 1048577, + 0x0147, 1048577, + 0x014a, 1048577, + 0x014c, 1048577, + 0x014e, 1048577, + 0x0150, 1048577, + 0x0152, 1048577, + 0x0154, 1048577, + 0x0156, 1048577, + 0x0158, 1048577, + 0x015a, 1048577, + 0x015c, 1048577, + 0x015e, 1048577, + 0x0160, 1048577, + 0x0162, 1048577, + 0x0164, 1048577, + 0x0166, 1048577, + 0x0168, 1048577, + 0x016a, 1048577, + 0x016c, 1048577, + 0x016e, 1048577, + 0x0170, 1048577, + 0x0172, 1048577, + 0x0174, 1048577, + 0x0176, 1048577, + 0x0178, 1048455, + 0x0179, 1048577, + 0x017b, 1048577, + 0x017d, 1048577, + 0x0181, 1048786, + 0x0182, 1048577, + 0x0184, 1048577, + 0x0186, 1048782, + 0x0187, 1048577, + 0x018b, 1048577, + 0x018e, 1048655, + 0x018f, 1048778, + 0x0190, 1048779, + 0x0191, 1048577, + 0x0193, 1048781, + 0x0194, 1048783, + 0x0196, 1048787, + 0x0197, 1048785, + 0x0198, 1048577, + 0x019c, 1048787, + 0x019d, 1048789, + 0x019f, 1048790, + 0x01a0, 1048577, + 0x01a2, 1048577, + 0x01a4, 1048577, + 0x01a6, 1048794, + 0x01a7, 1048577, + 0x01a9, 1048794, + 0x01ac, 1048577, + 0x01ae, 1048794, + 0x01af, 1048577, + 0x01b3, 1048577, + 0x01b5, 1048577, + 0x01b7, 1048795, + 0x01b8, 1048577, + 0x01bc, 1048577, + 0x01c4, 1048578, + 0x01c5, 1048577, + 0x01c7, 1048578, + 0x01c8, 1048577, + 0x01ca, 1048578, + 0x01cb, 1048577, + 0x01cd, 1048577, + 0x01cf, 1048577, + 0x01d1, 1048577, + 0x01d3, 1048577, + 0x01d5, 1048577, + 0x01d7, 1048577, + 0x01d9, 1048577, + 0x01db, 1048577, + 0x01de, 1048577, + 0x01e0, 1048577, + 0x01e2, 1048577, + 0x01e4, 1048577, + 0x01e6, 1048577, + 0x01e8, 1048577, + 0x01ea, 1048577, + 0x01ec, 1048577, + 0x01ee, 1048577, + 0x01f1, 1048578, + 0x01f2, 1048577, + 0x01f4, 1048577, + 0x01f6, 1048479, + 0x01f7, 1048520, + 0x01f8, 1048577, + 0x01fa, 1048577, + 0x01fc, 1048577, + 0x01fe, 1048577, + 0x0200, 1048577, + 0x0202, 1048577, + 0x0204, 1048577, + 0x0206, 1048577, + 0x0208, 1048577, + 0x020a, 1048577, + 0x020c, 1048577, + 0x020e, 1048577, + 0x0210, 1048577, + 0x0212, 1048577, + 0x0214, 1048577, + 0x0216, 1048577, + 0x0218, 1048577, + 0x021a, 1048577, + 0x021c, 1048577, + 0x021e, 1048577, + 0x0220, 1048446, + 0x0222, 1048577, + 0x0224, 1048577, + 0x0226, 1048577, + 0x0228, 1048577, + 0x022a, 1048577, + 0x022c, 1048577, + 0x022e, 1048577, + 0x0230, 1048577, + 0x0232, 1048577, + 0x023a, 1059371, + 0x023b, 1048577, + 0x023d, 1048413, + 0x023e, 1059368, + 0x0241, 1048577, + 0x0243, 1048381, + 0x0244, 1048645, + 0x0245, 1048647, + 0x0246, 1048577, + 0x0248, 1048577, + 0x024a, 1048577, + 0x024c, 1048577, + 0x024e, 1048577, + 0x0370, 1048577, + 0x0372, 1048577, + 0x0376, 1048577, + 0x037f, 1048692, + 0x0386, 1048614, + 0x038c, 1048640, + 0x03cf, 1048584, + 0x03d8, 1048577, + 0x03da, 1048577, + 0x03dc, 1048577, + 0x03de, 1048577, + 0x03e0, 1048577, + 0x03e2, 1048577, + 0x03e4, 1048577, + 0x03e6, 1048577, + 0x03e8, 1048577, + 0x03ea, 1048577, + 0x03ec, 1048577, + 0x03ee, 1048577, + 0x03f4, 1048516, + 0x03f7, 1048577, + 0x03f9, 1048569, + 0x03fa, 1048577, + 0x0460, 1048577, + 0x0462, 1048577, + 0x0464, 1048577, + 0x0466, 1048577, + 0x0468, 1048577, + 0x046a, 1048577, + 0x046c, 1048577, + 0x046e, 1048577, + 0x0470, 1048577, + 0x0472, 1048577, + 0x0474, 1048577, + 0x0476, 1048577, + 0x0478, 1048577, + 0x047a, 1048577, + 0x047c, 1048577, + 0x047e, 1048577, + 0x0480, 1048577, + 0x048a, 1048577, + 0x048c, 1048577, + 0x048e, 1048577, + 0x0490, 1048577, + 0x0492, 1048577, + 0x0494, 1048577, + 0x0496, 1048577, + 0x0498, 1048577, + 0x049a, 1048577, + 0x049c, 1048577, + 0x049e, 1048577, + 0x04a0, 1048577, + 0x04a2, 1048577, + 0x04a4, 1048577, + 0x04a6, 1048577, + 0x04a8, 1048577, + 0x04aa, 1048577, + 0x04ac, 1048577, + 0x04ae, 1048577, + 0x04b0, 1048577, + 0x04b2, 1048577, + 0x04b4, 1048577, + 0x04b6, 1048577, + 0x04b8, 1048577, + 0x04ba, 1048577, + 0x04bc, 1048577, + 0x04be, 1048577, + 0x04c0, 1048591, + 0x04c1, 1048577, + 0x04c3, 1048577, + 0x04c5, 1048577, + 0x04c7, 1048577, + 0x04c9, 1048577, + 0x04cb, 1048577, + 0x04cd, 1048577, + 0x04d0, 1048577, + 0x04d2, 1048577, + 0x04d4, 1048577, + 0x04d6, 1048577, + 0x04d8, 1048577, + 0x04da, 1048577, + 0x04dc, 1048577, + 0x04de, 1048577, + 0x04e0, 1048577, + 0x04e2, 1048577, + 0x04e4, 1048577, + 0x04e6, 1048577, + 0x04e8, 1048577, + 0x04ea, 1048577, + 0x04ec, 1048577, + 0x04ee, 1048577, + 0x04f0, 1048577, + 0x04f2, 1048577, + 0x04f4, 1048577, + 0x04f6, 1048577, + 0x04f8, 1048577, + 0x04fa, 1048577, + 0x04fc, 1048577, + 0x04fe, 1048577, + 0x0500, 1048577, + 0x0502, 1048577, + 0x0504, 1048577, + 0x0506, 1048577, + 0x0508, 1048577, + 0x050a, 1048577, + 0x050c, 1048577, + 0x050e, 1048577, + 0x0510, 1048577, + 0x0512, 1048577, + 0x0514, 1048577, + 0x0516, 1048577, + 0x0518, 1048577, + 0x051a, 1048577, + 0x051c, 1048577, + 0x051e, 1048577, + 0x0520, 1048577, + 0x0522, 1048577, + 0x0524, 1048577, + 0x0526, 1048577, + 0x0528, 1048577, + 0x052a, 1048577, + 0x052c, 1048577, + 0x052e, 1048577, + 0x10c7, 1055840, + 0x10cd, 1055840, + 0x1e00, 1048577, + 0x1e02, 1048577, + 0x1e04, 1048577, + 0x1e06, 1048577, + 0x1e08, 1048577, + 0x1e0a, 1048577, + 0x1e0c, 1048577, + 0x1e0e, 1048577, + 0x1e10, 1048577, + 0x1e12, 1048577, + 0x1e14, 1048577, + 0x1e16, 1048577, + 0x1e18, 1048577, + 0x1e1a, 1048577, + 0x1e1c, 1048577, + 0x1e1e, 1048577, + 0x1e20, 1048577, + 0x1e22, 1048577, + 0x1e24, 1048577, + 0x1e26, 1048577, + 0x1e28, 1048577, + 0x1e2a, 1048577, + 0x1e2c, 1048577, + 0x1e2e, 1048577, + 0x1e30, 1048577, + 0x1e32, 1048577, + 0x1e34, 1048577, + 0x1e36, 1048577, + 0x1e38, 1048577, + 0x1e3a, 1048577, + 0x1e3c, 1048577, + 0x1e3e, 1048577, + 0x1e40, 1048577, + 0x1e42, 1048577, + 0x1e44, 1048577, + 0x1e46, 1048577, + 0x1e48, 1048577, + 0x1e4a, 1048577, + 0x1e4c, 1048577, + 0x1e4e, 1048577, + 0x1e50, 1048577, + 0x1e52, 1048577, + 0x1e54, 1048577, + 0x1e56, 1048577, + 0x1e58, 1048577, + 0x1e5a, 1048577, + 0x1e5c, 1048577, + 0x1e5e, 1048577, + 0x1e60, 1048577, + 0x1e62, 1048577, + 0x1e64, 1048577, + 0x1e66, 1048577, + 0x1e68, 1048577, + 0x1e6a, 1048577, + 0x1e6c, 1048577, + 0x1e6e, 1048577, + 0x1e70, 1048577, + 0x1e72, 1048577, + 0x1e74, 1048577, + 0x1e76, 1048577, + 0x1e78, 1048577, + 0x1e7a, 1048577, + 0x1e7c, 1048577, + 0x1e7e, 1048577, + 0x1e80, 1048577, + 0x1e82, 1048577, + 0x1e84, 1048577, + 0x1e86, 1048577, + 0x1e88, 1048577, + 0x1e8a, 1048577, + 0x1e8c, 1048577, + 0x1e8e, 1048577, + 0x1e90, 1048577, + 0x1e92, 1048577, + 0x1e94, 1048577, + 0x1e9e, 1040961, + 0x1ea0, 1048577, + 0x1ea2, 1048577, + 0x1ea4, 1048577, + 0x1ea6, 1048577, + 0x1ea8, 1048577, + 0x1eaa, 1048577, + 0x1eac, 1048577, + 0x1eae, 1048577, + 0x1eb0, 1048577, + 0x1eb2, 1048577, + 0x1eb4, 1048577, + 0x1eb6, 1048577, + 0x1eb8, 1048577, + 0x1eba, 1048577, + 0x1ebc, 1048577, + 0x1ebe, 1048577, + 0x1ec0, 1048577, + 0x1ec2, 1048577, + 0x1ec4, 1048577, + 0x1ec6, 1048577, + 0x1ec8, 1048577, + 0x1eca, 1048577, + 0x1ecc, 1048577, + 0x1ece, 1048577, + 0x1ed0, 1048577, + 0x1ed2, 1048577, + 0x1ed4, 1048577, + 0x1ed6, 1048577, + 0x1ed8, 1048577, + 0x1eda, 1048577, + 0x1edc, 1048577, + 0x1ede, 1048577, + 0x1ee0, 1048577, + 0x1ee2, 1048577, + 0x1ee4, 1048577, + 0x1ee6, 1048577, + 0x1ee8, 1048577, + 0x1eea, 1048577, + 0x1eec, 1048577, + 0x1eee, 1048577, + 0x1ef0, 1048577, + 0x1ef2, 1048577, + 0x1ef4, 1048577, + 0x1ef6, 1048577, + 0x1ef8, 1048577, + 0x1efa, 1048577, + 0x1efc, 1048577, + 0x1efe, 1048577, + 0x1f59, 1048568, + 0x1f5b, 1048568, + 0x1f5d, 1048568, + 0x1f5f, 1048568, + 0x1fbc, 1048567, + 0x1fcc, 1048567, + 0x1fec, 1048569, + 0x1ffc, 1048567, + 0x2126, 1041059, + 0x212a, 1040193, + 0x212b, 1040314, + 0x2132, 1048604, + 0x2183, 1048577, + 0x2c60, 1048577, + 0x2c62, 1037833, + 0x2c63, 1044762, + 0x2c64, 1037849, + 0x2c67, 1048577, + 0x2c69, 1048577, + 0x2c6b, 1048577, + 0x2c6d, 1037796, + 0x2c6e, 1037827, + 0x2c6f, 1037793, + 0x2c70, 1037794, + 0x2c72, 1048577, + 0x2c75, 1048577, + 0x2c80, 1048577, + 0x2c82, 1048577, + 0x2c84, 1048577, + 0x2c86, 1048577, + 0x2c88, 1048577, + 0x2c8a, 1048577, + 0x2c8c, 1048577, + 0x2c8e, 1048577, + 0x2c90, 1048577, + 0x2c92, 1048577, + 0x2c94, 1048577, + 0x2c96, 1048577, + 0x2c98, 1048577, + 0x2c9a, 1048577, + 0x2c9c, 1048577, + 0x2c9e, 1048577, + 0x2ca0, 1048577, + 0x2ca2, 1048577, + 0x2ca4, 1048577, + 0x2ca6, 1048577, + 0x2ca8, 1048577, + 0x2caa, 1048577, + 0x2cac, 1048577, + 0x2cae, 1048577, + 0x2cb0, 1048577, + 0x2cb2, 1048577, + 0x2cb4, 1048577, + 0x2cb6, 1048577, + 0x2cb8, 1048577, + 0x2cba, 1048577, + 0x2cbc, 1048577, + 0x2cbe, 1048577, + 0x2cc0, 1048577, + 0x2cc2, 1048577, + 0x2cc4, 1048577, + 0x2cc6, 1048577, + 0x2cc8, 1048577, + 0x2cca, 1048577, + 0x2ccc, 1048577, + 0x2cce, 1048577, + 0x2cd0, 1048577, + 0x2cd2, 1048577, + 0x2cd4, 1048577, + 0x2cd6, 1048577, + 0x2cd8, 1048577, + 0x2cda, 1048577, + 0x2cdc, 1048577, + 0x2cde, 1048577, + 0x2ce0, 1048577, + 0x2ce2, 1048577, + 0x2ceb, 1048577, + 0x2ced, 1048577, + 0x2cf2, 1048577, + 0xa640, 1048577, + 0xa642, 1048577, + 0xa644, 1048577, + 0xa646, 1048577, + 0xa648, 1048577, + 0xa64a, 1048577, + 0xa64c, 1048577, + 0xa64e, 1048577, + 0xa650, 1048577, + 0xa652, 1048577, + 0xa654, 1048577, + 0xa656, 1048577, + 0xa658, 1048577, + 0xa65a, 1048577, + 0xa65c, 1048577, + 0xa65e, 1048577, + 0xa660, 1048577, + 0xa662, 1048577, + 0xa664, 1048577, + 0xa666, 1048577, + 0xa668, 1048577, + 0xa66a, 1048577, + 0xa66c, 1048577, + 0xa680, 1048577, + 0xa682, 1048577, + 0xa684, 1048577, + 0xa686, 1048577, + 0xa688, 1048577, + 0xa68a, 1048577, + 0xa68c, 1048577, + 0xa68e, 1048577, + 0xa690, 1048577, + 0xa692, 1048577, + 0xa694, 1048577, + 0xa696, 1048577, + 0xa698, 1048577, + 0xa69a, 1048577, + 0xa722, 1048577, + 0xa724, 1048577, + 0xa726, 1048577, + 0xa728, 1048577, + 0xa72a, 1048577, + 0xa72c, 1048577, + 0xa72e, 1048577, + 0xa732, 1048577, + 0xa734, 1048577, + 0xa736, 1048577, + 0xa738, 1048577, + 0xa73a, 1048577, + 0xa73c, 1048577, + 0xa73e, 1048577, + 0xa740, 1048577, + 0xa742, 1048577, + 0xa744, 1048577, + 0xa746, 1048577, + 0xa748, 1048577, + 0xa74a, 1048577, + 0xa74c, 1048577, + 0xa74e, 1048577, + 0xa750, 1048577, + 0xa752, 1048577, + 0xa754, 1048577, + 0xa756, 1048577, + 0xa758, 1048577, + 0xa75a, 1048577, + 0xa75c, 1048577, + 0xa75e, 1048577, + 0xa760, 1048577, + 0xa762, 1048577, + 0xa764, 1048577, + 0xa766, 1048577, + 0xa768, 1048577, + 0xa76a, 1048577, + 0xa76c, 1048577, + 0xa76e, 1048577, + 0xa779, 1048577, + 0xa77b, 1048577, + 0xa77d, 1013244, + 0xa77e, 1048577, + 0xa780, 1048577, + 0xa782, 1048577, + 0xa784, 1048577, + 0xa786, 1048577, + 0xa78b, 1048577, + 0xa78d, 1006296, + 0xa790, 1048577, + 0xa792, 1048577, + 0xa796, 1048577, + 0xa798, 1048577, + 0xa79a, 1048577, + 0xa79c, 1048577, + 0xa79e, 1048577, + 0xa7a0, 1048577, + 0xa7a2, 1048577, + 0xa7a4, 1048577, + 0xa7a6, 1048577, + 0xa7a8, 1048577, + 0xa7aa, 1006268, + 0xa7ab, 1006257, + 0xa7ac, 1006261, + 0xa7ad, 1006271, + 0xa7b0, 1006318, + 0xa7b1, 1006294, }; } // !namespace char32_t tolower(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, tolowerr, nelem (tolowerr)/3, 3); + p = rbsearch(c, tolowerr, nelem (tolowerr)/3, 3); - if (p && c >= p[0] && c <= p[1]) - return c + p[2] - 1048576; + if (p && c >= p[0] && c <= p[1]) + return c + p[2] - 1048576; - p = rbsearch(c, tolowers, nelem (tolowers)/2, 2); + p = rbsearch(c, tolowers, nelem (tolowers)/2, 2); - if (p && c == p[0]) - return c + p[1] - 1048576; + if (p && c == p[0]) + return c + p[1] - 1048576; - return c; + return c; } namespace { const char32_t totitler[] = { - 0x0061, 0x007a, 1048544, - 0x00e0, 0x00f6, 1048544, - 0x00f8, 0x00fe, 1048544, - 0x023f, 0x0240, 1059391, - 0x0256, 0x0257, 1048371, - 0x028a, 0x028b, 1048359, - 0x037b, 0x037d, 1048706, - 0x03ad, 0x03af, 1048539, - 0x03b1, 0x03c1, 1048544, - 0x03c3, 0x03cb, 1048544, - 0x03cd, 0x03ce, 1048513, - 0x0430, 0x044f, 1048544, - 0x0450, 0x045f, 1048496, - 0x0561, 0x0586, 1048528, - 0x1f00, 0x1f07, 1048584, - 0x1f10, 0x1f15, 1048584, - 0x1f20, 0x1f27, 1048584, - 0x1f30, 0x1f37, 1048584, - 0x1f40, 0x1f45, 1048584, - 0x1f60, 0x1f67, 1048584, - 0x1f70, 0x1f71, 1048650, - 0x1f72, 0x1f75, 1048662, - 0x1f76, 0x1f77, 1048676, - 0x1f78, 0x1f79, 1048704, - 0x1f7a, 0x1f7b, 1048688, - 0x1f7c, 0x1f7d, 1048702, - 0x1f80, 0x1f87, 1048584, - 0x1f90, 0x1f97, 1048584, - 0x1fa0, 0x1fa7, 1048584, - 0x1fb0, 0x1fb1, 1048584, - 0x1fd0, 0x1fd1, 1048584, - 0x1fe0, 0x1fe1, 1048584, - 0x2170, 0x217f, 1048560, - 0x24d0, 0x24e9, 1048550, - 0x2c30, 0x2c5e, 1048528, - 0x2d00, 0x2d25, 1041312, - 0xff41, 0xff5a, 1048544, - 0x10428, 0x1044f, 1048536, - 0x118c0, 0x118df, 1048544, + 0x0061, 0x007a, 1048544, + 0x00e0, 0x00f6, 1048544, + 0x00f8, 0x00fe, 1048544, + 0x023f, 0x0240, 1059391, + 0x0256, 0x0257, 1048371, + 0x028a, 0x028b, 1048359, + 0x037b, 0x037d, 1048706, + 0x03ad, 0x03af, 1048539, + 0x03b1, 0x03c1, 1048544, + 0x03c3, 0x03cb, 1048544, + 0x03cd, 0x03ce, 1048513, + 0x0430, 0x044f, 1048544, + 0x0450, 0x045f, 1048496, + 0x0561, 0x0586, 1048528, + 0x1f00, 0x1f07, 1048584, + 0x1f10, 0x1f15, 1048584, + 0x1f20, 0x1f27, 1048584, + 0x1f30, 0x1f37, 1048584, + 0x1f40, 0x1f45, 1048584, + 0x1f60, 0x1f67, 1048584, + 0x1f70, 0x1f71, 1048650, + 0x1f72, 0x1f75, 1048662, + 0x1f76, 0x1f77, 1048676, + 0x1f78, 0x1f79, 1048704, + 0x1f7a, 0x1f7b, 1048688, + 0x1f7c, 0x1f7d, 1048702, + 0x1f80, 0x1f87, 1048584, + 0x1f90, 0x1f97, 1048584, + 0x1fa0, 0x1fa7, 1048584, + 0x1fb0, 0x1fb1, 1048584, + 0x1fd0, 0x1fd1, 1048584, + 0x1fe0, 0x1fe1, 1048584, + 0x2170, 0x217f, 1048560, + 0x24d0, 0x24e9, 1048550, + 0x2c30, 0x2c5e, 1048528, + 0x2d00, 0x2d25, 1041312, + 0xff41, 0xff5a, 1048544, + 0x10428, 0x1044f, 1048536, + 0x118c0, 0x118df, 1048544, }; } // !namespace @@ -4038,755 +4038,755 @@ namespace { const char32_t totitles[] = { - 0x00b5, 1049319, - 0x00ff, 1048697, - 0x0101, 1048575, - 0x0103, 1048575, - 0x0105, 1048575, - 0x0107, 1048575, - 0x0109, 1048575, - 0x010b, 1048575, - 0x010d, 1048575, - 0x010f, 1048575, - 0x0111, 1048575, - 0x0113, 1048575, - 0x0115, 1048575, - 0x0117, 1048575, - 0x0119, 1048575, - 0x011b, 1048575, - 0x011d, 1048575, - 0x011f, 1048575, - 0x0121, 1048575, - 0x0123, 1048575, - 0x0125, 1048575, - 0x0127, 1048575, - 0x0129, 1048575, - 0x012b, 1048575, - 0x012d, 1048575, - 0x012f, 1048575, - 0x0131, 1048344, - 0x0133, 1048575, - 0x0135, 1048575, - 0x0137, 1048575, - 0x013a, 1048575, - 0x013c, 1048575, - 0x013e, 1048575, - 0x0140, 1048575, - 0x0142, 1048575, - 0x0144, 1048575, - 0x0146, 1048575, - 0x0148, 1048575, - 0x014b, 1048575, - 0x014d, 1048575, - 0x014f, 1048575, - 0x0151, 1048575, - 0x0153, 1048575, - 0x0155, 1048575, - 0x0157, 1048575, - 0x0159, 1048575, - 0x015b, 1048575, - 0x015d, 1048575, - 0x015f, 1048575, - 0x0161, 1048575, - 0x0163, 1048575, - 0x0165, 1048575, - 0x0167, 1048575, - 0x0169, 1048575, - 0x016b, 1048575, - 0x016d, 1048575, - 0x016f, 1048575, - 0x0171, 1048575, - 0x0173, 1048575, - 0x0175, 1048575, - 0x0177, 1048575, - 0x017a, 1048575, - 0x017c, 1048575, - 0x017e, 1048575, - 0x017f, 1048276, - 0x0180, 1048771, - 0x0183, 1048575, - 0x0185, 1048575, - 0x0188, 1048575, - 0x018c, 1048575, - 0x0192, 1048575, - 0x0195, 1048673, - 0x0199, 1048575, - 0x019a, 1048739, - 0x019e, 1048706, - 0x01a1, 1048575, - 0x01a3, 1048575, - 0x01a5, 1048575, - 0x01a8, 1048575, - 0x01ad, 1048575, - 0x01b0, 1048575, - 0x01b4, 1048575, - 0x01b6, 1048575, - 0x01b9, 1048575, - 0x01bd, 1048575, - 0x01bf, 1048632, - 0x01c4, 1048577, - 0x01c6, 1048575, - 0x01c7, 1048577, - 0x01c9, 1048575, - 0x01ca, 1048577, - 0x01cc, 1048575, - 0x01ce, 1048575, - 0x01d0, 1048575, - 0x01d2, 1048575, - 0x01d4, 1048575, - 0x01d6, 1048575, - 0x01d8, 1048575, - 0x01da, 1048575, - 0x01dc, 1048575, - 0x01dd, 1048497, - 0x01df, 1048575, - 0x01e1, 1048575, - 0x01e3, 1048575, - 0x01e5, 1048575, - 0x01e7, 1048575, - 0x01e9, 1048575, - 0x01eb, 1048575, - 0x01ed, 1048575, - 0x01ef, 1048575, - 0x01f1, 1048577, - 0x01f3, 1048575, - 0x01f5, 1048575, - 0x01f9, 1048575, - 0x01fb, 1048575, - 0x01fd, 1048575, - 0x01ff, 1048575, - 0x0201, 1048575, - 0x0203, 1048575, - 0x0205, 1048575, - 0x0207, 1048575, - 0x0209, 1048575, - 0x020b, 1048575, - 0x020d, 1048575, - 0x020f, 1048575, - 0x0211, 1048575, - 0x0213, 1048575, - 0x0215, 1048575, - 0x0217, 1048575, - 0x0219, 1048575, - 0x021b, 1048575, - 0x021d, 1048575, - 0x021f, 1048575, - 0x0223, 1048575, - 0x0225, 1048575, - 0x0227, 1048575, - 0x0229, 1048575, - 0x022b, 1048575, - 0x022d, 1048575, - 0x022f, 1048575, - 0x0231, 1048575, - 0x0233, 1048575, - 0x023c, 1048575, - 0x0242, 1048575, - 0x0247, 1048575, - 0x0249, 1048575, - 0x024b, 1048575, - 0x024d, 1048575, - 0x024f, 1048575, - 0x0250, 1059359, - 0x0251, 1059356, - 0x0252, 1059358, - 0x0253, 1048366, - 0x0254, 1048370, - 0x0259, 1048374, - 0x025b, 1048373, - 0x025c, 1090895, - 0x0260, 1048371, - 0x0261, 1090891, - 0x0263, 1048369, - 0x0265, 1090856, - 0x0266, 1090884, - 0x0268, 1048367, - 0x0269, 1048365, - 0x026b, 1059319, - 0x026c, 1090881, - 0x026f, 1048365, - 0x0271, 1059325, - 0x0272, 1048363, - 0x0275, 1048362, - 0x027d, 1059303, - 0x0280, 1048358, - 0x0283, 1048358, - 0x0287, 1090858, - 0x0288, 1048358, - 0x0289, 1048507, - 0x028c, 1048505, - 0x0292, 1048357, - 0x029e, 1090834, - 0x0345, 1048660, - 0x0371, 1048575, - 0x0373, 1048575, - 0x0377, 1048575, - 0x03ac, 1048538, - 0x03c2, 1048545, - 0x03cc, 1048512, - 0x03d0, 1048514, - 0x03d1, 1048519, - 0x03d5, 1048529, - 0x03d6, 1048522, - 0x03d7, 1048568, - 0x03d9, 1048575, - 0x03db, 1048575, - 0x03dd, 1048575, - 0x03df, 1048575, - 0x03e1, 1048575, - 0x03e3, 1048575, - 0x03e5, 1048575, - 0x03e7, 1048575, - 0x03e9, 1048575, - 0x03eb, 1048575, - 0x03ed, 1048575, - 0x03ef, 1048575, - 0x03f0, 1048490, - 0x03f1, 1048496, - 0x03f2, 1048583, - 0x03f3, 1048460, - 0x03f5, 1048480, - 0x03f8, 1048575, - 0x03fb, 1048575, - 0x0461, 1048575, - 0x0463, 1048575, - 0x0465, 1048575, - 0x0467, 1048575, - 0x0469, 1048575, - 0x046b, 1048575, - 0x046d, 1048575, - 0x046f, 1048575, - 0x0471, 1048575, - 0x0473, 1048575, - 0x0475, 1048575, - 0x0477, 1048575, - 0x0479, 1048575, - 0x047b, 1048575, - 0x047d, 1048575, - 0x047f, 1048575, - 0x0481, 1048575, - 0x048b, 1048575, - 0x048d, 1048575, - 0x048f, 1048575, - 0x0491, 1048575, - 0x0493, 1048575, - 0x0495, 1048575, - 0x0497, 1048575, - 0x0499, 1048575, - 0x049b, 1048575, - 0x049d, 1048575, - 0x049f, 1048575, - 0x04a1, 1048575, - 0x04a3, 1048575, - 0x04a5, 1048575, - 0x04a7, 1048575, - 0x04a9, 1048575, - 0x04ab, 1048575, - 0x04ad, 1048575, - 0x04af, 1048575, - 0x04b1, 1048575, - 0x04b3, 1048575, - 0x04b5, 1048575, - 0x04b7, 1048575, - 0x04b9, 1048575, - 0x04bb, 1048575, - 0x04bd, 1048575, - 0x04bf, 1048575, - 0x04c2, 1048575, - 0x04c4, 1048575, - 0x04c6, 1048575, - 0x04c8, 1048575, - 0x04ca, 1048575, - 0x04cc, 1048575, - 0x04ce, 1048575, - 0x04cf, 1048561, - 0x04d1, 1048575, - 0x04d3, 1048575, - 0x04d5, 1048575, - 0x04d7, 1048575, - 0x04d9, 1048575, - 0x04db, 1048575, - 0x04dd, 1048575, - 0x04df, 1048575, - 0x04e1, 1048575, - 0x04e3, 1048575, - 0x04e5, 1048575, - 0x04e7, 1048575, - 0x04e9, 1048575, - 0x04eb, 1048575, - 0x04ed, 1048575, - 0x04ef, 1048575, - 0x04f1, 1048575, - 0x04f3, 1048575, - 0x04f5, 1048575, - 0x04f7, 1048575, - 0x04f9, 1048575, - 0x04fb, 1048575, - 0x04fd, 1048575, - 0x04ff, 1048575, - 0x0501, 1048575, - 0x0503, 1048575, - 0x0505, 1048575, - 0x0507, 1048575, - 0x0509, 1048575, - 0x050b, 1048575, - 0x050d, 1048575, - 0x050f, 1048575, - 0x0511, 1048575, - 0x0513, 1048575, - 0x0515, 1048575, - 0x0517, 1048575, - 0x0519, 1048575, - 0x051b, 1048575, - 0x051d, 1048575, - 0x051f, 1048575, - 0x0521, 1048575, - 0x0523, 1048575, - 0x0525, 1048575, - 0x0527, 1048575, - 0x0529, 1048575, - 0x052b, 1048575, - 0x052d, 1048575, - 0x052f, 1048575, - 0x1d79, 1083908, - 0x1d7d, 1052390, - 0x1e01, 1048575, - 0x1e03, 1048575, - 0x1e05, 1048575, - 0x1e07, 1048575, - 0x1e09, 1048575, - 0x1e0b, 1048575, - 0x1e0d, 1048575, - 0x1e0f, 1048575, - 0x1e11, 1048575, - 0x1e13, 1048575, - 0x1e15, 1048575, - 0x1e17, 1048575, - 0x1e19, 1048575, - 0x1e1b, 1048575, - 0x1e1d, 1048575, - 0x1e1f, 1048575, - 0x1e21, 1048575, - 0x1e23, 1048575, - 0x1e25, 1048575, - 0x1e27, 1048575, - 0x1e29, 1048575, - 0x1e2b, 1048575, - 0x1e2d, 1048575, - 0x1e2f, 1048575, - 0x1e31, 1048575, - 0x1e33, 1048575, - 0x1e35, 1048575, - 0x1e37, 1048575, - 0x1e39, 1048575, - 0x1e3b, 1048575, - 0x1e3d, 1048575, - 0x1e3f, 1048575, - 0x1e41, 1048575, - 0x1e43, 1048575, - 0x1e45, 1048575, - 0x1e47, 1048575, - 0x1e49, 1048575, - 0x1e4b, 1048575, - 0x1e4d, 1048575, - 0x1e4f, 1048575, - 0x1e51, 1048575, - 0x1e53, 1048575, - 0x1e55, 1048575, - 0x1e57, 1048575, - 0x1e59, 1048575, - 0x1e5b, 1048575, - 0x1e5d, 1048575, - 0x1e5f, 1048575, - 0x1e61, 1048575, - 0x1e63, 1048575, - 0x1e65, 1048575, - 0x1e67, 1048575, - 0x1e69, 1048575, - 0x1e6b, 1048575, - 0x1e6d, 1048575, - 0x1e6f, 1048575, - 0x1e71, 1048575, - 0x1e73, 1048575, - 0x1e75, 1048575, - 0x1e77, 1048575, - 0x1e79, 1048575, - 0x1e7b, 1048575, - 0x1e7d, 1048575, - 0x1e7f, 1048575, - 0x1e81, 1048575, - 0x1e83, 1048575, - 0x1e85, 1048575, - 0x1e87, 1048575, - 0x1e89, 1048575, - 0x1e8b, 1048575, - 0x1e8d, 1048575, - 0x1e8f, 1048575, - 0x1e91, 1048575, - 0x1e93, 1048575, - 0x1e95, 1048575, - 0x1e9b, 1048517, - 0x1ea1, 1048575, - 0x1ea3, 1048575, - 0x1ea5, 1048575, - 0x1ea7, 1048575, - 0x1ea9, 1048575, - 0x1eab, 1048575, - 0x1ead, 1048575, - 0x1eaf, 1048575, - 0x1eb1, 1048575, - 0x1eb3, 1048575, - 0x1eb5, 1048575, - 0x1eb7, 1048575, - 0x1eb9, 1048575, - 0x1ebb, 1048575, - 0x1ebd, 1048575, - 0x1ebf, 1048575, - 0x1ec1, 1048575, - 0x1ec3, 1048575, - 0x1ec5, 1048575, - 0x1ec7, 1048575, - 0x1ec9, 1048575, - 0x1ecb, 1048575, - 0x1ecd, 1048575, - 0x1ecf, 1048575, - 0x1ed1, 1048575, - 0x1ed3, 1048575, - 0x1ed5, 1048575, - 0x1ed7, 1048575, - 0x1ed9, 1048575, - 0x1edb, 1048575, - 0x1edd, 1048575, - 0x1edf, 1048575, - 0x1ee1, 1048575, - 0x1ee3, 1048575, - 0x1ee5, 1048575, - 0x1ee7, 1048575, - 0x1ee9, 1048575, - 0x1eeb, 1048575, - 0x1eed, 1048575, - 0x1eef, 1048575, - 0x1ef1, 1048575, - 0x1ef3, 1048575, - 0x1ef5, 1048575, - 0x1ef7, 1048575, - 0x1ef9, 1048575, - 0x1efb, 1048575, - 0x1efd, 1048575, - 0x1eff, 1048575, - 0x1f51, 1048584, - 0x1f53, 1048584, - 0x1f55, 1048584, - 0x1f57, 1048584, - 0x1fb3, 1048585, - 0x1fbe, 1041371, - 0x1fc3, 1048585, - 0x1fe5, 1048583, - 0x1ff3, 1048585, - 0x214e, 1048548, - 0x2184, 1048575, - 0x2c61, 1048575, - 0x2c65, 1037781, - 0x2c66, 1037784, - 0x2c68, 1048575, - 0x2c6a, 1048575, - 0x2c6c, 1048575, - 0x2c73, 1048575, - 0x2c76, 1048575, - 0x2c81, 1048575, - 0x2c83, 1048575, - 0x2c85, 1048575, - 0x2c87, 1048575, - 0x2c89, 1048575, - 0x2c8b, 1048575, - 0x2c8d, 1048575, - 0x2c8f, 1048575, - 0x2c91, 1048575, - 0x2c93, 1048575, - 0x2c95, 1048575, - 0x2c97, 1048575, - 0x2c99, 1048575, - 0x2c9b, 1048575, - 0x2c9d, 1048575, - 0x2c9f, 1048575, - 0x2ca1, 1048575, - 0x2ca3, 1048575, - 0x2ca5, 1048575, - 0x2ca7, 1048575, - 0x2ca9, 1048575, - 0x2cab, 1048575, - 0x2cad, 1048575, - 0x2caf, 1048575, - 0x2cb1, 1048575, - 0x2cb3, 1048575, - 0x2cb5, 1048575, - 0x2cb7, 1048575, - 0x2cb9, 1048575, - 0x2cbb, 1048575, - 0x2cbd, 1048575, - 0x2cbf, 1048575, - 0x2cc1, 1048575, - 0x2cc3, 1048575, - 0x2cc5, 1048575, - 0x2cc7, 1048575, - 0x2cc9, 1048575, - 0x2ccb, 1048575, - 0x2ccd, 1048575, - 0x2ccf, 1048575, - 0x2cd1, 1048575, - 0x2cd3, 1048575, - 0x2cd5, 1048575, - 0x2cd7, 1048575, - 0x2cd9, 1048575, - 0x2cdb, 1048575, - 0x2cdd, 1048575, - 0x2cdf, 1048575, - 0x2ce1, 1048575, - 0x2ce3, 1048575, - 0x2cec, 1048575, - 0x2cee, 1048575, - 0x2cf3, 1048575, - 0x2d27, 1041312, - 0x2d2d, 1041312, - 0xa641, 1048575, - 0xa643, 1048575, - 0xa645, 1048575, - 0xa647, 1048575, - 0xa649, 1048575, - 0xa64b, 1048575, - 0xa64d, 1048575, - 0xa64f, 1048575, - 0xa651, 1048575, - 0xa653, 1048575, - 0xa655, 1048575, - 0xa657, 1048575, - 0xa659, 1048575, - 0xa65b, 1048575, - 0xa65d, 1048575, - 0xa65f, 1048575, - 0xa661, 1048575, - 0xa663, 1048575, - 0xa665, 1048575, - 0xa667, 1048575, - 0xa669, 1048575, - 0xa66b, 1048575, - 0xa66d, 1048575, - 0xa681, 1048575, - 0xa683, 1048575, - 0xa685, 1048575, - 0xa687, 1048575, - 0xa689, 1048575, - 0xa68b, 1048575, - 0xa68d, 1048575, - 0xa68f, 1048575, - 0xa691, 1048575, - 0xa693, 1048575, - 0xa695, 1048575, - 0xa697, 1048575, - 0xa699, 1048575, - 0xa69b, 1048575, - 0xa723, 1048575, - 0xa725, 1048575, - 0xa727, 1048575, - 0xa729, 1048575, - 0xa72b, 1048575, - 0xa72d, 1048575, - 0xa72f, 1048575, - 0xa733, 1048575, - 0xa735, 1048575, - 0xa737, 1048575, - 0xa739, 1048575, - 0xa73b, 1048575, - 0xa73d, 1048575, - 0xa73f, 1048575, - 0xa741, 1048575, - 0xa743, 1048575, - 0xa745, 1048575, - 0xa747, 1048575, - 0xa749, 1048575, - 0xa74b, 1048575, - 0xa74d, 1048575, - 0xa74f, 1048575, - 0xa751, 1048575, - 0xa753, 1048575, - 0xa755, 1048575, - 0xa757, 1048575, - 0xa759, 1048575, - 0xa75b, 1048575, - 0xa75d, 1048575, - 0xa75f, 1048575, - 0xa761, 1048575, - 0xa763, 1048575, - 0xa765, 1048575, - 0xa767, 1048575, - 0xa769, 1048575, - 0xa76b, 1048575, - 0xa76d, 1048575, - 0xa76f, 1048575, - 0xa77a, 1048575, - 0xa77c, 1048575, - 0xa77f, 1048575, - 0xa781, 1048575, - 0xa783, 1048575, - 0xa785, 1048575, - 0xa787, 1048575, - 0xa78c, 1048575, - 0xa791, 1048575, - 0xa793, 1048575, - 0xa797, 1048575, - 0xa799, 1048575, - 0xa79b, 1048575, - 0xa79d, 1048575, - 0xa79f, 1048575, - 0xa7a1, 1048575, - 0xa7a3, 1048575, - 0xa7a5, 1048575, - 0xa7a7, 1048575, - 0xa7a9, 1048575, + 0x00b5, 1049319, + 0x00ff, 1048697, + 0x0101, 1048575, + 0x0103, 1048575, + 0x0105, 1048575, + 0x0107, 1048575, + 0x0109, 1048575, + 0x010b, 1048575, + 0x010d, 1048575, + 0x010f, 1048575, + 0x0111, 1048575, + 0x0113, 1048575, + 0x0115, 1048575, + 0x0117, 1048575, + 0x0119, 1048575, + 0x011b, 1048575, + 0x011d, 1048575, + 0x011f, 1048575, + 0x0121, 1048575, + 0x0123, 1048575, + 0x0125, 1048575, + 0x0127, 1048575, + 0x0129, 1048575, + 0x012b, 1048575, + 0x012d, 1048575, + 0x012f, 1048575, + 0x0131, 1048344, + 0x0133, 1048575, + 0x0135, 1048575, + 0x0137, 1048575, + 0x013a, 1048575, + 0x013c, 1048575, + 0x013e, 1048575, + 0x0140, 1048575, + 0x0142, 1048575, + 0x0144, 1048575, + 0x0146, 1048575, + 0x0148, 1048575, + 0x014b, 1048575, + 0x014d, 1048575, + 0x014f, 1048575, + 0x0151, 1048575, + 0x0153, 1048575, + 0x0155, 1048575, + 0x0157, 1048575, + 0x0159, 1048575, + 0x015b, 1048575, + 0x015d, 1048575, + 0x015f, 1048575, + 0x0161, 1048575, + 0x0163, 1048575, + 0x0165, 1048575, + 0x0167, 1048575, + 0x0169, 1048575, + 0x016b, 1048575, + 0x016d, 1048575, + 0x016f, 1048575, + 0x0171, 1048575, + 0x0173, 1048575, + 0x0175, 1048575, + 0x0177, 1048575, + 0x017a, 1048575, + 0x017c, 1048575, + 0x017e, 1048575, + 0x017f, 1048276, + 0x0180, 1048771, + 0x0183, 1048575, + 0x0185, 1048575, + 0x0188, 1048575, + 0x018c, 1048575, + 0x0192, 1048575, + 0x0195, 1048673, + 0x0199, 1048575, + 0x019a, 1048739, + 0x019e, 1048706, + 0x01a1, 1048575, + 0x01a3, 1048575, + 0x01a5, 1048575, + 0x01a8, 1048575, + 0x01ad, 1048575, + 0x01b0, 1048575, + 0x01b4, 1048575, + 0x01b6, 1048575, + 0x01b9, 1048575, + 0x01bd, 1048575, + 0x01bf, 1048632, + 0x01c4, 1048577, + 0x01c6, 1048575, + 0x01c7, 1048577, + 0x01c9, 1048575, + 0x01ca, 1048577, + 0x01cc, 1048575, + 0x01ce, 1048575, + 0x01d0, 1048575, + 0x01d2, 1048575, + 0x01d4, 1048575, + 0x01d6, 1048575, + 0x01d8, 1048575, + 0x01da, 1048575, + 0x01dc, 1048575, + 0x01dd, 1048497, + 0x01df, 1048575, + 0x01e1, 1048575, + 0x01e3, 1048575, + 0x01e5, 1048575, + 0x01e7, 1048575, + 0x01e9, 1048575, + 0x01eb, 1048575, + 0x01ed, 1048575, + 0x01ef, 1048575, + 0x01f1, 1048577, + 0x01f3, 1048575, + 0x01f5, 1048575, + 0x01f9, 1048575, + 0x01fb, 1048575, + 0x01fd, 1048575, + 0x01ff, 1048575, + 0x0201, 1048575, + 0x0203, 1048575, + 0x0205, 1048575, + 0x0207, 1048575, + 0x0209, 1048575, + 0x020b, 1048575, + 0x020d, 1048575, + 0x020f, 1048575, + 0x0211, 1048575, + 0x0213, 1048575, + 0x0215, 1048575, + 0x0217, 1048575, + 0x0219, 1048575, + 0x021b, 1048575, + 0x021d, 1048575, + 0x021f, 1048575, + 0x0223, 1048575, + 0x0225, 1048575, + 0x0227, 1048575, + 0x0229, 1048575, + 0x022b, 1048575, + 0x022d, 1048575, + 0x022f, 1048575, + 0x0231, 1048575, + 0x0233, 1048575, + 0x023c, 1048575, + 0x0242, 1048575, + 0x0247, 1048575, + 0x0249, 1048575, + 0x024b, 1048575, + 0x024d, 1048575, + 0x024f, 1048575, + 0x0250, 1059359, + 0x0251, 1059356, + 0x0252, 1059358, + 0x0253, 1048366, + 0x0254, 1048370, + 0x0259, 1048374, + 0x025b, 1048373, + 0x025c, 1090895, + 0x0260, 1048371, + 0x0261, 1090891, + 0x0263, 1048369, + 0x0265, 1090856, + 0x0266, 1090884, + 0x0268, 1048367, + 0x0269, 1048365, + 0x026b, 1059319, + 0x026c, 1090881, + 0x026f, 1048365, + 0x0271, 1059325, + 0x0272, 1048363, + 0x0275, 1048362, + 0x027d, 1059303, + 0x0280, 1048358, + 0x0283, 1048358, + 0x0287, 1090858, + 0x0288, 1048358, + 0x0289, 1048507, + 0x028c, 1048505, + 0x0292, 1048357, + 0x029e, 1090834, + 0x0345, 1048660, + 0x0371, 1048575, + 0x0373, 1048575, + 0x0377, 1048575, + 0x03ac, 1048538, + 0x03c2, 1048545, + 0x03cc, 1048512, + 0x03d0, 1048514, + 0x03d1, 1048519, + 0x03d5, 1048529, + 0x03d6, 1048522, + 0x03d7, 1048568, + 0x03d9, 1048575, + 0x03db, 1048575, + 0x03dd, 1048575, + 0x03df, 1048575, + 0x03e1, 1048575, + 0x03e3, 1048575, + 0x03e5, 1048575, + 0x03e7, 1048575, + 0x03e9, 1048575, + 0x03eb, 1048575, + 0x03ed, 1048575, + 0x03ef, 1048575, + 0x03f0, 1048490, + 0x03f1, 1048496, + 0x03f2, 1048583, + 0x03f3, 1048460, + 0x03f5, 1048480, + 0x03f8, 1048575, + 0x03fb, 1048575, + 0x0461, 1048575, + 0x0463, 1048575, + 0x0465, 1048575, + 0x0467, 1048575, + 0x0469, 1048575, + 0x046b, 1048575, + 0x046d, 1048575, + 0x046f, 1048575, + 0x0471, 1048575, + 0x0473, 1048575, + 0x0475, 1048575, + 0x0477, 1048575, + 0x0479, 1048575, + 0x047b, 1048575, + 0x047d, 1048575, + 0x047f, 1048575, + 0x0481, 1048575, + 0x048b, 1048575, + 0x048d, 1048575, + 0x048f, 1048575, + 0x0491, 1048575, + 0x0493, 1048575, + 0x0495, 1048575, + 0x0497, 1048575, + 0x0499, 1048575, + 0x049b, 1048575, + 0x049d, 1048575, + 0x049f, 1048575, + 0x04a1, 1048575, + 0x04a3, 1048575, + 0x04a5, 1048575, + 0x04a7, 1048575, + 0x04a9, 1048575, + 0x04ab, 1048575, + 0x04ad, 1048575, + 0x04af, 1048575, + 0x04b1, 1048575, + 0x04b3, 1048575, + 0x04b5, 1048575, + 0x04b7, 1048575, + 0x04b9, 1048575, + 0x04bb, 1048575, + 0x04bd, 1048575, + 0x04bf, 1048575, + 0x04c2, 1048575, + 0x04c4, 1048575, + 0x04c6, 1048575, + 0x04c8, 1048575, + 0x04ca, 1048575, + 0x04cc, 1048575, + 0x04ce, 1048575, + 0x04cf, 1048561, + 0x04d1, 1048575, + 0x04d3, 1048575, + 0x04d5, 1048575, + 0x04d7, 1048575, + 0x04d9, 1048575, + 0x04db, 1048575, + 0x04dd, 1048575, + 0x04df, 1048575, + 0x04e1, 1048575, + 0x04e3, 1048575, + 0x04e5, 1048575, + 0x04e7, 1048575, + 0x04e9, 1048575, + 0x04eb, 1048575, + 0x04ed, 1048575, + 0x04ef, 1048575, + 0x04f1, 1048575, + 0x04f3, 1048575, + 0x04f5, 1048575, + 0x04f7, 1048575, + 0x04f9, 1048575, + 0x04fb, 1048575, + 0x04fd, 1048575, + 0x04ff, 1048575, + 0x0501, 1048575, + 0x0503, 1048575, + 0x0505, 1048575, + 0x0507, 1048575, + 0x0509, 1048575, + 0x050b, 1048575, + 0x050d, 1048575, + 0x050f, 1048575, + 0x0511, 1048575, + 0x0513, 1048575, + 0x0515, 1048575, + 0x0517, 1048575, + 0x0519, 1048575, + 0x051b, 1048575, + 0x051d, 1048575, + 0x051f, 1048575, + 0x0521, 1048575, + 0x0523, 1048575, + 0x0525, 1048575, + 0x0527, 1048575, + 0x0529, 1048575, + 0x052b, 1048575, + 0x052d, 1048575, + 0x052f, 1048575, + 0x1d79, 1083908, + 0x1d7d, 1052390, + 0x1e01, 1048575, + 0x1e03, 1048575, + 0x1e05, 1048575, + 0x1e07, 1048575, + 0x1e09, 1048575, + 0x1e0b, 1048575, + 0x1e0d, 1048575, + 0x1e0f, 1048575, + 0x1e11, 1048575, + 0x1e13, 1048575, + 0x1e15, 1048575, + 0x1e17, 1048575, + 0x1e19, 1048575, + 0x1e1b, 1048575, + 0x1e1d, 1048575, + 0x1e1f, 1048575, + 0x1e21, 1048575, + 0x1e23, 1048575, + 0x1e25, 1048575, + 0x1e27, 1048575, + 0x1e29, 1048575, + 0x1e2b, 1048575, + 0x1e2d, 1048575, + 0x1e2f, 1048575, + 0x1e31, 1048575, + 0x1e33, 1048575, + 0x1e35, 1048575, + 0x1e37, 1048575, + 0x1e39, 1048575, + 0x1e3b, 1048575, + 0x1e3d, 1048575, + 0x1e3f, 1048575, + 0x1e41, 1048575, + 0x1e43, 1048575, + 0x1e45, 1048575, + 0x1e47, 1048575, + 0x1e49, 1048575, + 0x1e4b, 1048575, + 0x1e4d, 1048575, + 0x1e4f, 1048575, + 0x1e51, 1048575, + 0x1e53, 1048575, + 0x1e55, 1048575, + 0x1e57, 1048575, + 0x1e59, 1048575, + 0x1e5b, 1048575, + 0x1e5d, 1048575, + 0x1e5f, 1048575, + 0x1e61, 1048575, + 0x1e63, 1048575, + 0x1e65, 1048575, + 0x1e67, 1048575, + 0x1e69, 1048575, + 0x1e6b, 1048575, + 0x1e6d, 1048575, + 0x1e6f, 1048575, + 0x1e71, 1048575, + 0x1e73, 1048575, + 0x1e75, 1048575, + 0x1e77, 1048575, + 0x1e79, 1048575, + 0x1e7b, 1048575, + 0x1e7d, 1048575, + 0x1e7f, 1048575, + 0x1e81, 1048575, + 0x1e83, 1048575, + 0x1e85, 1048575, + 0x1e87, 1048575, + 0x1e89, 1048575, + 0x1e8b, 1048575, + 0x1e8d, 1048575, + 0x1e8f, 1048575, + 0x1e91, 1048575, + 0x1e93, 1048575, + 0x1e95, 1048575, + 0x1e9b, 1048517, + 0x1ea1, 1048575, + 0x1ea3, 1048575, + 0x1ea5, 1048575, + 0x1ea7, 1048575, + 0x1ea9, 1048575, + 0x1eab, 1048575, + 0x1ead, 1048575, + 0x1eaf, 1048575, + 0x1eb1, 1048575, + 0x1eb3, 1048575, + 0x1eb5, 1048575, + 0x1eb7, 1048575, + 0x1eb9, 1048575, + 0x1ebb, 1048575, + 0x1ebd, 1048575, + 0x1ebf, 1048575, + 0x1ec1, 1048575, + 0x1ec3, 1048575, + 0x1ec5, 1048575, + 0x1ec7, 1048575, + 0x1ec9, 1048575, + 0x1ecb, 1048575, + 0x1ecd, 1048575, + 0x1ecf, 1048575, + 0x1ed1, 1048575, + 0x1ed3, 1048575, + 0x1ed5, 1048575, + 0x1ed7, 1048575, + 0x1ed9, 1048575, + 0x1edb, 1048575, + 0x1edd, 1048575, + 0x1edf, 1048575, + 0x1ee1, 1048575, + 0x1ee3, 1048575, + 0x1ee5, 1048575, + 0x1ee7, 1048575, + 0x1ee9, 1048575, + 0x1eeb, 1048575, + 0x1eed, 1048575, + 0x1eef, 1048575, + 0x1ef1, 1048575, + 0x1ef3, 1048575, + 0x1ef5, 1048575, + 0x1ef7, 1048575, + 0x1ef9, 1048575, + 0x1efb, 1048575, + 0x1efd, 1048575, + 0x1eff, 1048575, + 0x1f51, 1048584, + 0x1f53, 1048584, + 0x1f55, 1048584, + 0x1f57, 1048584, + 0x1fb3, 1048585, + 0x1fbe, 1041371, + 0x1fc3, 1048585, + 0x1fe5, 1048583, + 0x1ff3, 1048585, + 0x214e, 1048548, + 0x2184, 1048575, + 0x2c61, 1048575, + 0x2c65, 1037781, + 0x2c66, 1037784, + 0x2c68, 1048575, + 0x2c6a, 1048575, + 0x2c6c, 1048575, + 0x2c73, 1048575, + 0x2c76, 1048575, + 0x2c81, 1048575, + 0x2c83, 1048575, + 0x2c85, 1048575, + 0x2c87, 1048575, + 0x2c89, 1048575, + 0x2c8b, 1048575, + 0x2c8d, 1048575, + 0x2c8f, 1048575, + 0x2c91, 1048575, + 0x2c93, 1048575, + 0x2c95, 1048575, + 0x2c97, 1048575, + 0x2c99, 1048575, + 0x2c9b, 1048575, + 0x2c9d, 1048575, + 0x2c9f, 1048575, + 0x2ca1, 1048575, + 0x2ca3, 1048575, + 0x2ca5, 1048575, + 0x2ca7, 1048575, + 0x2ca9, 1048575, + 0x2cab, 1048575, + 0x2cad, 1048575, + 0x2caf, 1048575, + 0x2cb1, 1048575, + 0x2cb3, 1048575, + 0x2cb5, 1048575, + 0x2cb7, 1048575, + 0x2cb9, 1048575, + 0x2cbb, 1048575, + 0x2cbd, 1048575, + 0x2cbf, 1048575, + 0x2cc1, 1048575, + 0x2cc3, 1048575, + 0x2cc5, 1048575, + 0x2cc7, 1048575, + 0x2cc9, 1048575, + 0x2ccb, 1048575, + 0x2ccd, 1048575, + 0x2ccf, 1048575, + 0x2cd1, 1048575, + 0x2cd3, 1048575, + 0x2cd5, 1048575, + 0x2cd7, 1048575, + 0x2cd9, 1048575, + 0x2cdb, 1048575, + 0x2cdd, 1048575, + 0x2cdf, 1048575, + 0x2ce1, 1048575, + 0x2ce3, 1048575, + 0x2cec, 1048575, + 0x2cee, 1048575, + 0x2cf3, 1048575, + 0x2d27, 1041312, + 0x2d2d, 1041312, + 0xa641, 1048575, + 0xa643, 1048575, + 0xa645, 1048575, + 0xa647, 1048575, + 0xa649, 1048575, + 0xa64b, 1048575, + 0xa64d, 1048575, + 0xa64f, 1048575, + 0xa651, 1048575, + 0xa653, 1048575, + 0xa655, 1048575, + 0xa657, 1048575, + 0xa659, 1048575, + 0xa65b, 1048575, + 0xa65d, 1048575, + 0xa65f, 1048575, + 0xa661, 1048575, + 0xa663, 1048575, + 0xa665, 1048575, + 0xa667, 1048575, + 0xa669, 1048575, + 0xa66b, 1048575, + 0xa66d, 1048575, + 0xa681, 1048575, + 0xa683, 1048575, + 0xa685, 1048575, + 0xa687, 1048575, + 0xa689, 1048575, + 0xa68b, 1048575, + 0xa68d, 1048575, + 0xa68f, 1048575, + 0xa691, 1048575, + 0xa693, 1048575, + 0xa695, 1048575, + 0xa697, 1048575, + 0xa699, 1048575, + 0xa69b, 1048575, + 0xa723, 1048575, + 0xa725, 1048575, + 0xa727, 1048575, + 0xa729, 1048575, + 0xa72b, 1048575, + 0xa72d, 1048575, + 0xa72f, 1048575, + 0xa733, 1048575, + 0xa735, 1048575, + 0xa737, 1048575, + 0xa739, 1048575, + 0xa73b, 1048575, + 0xa73d, 1048575, + 0xa73f, 1048575, + 0xa741, 1048575, + 0xa743, 1048575, + 0xa745, 1048575, + 0xa747, 1048575, + 0xa749, 1048575, + 0xa74b, 1048575, + 0xa74d, 1048575, + 0xa74f, 1048575, + 0xa751, 1048575, + 0xa753, 1048575, + 0xa755, 1048575, + 0xa757, 1048575, + 0xa759, 1048575, + 0xa75b, 1048575, + 0xa75d, 1048575, + 0xa75f, 1048575, + 0xa761, 1048575, + 0xa763, 1048575, + 0xa765, 1048575, + 0xa767, 1048575, + 0xa769, 1048575, + 0xa76b, 1048575, + 0xa76d, 1048575, + 0xa76f, 1048575, + 0xa77a, 1048575, + 0xa77c, 1048575, + 0xa77f, 1048575, + 0xa781, 1048575, + 0xa783, 1048575, + 0xa785, 1048575, + 0xa787, 1048575, + 0xa78c, 1048575, + 0xa791, 1048575, + 0xa793, 1048575, + 0xa797, 1048575, + 0xa799, 1048575, + 0xa79b, 1048575, + 0xa79d, 1048575, + 0xa79f, 1048575, + 0xa7a1, 1048575, + 0xa7a3, 1048575, + 0xa7a5, 1048575, + 0xa7a7, 1048575, + 0xa7a9, 1048575, }; } // !namespace char32_t totitle(char32_t c) noexcept { - const char32_t *p; + const char32_t *p; - p = rbsearch(c, totitler, nelem (totitler)/3, 3); + p = rbsearch(c, totitler, nelem (totitler)/3, 3); - if (p && c >= p[0] && c <= p[1]) - return c + p[2] - 1048576; + if (p && c >= p[0] && c <= p[1]) + return c + p[2] - 1048576; - p = rbsearch(c, totitles, nelem (totitles)/2, 2); + p = rbsearch(c, totitles, nelem (totitles)/2, 2); - if (p && c == p[0]) - return c + p[1] - 1048576; + if (p && c == p[0]) + return c + p[1] - 1048576; - return c; + return c; } void encode(char32_t c, char res[5]) noexcept { - switch (nbytesPoint(c)) { - case 1: - res[0] = static_cast<char>(c); - res[1] = '\0'; - break; - case 2: - res[0] = 0xC0 | ((c >> 6) & 0x1F); - res[1] = 0x80 | (c & 0x3F); - res[2] = '\0'; - break; - case 3: - res[0] = 0xE0 | ((c >> 12) & 0xF ); - res[1] = 0x80 | ((c >> 6) & 0x3F); - res[2] = 0x80 | (c & 0x3F); - res[3] = '\0'; - break; - case 4: - res[0] = 0xF0 | ((c >> 18) & 0x7 ); - res[1] = 0x80 | ((c >> 12) & 0x3F); - res[2] = 0x80 | ((c >> 6) & 0x3F); - res[3] = 0x80 | (c & 0x3F); - res[4] = '\0'; - break; - default: - break; - } + switch (nbytesPoint(c)) { + case 1: + res[0] = static_cast<char>(c); + res[1] = '\0'; + break; + case 2: + res[0] = 0xC0 | ((c >> 6) & 0x1F); + res[1] = 0x80 | (c & 0x3F); + res[2] = '\0'; + break; + case 3: + res[0] = 0xE0 | ((c >> 12) & 0xF ); + res[1] = 0x80 | ((c >> 6) & 0x3F); + res[2] = 0x80 | (c & 0x3F); + res[3] = '\0'; + break; + case 4: + res[0] = 0xF0 | ((c >> 18) & 0x7 ); + res[1] = 0x80 | ((c >> 12) & 0x3F); + res[2] = 0x80 | ((c >> 6) & 0x3F); + res[3] = 0x80 | (c & 0x3F); + res[4] = '\0'; + break; + default: + break; + } } void decode(char32_t &c, const char *res) noexcept { - c = 0; + c = 0; - switch (nbytesUtf8(res[0])) { - case 1: - c = res[0]; - break; - case 2: - c = (res[0] & 0x1f) << 6; - c |= (res[1] & 0x3f); - break; - case 3: - c = (res[0] & 0x0f) << 12; - c |= (res[1] & 0x3f) << 6; - c |= (res[2] & 0x3f); - break; - case 4: - c = (res[0] & 0x07) << 16; - c |= (res[1] & 0x3f) << 12; - c |= (res[2] & 0x3f) << 6; - c |= (res[3] & 0x3f); - default: - break; - } + switch (nbytesUtf8(res[0])) { + case 1: + c = res[0]; + break; + case 2: + c = (res[0] & 0x1f) << 6; + c |= (res[1] & 0x3f); + break; + case 3: + c = (res[0] & 0x0f) << 12; + c |= (res[1] & 0x3f) << 6; + c |= (res[2] & 0x3f); + break; + case 4: + c = (res[0] & 0x07) << 16; + c |= (res[1] & 0x3f) << 12; + c |= (res[2] & 0x3f) << 6; + c |= (res[3] & 0x3f); + default: + break; + } } int nbytesUtf8(char c) noexcept { - if (static_cast<unsigned char>(c) <= 127) - return 1; - if ((c & 0xE0) == 0xC0) - return 2; - if ((c & 0xF0) == 0xE0) - return 3; - if ((c & 0xF8) == 0xF0) - return 4; + if (static_cast<unsigned char>(c) <= 127) + return 1; + if ((c & 0xE0) == 0xC0) + return 2; + if ((c & 0xF0) == 0xE0) + return 3; + if ((c & 0xF8) == 0xF0) + return 4; - return -1; + return -1; } int nbytesPoint(char32_t c) noexcept { - if (c <= 0x7F) - return 1; - if (c <= 0x7FF) - return 2; - if (c <= 0xFFFF) - return 3; - if (c <= 0x1FFFFF) - return 4; + if (c <= 0x7F) + return 1; + if (c <= 0x7FF) + return 2; + if (c <= 0xFFFF) + return 3; + if (c <= 0x1FFFFF) + return 4; - return -1; + return -1; } unsigned length(const std::string &str) { - unsigned total = 0; + unsigned total = 0; - forEach(str, [&] (char32_t) { - ++ total; - }); + forEach(str, [&] (char32_t) { + ++ total; + }); - return total; + return total; } std::string toUtf8(const std::u32string &array) { - std::string res; + std::string res; - for (size_t i = 0; i < array.size(); ++i) { - char tmp[5]; - int size = nbytesPoint(array[i]); + for (size_t i = 0; i < array.size(); ++i) { + char tmp[5]; + int size = nbytesPoint(array[i]); - if (size < 0) - throw std::invalid_argument("invalid sequence"); + if (size < 0) + throw std::invalid_argument("invalid sequence"); - encode(array[i], tmp); - res.insert(res.length(), tmp); - } + encode(array[i], tmp); + res.insert(res.length(), tmp); + } - return res; + return res; } std::u32string toUtf32(const std::string &str) { - std::u32string res; + std::u32string res; - forEach(str, [&] (char32_t code) { - res.push_back(code); - }); + forEach(str, [&] (char32_t code) { + res.push_back(code); + }); - return res; + return res; } } // !unicode
--- a/modules/unicode/unicode.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/unicode/unicode.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -83,7 +83,7 @@ * Iterate over all real characters in the UTF-8 string. * * The function must have the following signature: - * void f(char ch) + * void f(char ch) * * \param str the UTF-8 string * \param function the function callback @@ -92,18 +92,18 @@ template <typename Func> void forEach(const std::string &str, Func function) { - for (size_t i = 0; i < str.size(); ) { - char32_t point = 0; - int size = nbytesUtf8(str[i]); + for (size_t i = 0; i < str.size(); ) { + char32_t point = 0; + int size = nbytesUtf8(str[i]); - if (size < 0) - throw std::invalid_argument("invalid sequence"); + if (size < 0) + throw std::invalid_argument("invalid sequence"); - decode(point, str.data() + i); - function(point); + decode(point, str.data() + i); + function(point); - i += size; - } + i += size; + } } /** @@ -204,10 +204,10 @@ */ inline std::u32string toupper(std::u32string str) { - for (size_t i = 0; i < str.size(); ++i) - str[i] = toupper(str[i]); + for (size_t i = 0; i < str.size(); ++i) + str[i] = toupper(str[i]); - return str; + return str; } /** @@ -219,15 +219,15 @@ */ inline std::string toupper(const std::string &str) { - std::string result; - char buffer[5]; + std::string result; + char buffer[5]; - forEach(str, [&] (char32_t code) { - encode(toupper(code), buffer); - result += buffer; - }); + forEach(str, [&] (char32_t code) { + encode(toupper(code), buffer); + result += buffer; + }); - return result; + return result; } /** @@ -238,10 +238,10 @@ */ inline std::u32string tolower(std::u32string str) { - for (size_t i = 0; i < str.size(); ++i) - str[i] = tolower(str[i]); + for (size_t i = 0; i < str.size(); ++i) + str[i] = tolower(str[i]); - return str; + return str; } /** @@ -253,15 +253,15 @@ */ inline std::string tolower(const std::string &str) { - std::string result; - char buffer[5]; + std::string result; + char buffer[5]; - forEach(str, [&] (char32_t code) { - encode(tolower(code), buffer); - result += buffer; - }); + forEach(str, [&] (char32_t code) { + encode(tolower(code), buffer); + result += buffer; + }); - return result; + return result; } } // !unicode
--- a/modules/xdg/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/xdg/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -17,8 +17,8 @@ # if (NOT WIN32) - code_define_module( - NAME xdg - SOURCES xdg.hpp - ) -endif () \ No newline at end of file + code_define_module( + NAME xdg + SOURCES xdg.hpp + ) +endif ()
--- a/modules/xdg/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/xdg/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -32,243 +32,243 @@ inline bool unsetenv(std::string name) { - name += "="; + name += "="; - _putenv(name.c_str()); + _putenv(name.c_str()); - return true; + return true; } inline bool setenv(const std::string &name, const std::string &value, bool) { - std::string t = name + "=" + value; + std::string t = name + "=" + value; - _putenv(t.c_str()); + _putenv(t.c_str()); - return true; + return true; } #endif TEST(HomeEmpty, config) { - ASSERT_TRUE(unsetenv("XDG_CONFIG_HOME") == 0); + ASSERT_TRUE(unsetenv("XDG_CONFIG_HOME") == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ(myhome + "/.config", xdg.configHome()); + ASSERT_EQ(myhome + "/.config", xdg.configHome()); } TEST(HomeEmpty, data) { - ASSERT_TRUE(unsetenv("XDG_DATA_HOME") == 0); + ASSERT_TRUE(unsetenv("XDG_DATA_HOME") == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ(myhome + "/.local/share", xdg.dataHome()); + ASSERT_EQ(myhome + "/.local/share", xdg.dataHome()); } TEST(HomeEmpty, cache) { - ASSERT_TRUE(unsetenv("XDG_CACHE_HOME") == 0); + ASSERT_TRUE(unsetenv("XDG_CACHE_HOME") == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ(myhome + "/.cache", xdg.cacheHome()); + ASSERT_EQ(myhome + "/.cache", xdg.cacheHome()); } TEST(HomeEmpty, runtime) { - ASSERT_TRUE(unsetenv("XDG_RUNTIME_DIR") == 0); + ASSERT_TRUE(unsetenv("XDG_RUNTIME_DIR") == 0); - Xdg xdg; + Xdg xdg; - ASSERT_TRUE(xdg.runtimeDir().empty()); + ASSERT_TRUE(xdg.runtimeDir().empty()); } TEST(HomeValid, config) { - ASSERT_TRUE(setenv("XDG_CONFIG_HOME", "/test/config", true) == 0); + ASSERT_TRUE(setenv("XDG_CONFIG_HOME", "/test/config", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ("/test/config", xdg.configHome()); + ASSERT_EQ("/test/config", xdg.configHome()); } TEST(HomeValid, data) { - ASSERT_TRUE(setenv("XDG_DATA_HOME", "/test/data", true) == 0); + ASSERT_TRUE(setenv("XDG_DATA_HOME", "/test/data", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ("/test/data", xdg.dataHome()); + ASSERT_EQ("/test/data", xdg.dataHome()); } TEST(HomeValid, cache) { - ASSERT_TRUE(setenv("XDG_CACHE_HOME", "/test/cache", true) == 0); + ASSERT_TRUE(setenv("XDG_CACHE_HOME", "/test/cache", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ("/test/cache", xdg.cacheHome()); + ASSERT_EQ("/test/cache", xdg.cacheHome()); } TEST(HomeValid, runtime) { - ASSERT_TRUE(setenv("XDG_RUNTIME_DIR", "/test/runtime", true) == 0); + ASSERT_TRUE(setenv("XDG_RUNTIME_DIR", "/test/runtime", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ("/test/runtime", xdg.runtimeDir()); + ASSERT_EQ("/test/runtime", xdg.runtimeDir()); } TEST(HomeInvalid, config) { - ASSERT_TRUE(setenv("XDG_CONFIG_HOME", "invalid", true) == 0); + ASSERT_TRUE(setenv("XDG_CONFIG_HOME", "invalid", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ(myhome + "/.config", xdg.configHome()); + ASSERT_EQ(myhome + "/.config", xdg.configHome()); } TEST(HomeInvalid, data) { - ASSERT_TRUE(setenv("XDG_DATA_HOME", "invalid", true) == 0); + ASSERT_TRUE(setenv("XDG_DATA_HOME", "invalid", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ(myhome + "/.local/share", xdg.dataHome()); + ASSERT_EQ(myhome + "/.local/share", xdg.dataHome()); } TEST(HomeInvalid, cache) { - ASSERT_TRUE(setenv("XDG_CACHE_HOME", "invalid", true) == 0); + ASSERT_TRUE(setenv("XDG_CACHE_HOME", "invalid", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_EQ(myhome + "/.cache", xdg.cacheHome()); + ASSERT_EQ(myhome + "/.cache", xdg.cacheHome()); } TEST(HomeInvalid, runtime) { - ASSERT_TRUE(setenv("XDG_RUNTIME_DIR", "invalid", true) == 0); + ASSERT_TRUE(setenv("XDG_RUNTIME_DIR", "invalid", true) == 0); - Xdg xdg; + Xdg xdg; - ASSERT_TRUE(xdg.runtimeDir().empty()); + ASSERT_TRUE(xdg.runtimeDir().empty()); } TEST(DirectoriesEmpty, config) { - ASSERT_TRUE(unsetenv("XDG_CONFIG_DIRS") == 0); + ASSERT_TRUE(unsetenv("XDG_CONFIG_DIRS") == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.configDirs(); + const auto &list = xdg.configDirs(); - ASSERT_EQ((size_t)1, list.size()); - ASSERT_EQ("/etc/xdg", list[0]); + ASSERT_EQ((size_t)1, list.size()); + ASSERT_EQ("/etc/xdg", list[0]); } TEST(DirectoriesEmpty, data) { - ASSERT_TRUE(unsetenv("XDG_DATA_DIRS") == 0); + ASSERT_TRUE(unsetenv("XDG_DATA_DIRS") == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.dataDirs(); + const auto &list = xdg.dataDirs(); - ASSERT_EQ((size_t)2, list.size()); - ASSERT_EQ("/usr/local/share", list[0]); - ASSERT_EQ("/usr/share", list[1]); + ASSERT_EQ((size_t)2, list.size()); + ASSERT_EQ("/usr/local/share", list[0]); + ASSERT_EQ("/usr/share", list[1]); } TEST(DirectoriesValid, config) { - ASSERT_TRUE(setenv("XDG_CONFIG_DIRS", "/config1:/config2", true) == 0); + ASSERT_TRUE(setenv("XDG_CONFIG_DIRS", "/config1:/config2", true) == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.configDirs(); + const auto &list = xdg.configDirs(); - ASSERT_EQ((size_t)2, list.size()); - ASSERT_EQ("/config1", list[0]); - ASSERT_EQ("/config2", list[1]); + ASSERT_EQ((size_t)2, list.size()); + ASSERT_EQ("/config1", list[0]); + ASSERT_EQ("/config2", list[1]); } TEST(DirectoriesValid, data) { - ASSERT_TRUE(setenv("XDG_DATA_DIRS", "/data1:/data2", true) == 0); + ASSERT_TRUE(setenv("XDG_DATA_DIRS", "/data1:/data2", true) == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.dataDirs(); + const auto &list = xdg.dataDirs(); - ASSERT_EQ((size_t)2, list.size()); - ASSERT_EQ("/data1", list[0]); - ASSERT_EQ("/data2", list[1]); + ASSERT_EQ((size_t)2, list.size()); + ASSERT_EQ("/data1", list[0]); + ASSERT_EQ("/data2", list[1]); } TEST(DirectoriesInvalid, config) { - ASSERT_TRUE(setenv("XDG_CONFIG_DIRS", "bad1:bad2", true) == 0); + ASSERT_TRUE(setenv("XDG_CONFIG_DIRS", "bad1:bad2", true) == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.configDirs(); + const auto &list = xdg.configDirs(); - ASSERT_EQ((size_t)1, list.size()); - ASSERT_EQ("/etc/xdg", list[0]); + ASSERT_EQ((size_t)1, list.size()); + ASSERT_EQ("/etc/xdg", list[0]); } TEST(DirectoriesInvalid, data) { - ASSERT_TRUE(setenv("XDG_DATA_DIRS", "bad1:bad2", true) == 0); + ASSERT_TRUE(setenv("XDG_DATA_DIRS", "bad1:bad2", true) == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.dataDirs(); + const auto &list = xdg.dataDirs(); - ASSERT_EQ((size_t)2, list.size()); - ASSERT_EQ("/usr/local/share", list[0]); - ASSERT_EQ("/usr/share", list[1]); + ASSERT_EQ((size_t)2, list.size()); + ASSERT_EQ("/usr/local/share", list[0]); + ASSERT_EQ("/usr/share", list[1]); } TEST(DirectoriesMixed, config) { - ASSERT_TRUE(setenv("XDG_CONFIG_DIRS", "/config1:bad:/config2", true) == 0); + ASSERT_TRUE(setenv("XDG_CONFIG_DIRS", "/config1:bad:/config2", true) == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.configDirs(); + const auto &list = xdg.configDirs(); - ASSERT_EQ((size_t)2, list.size()); - ASSERT_EQ("/config1", list[0]); - ASSERT_EQ("/config2", list[1]); + ASSERT_EQ((size_t)2, list.size()); + ASSERT_EQ("/config1", list[0]); + ASSERT_EQ("/config2", list[1]); } TEST(DirectoriesMixed, data) { - ASSERT_TRUE(setenv("XDG_DATA_DIRS", "/data1:bad:/data2", true) == 0); + ASSERT_TRUE(setenv("XDG_DATA_DIRS", "/data1:bad:/data2", true) == 0); - Xdg xdg; + Xdg xdg; - const auto &list = xdg.dataDirs(); + const auto &list = xdg.dataDirs(); - ASSERT_EQ((size_t)2, list.size()); - ASSERT_EQ("/data1", list[0]); - ASSERT_EQ("/data2", list[1]); + ASSERT_EQ((size_t)2, list.size()); + ASSERT_EQ("/data1", list[0]); + ASSERT_EQ("/data2", list[1]); } int main(int argc, char **argv) { - auto home = getenv("HOME"); + auto home = getenv("HOME"); - if (home == nullptr) - return 0; + if (home == nullptr) + return 0; - myhome = home; - InitGoogleTest(&argc, argv); + myhome = home; + InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/xdg/xdg.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/xdg/xdg.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -41,146 +41,146 @@ */ class Xdg { private: - std::string m_configHome; - std::string m_dataHome; - std::string m_cacheHome; - std::string m_runtimeDir; - std::vector<std::string> m_configDirs; - std::vector<std::string> m_dataDirs; + std::string m_configHome; + std::string m_dataHome; + std::string m_cacheHome; + std::string m_runtimeDir; + std::vector<std::string> m_configDirs; + std::vector<std::string> m_dataDirs; - bool isabsolute(const std::string &path) const noexcept - { - return path.length() > 0 && path[0] == '/'; - } + bool isabsolute(const std::string &path) const noexcept + { + return path.length() > 0 && path[0] == '/'; + } - std::vector<std::string> split(const std::string &arg) const - { - std::stringstream iss(arg); - std::string item; - std::vector<std::string> elems; + std::vector<std::string> split(const std::string &arg) const + { + std::stringstream iss(arg); + std::string item; + std::vector<std::string> elems; - while (std::getline(iss, item, ':')) - if (isabsolute(item)) - elems.push_back(item); + while (std::getline(iss, item, ':')) + if (isabsolute(item)) + elems.push_back(item); - return elems; - } + return elems; + } - std::string envOrHome(const std::string &var, const std::string &repl) const - { - auto value = std::getenv(var.c_str()); + std::string envOrHome(const std::string &var, const std::string &repl) const + { + auto value = std::getenv(var.c_str()); - if (value == nullptr || !isabsolute(value)) { - auto home = std::getenv("HOME"); + if (value == nullptr || !isabsolute(value)) { + auto home = std::getenv("HOME"); - if (home == nullptr) - throw std::runtime_error("could not get home directory"); + if (home == nullptr) + throw std::runtime_error("could not get home directory"); - return std::string(home) + "/" + repl; - } + return std::string(home) + "/" + repl; + } - return value; - } + return value; + } - std::vector<std::string> listOrDefaults(const std::string &var, const std::vector<std::string> &list) const - { - auto value = std::getenv(var.c_str()); + std::vector<std::string> listOrDefaults(const std::string &var, const std::vector<std::string> &list) const + { + auto value = std::getenv(var.c_str()); - if (!value) - return list; + if (!value) + return list; - // No valid item at all? Use defaults. - auto result = split(value); + // No valid item at all? Use defaults. + auto result = split(value); - return (result.size() == 0) ? list : result; - } + return (result.size() == 0) ? list : result; + } public: - /** - * Open an xdg instance and load directories. - * - * \throw std::runtime_error on failures - */ - Xdg() - { - m_configHome = envOrHome("XDG_CONFIG_HOME", ".config"); - m_dataHome = envOrHome("XDG_DATA_HOME", ".local/share"); - m_cacheHome = envOrHome("XDG_CACHE_HOME", ".cache"); + /** + * Open an xdg instance and load directories. + * + * \throw std::runtime_error on failures + */ + Xdg() + { + m_configHome = envOrHome("XDG_CONFIG_HOME", ".config"); + m_dataHome = envOrHome("XDG_DATA_HOME", ".local/share"); + m_cacheHome = envOrHome("XDG_CACHE_HOME", ".cache"); - m_configDirs = listOrDefaults("XDG_CONFIG_DIRS", { "/etc/xdg" }); - m_dataDirs = listOrDefaults("XDG_DATA_DIRS", { "/usr/local/share", "/usr/share" }); + m_configDirs = listOrDefaults("XDG_CONFIG_DIRS", { "/etc/xdg" }); + m_dataDirs = listOrDefaults("XDG_DATA_DIRS", { "/usr/local/share", "/usr/share" }); - /* - * Runtime directory is a special case and does not have a replacement, the application should manage - * this by itself. - */ - auto runtime = std::getenv("XDG_RUNTIME_DIR"); - if (runtime && isabsolute(runtime)) - m_runtimeDir = runtime; - } + /* + * Runtime directory is a special case and does not have a replacement, the application should manage + * this by itself. + */ + auto runtime = std::getenv("XDG_RUNTIME_DIR"); + if (runtime && isabsolute(runtime)) + m_runtimeDir = runtime; + } - /** - * Get the config directory. ${XDG_CONFIG_HOME} or ${HOME}/.config - * - * \return the config directory - */ - inline const std::string &configHome() const noexcept - { - return m_configHome; - } + /** + * Get the config directory. ${XDG_CONFIG_HOME} or ${HOME}/.config + * + * \return the config directory + */ + inline const std::string &configHome() const noexcept + { + return m_configHome; + } - /** - * Get the data directory. ${XDG_DATA_HOME} or ${HOME}/.local/share - * - * \return the data directory - */ - inline const std::string &dataHome() const noexcept - { - return m_dataHome; - } + /** + * Get the data directory. ${XDG_DATA_HOME} or ${HOME}/.local/share + * + * \return the data directory + */ + inline const std::string &dataHome() const noexcept + { + return m_dataHome; + } - /** - * Get the cache directory. ${XDG_CACHE_HOME} or ${HOME}/.cache - * - * \return the cache directory - */ - inline const std::string &cacheHome() const noexcept - { - return m_cacheHome; - } + /** + * Get the cache directory. ${XDG_CACHE_HOME} or ${HOME}/.cache + * + * \return the cache directory + */ + inline const std::string &cacheHome() const noexcept + { + return m_cacheHome; + } - /** - * Get the runtime directory. - * - * There is no replacement for XDG_RUNTIME_DIR, if it is not set, an empty valus is returned and the user is - * responsible of using something else. - * - * \return the runtime directory - */ - inline const std::string &runtimeDir() const noexcept - { - return m_runtimeDir; - } + /** + * Get the runtime directory. + * + * There is no replacement for XDG_RUNTIME_DIR, if it is not set, an empty valus is returned and the user is + * responsible of using something else. + * + * \return the runtime directory + */ + inline const std::string &runtimeDir() const noexcept + { + return m_runtimeDir; + } - /** - * Get the standard config directories. ${XDG_CONFIG_DIRS} or { "/etc/xdg" } - * - * \return the list of config directories - */ - inline const std::vector<std::string> &configDirs() const noexcept - { - return m_configDirs; - } + /** + * Get the standard config directories. ${XDG_CONFIG_DIRS} or { "/etc/xdg" } + * + * \return the list of config directories + */ + inline const std::vector<std::string> &configDirs() const noexcept + { + return m_configDirs; + } - /** - * Get the data directories. ${XDG_DATA_DIRS} or { "/usr/local/share", "/usr/share" } - * - * \return the list of data directories - */ - inline const std::vector<std::string> &dataDirs() const noexcept - { - return m_dataDirs; - } + /** + * Get the data directories. ${XDG_DATA_DIRS} or { "/usr/local/share", "/usr/share" } + * + * \return the list of data directories + */ + inline const std::vector<std::string> &dataDirs() const noexcept + { + return m_dataDirs; + } }; #endif // !XDG_HPP
--- a/modules/zip/CMakeLists.txt Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/zip/CMakeLists.txt Wed Jun 15 13:13:26 2016 +0200 @@ -19,8 +19,8 @@ add_subdirectory(libzip) code_define_module( - NAME zippy - SOURCES zippy.hpp - LIBRARIES zip - FLAGS DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}/test/data/\" + NAME zippy + SOURCES zippy.hpp + LIBRARIES zip + FLAGS DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}/test/data/\" ) \ No newline at end of file
--- a/modules/zip/test/main.cpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/zip/test/main.cpp Wed Jun 15 13:13:26 2016 +0200 @@ -30,52 +30,52 @@ TEST(Source, file) { - remove("output.zip"); + remove("output.zip"); - try { - Archive archive("output.zip", ZIP_CREATE); + try { + Archive archive("output.zip", ZIP_CREATE); - archive.add(file(DIRECTORY "data.txt"), "data.txt"); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + archive.add(file(DIRECTORY "data.txt"), "data.txt"); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } - try { - Archive archive("output.zip"); + try { + Archive archive("output.zip"); - auto stats = archive.stat("data.txt"); - auto file = archive.open("data.txt"); - auto content = file.read(stats.size); + auto stats = archive.stat("data.txt"); + auto file = archive.open("data.txt"); + auto content = file.read(stats.size); - ASSERT_EQ("abcdef\n", content); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("abcdef\n", content); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Source, buffer) { - remove("output.zip"); + remove("output.zip"); - try { - Archive archive("output.zip", ZIP_CREATE); + try { + Archive archive("output.zip", ZIP_CREATE); - archive.add(buffer("abcdef"), "data.txt"); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + archive.add(buffer("abcdef"), "data.txt"); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } - try { - Archive archive("output.zip"); + try { + Archive archive("output.zip"); - auto stats = archive.stat("data.txt"); - auto file = archive.open("data.txt"); - auto content = file.read(stats.size); + auto stats = archive.stat("data.txt"); + auto file = archive.open("data.txt"); + auto content = file.read(stats.size); - ASSERT_EQ("abcdef", content); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("abcdef", content); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -85,46 +85,46 @@ TEST(Write, simple) { - remove("output.zip"); + remove("output.zip"); - // Open first and save some data. - try { - Archive archive("output.zip", ZIP_CREATE); + // Open first and save some data. + try { + Archive archive("output.zip", ZIP_CREATE); - archive.add(buffer("hello world!"), "DATA"); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + archive.add(buffer("hello world!"), "DATA"); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } - try { - Archive archive("output.zip"); + try { + Archive archive("output.zip"); - auto stats = archive.stat("DATA"); - auto file = archive.open("DATA"); - auto content = file.read(stats.size); + auto stats = archive.stat("DATA"); + auto file = archive.open("DATA"); + auto content = file.read(stats.size); - ASSERT_EQ(static_cast<decltype(stats.size)>(12), stats.size); - ASSERT_EQ("hello world!", content); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(static_cast<decltype(stats.size)>(12), stats.size); + ASSERT_EQ("hello world!", content); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST(Write, notexist) { - remove("output.zip"); + remove("output.zip"); - try { - Archive archive("output.zip", ZIP_CREATE); + try { + Archive archive("output.zip", ZIP_CREATE); - /* - * According to the libzip, adding a file that does not exists - * on the disk is not an error. - */ - archive.add(file("file_not_exist"), "FILE"); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + /* + * According to the libzip, adding a file that does not exists + * on the disk is not an error. + */ + archive.add(file("file_not_exist"), "FILE"); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } /* @@ -134,163 +134,163 @@ class ReadingTest : public testing::Test { protected: - Archive m_archive; + Archive m_archive; public: - ReadingTest() - : m_archive(DIRECTORY "stats.zip") - { - } + ReadingTest() + : m_archive(DIRECTORY "stats.zip") + { + } }; TEST_F(ReadingTest, numEntries) { - ASSERT_EQ(static_cast<Int64>(4), m_archive.numEntries()); + ASSERT_EQ(static_cast<Int64>(4), m_archive.numEntries()); } TEST_F(ReadingTest, stat) { - try { - Stat stats = m_archive.stat("README"); + try { + Stat stats = m_archive.stat("README"); - ASSERT_EQ(static_cast<decltype(stats.size)>(15), stats.size); - ASSERT_STREQ("README", stats.name); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ(static_cast<decltype(stats.size)>(15), stats.size); + ASSERT_STREQ("README", stats.name); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(ReadingTest, exists) { - ASSERT_TRUE(m_archive.exists("README")); + ASSERT_TRUE(m_archive.exists("README")); } TEST_F(ReadingTest, read) { - try { - auto file = m_archive.open("README"); - auto stats = m_archive.stat("README"); - auto text = file.read(stats.size); + try { + auto file = m_archive.open("README"); + auto stats = m_archive.stat("README"); + auto text = file.read(stats.size); - ASSERT_EQ("This is a test\n", text); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + ASSERT_EQ("This is a test\n", text); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(ReadingTest, increment) { - { - Archive::iterator it = m_archive.begin(); + { + Archive::iterator it = m_archive.begin(); - ASSERT_STREQ("README", (*it++).name); - } + ASSERT_STREQ("README", (*it++).name); + } - { - Archive::iterator it = m_archive.begin(); + { + Archive::iterator it = m_archive.begin(); - ASSERT_STREQ("INSTALL", (*++it).name); - } + ASSERT_STREQ("INSTALL", (*++it).name); + } - { - Archive::iterator it = m_archive.begin() + 1; + { + Archive::iterator it = m_archive.begin() + 1; - ASSERT_STREQ("INSTALL", (*it).name); - } + ASSERT_STREQ("INSTALL", (*it).name); + } } TEST_F(ReadingTest, decrement) { - { - Archive::iterator it = m_archive.begin() + 1; + { + Archive::iterator it = m_archive.begin() + 1; - ASSERT_STREQ("INSTALL", (*it--).name); - } + ASSERT_STREQ("INSTALL", (*it--).name); + } - { - Archive::iterator it = m_archive.begin() + 1; + { + Archive::iterator it = m_archive.begin() + 1; - ASSERT_STREQ("README", (*--it).name); - } + ASSERT_STREQ("README", (*--it).name); + } - { - Archive::iterator it = m_archive.end() - 1; + { + Archive::iterator it = m_archive.end() - 1; - ASSERT_STREQ("doc/REFMAN", (*it).name); - } + ASSERT_STREQ("doc/REFMAN", (*it).name); + } } TEST_F(ReadingTest, constIncrement) { - { - Archive::const_iterator it = m_archive.cbegin(); + { + Archive::const_iterator it = m_archive.cbegin(); - ASSERT_STREQ("README", (*it++).name); - } + ASSERT_STREQ("README", (*it++).name); + } - { - Archive::const_iterator it = m_archive.cbegin(); + { + Archive::const_iterator it = m_archive.cbegin(); - ASSERT_STREQ("INSTALL", (*++it).name); - } + ASSERT_STREQ("INSTALL", (*++it).name); + } - { - Archive::const_iterator it = m_archive.cbegin() + 1; + { + Archive::const_iterator it = m_archive.cbegin() + 1; - ASSERT_STREQ("INSTALL", (*it).name); - } + ASSERT_STREQ("INSTALL", (*it).name); + } } TEST_F(ReadingTest, constDecrement) { - { - Archive::const_iterator it = m_archive.cbegin() + 1; + { + Archive::const_iterator it = m_archive.cbegin() + 1; - ASSERT_STREQ("INSTALL", (*it--).name); - } + ASSERT_STREQ("INSTALL", (*it--).name); + } - { - Archive::const_iterator it = m_archive.cbegin() + 1; + { + Archive::const_iterator it = m_archive.cbegin() + 1; - ASSERT_STREQ("README", (*--it).name); - } + ASSERT_STREQ("README", (*--it).name); + } - { - Archive::const_iterator it = m_archive.cend() - 1; + { + Archive::const_iterator it = m_archive.cend() - 1; - ASSERT_STREQ("doc/REFMAN", (*it).name); - } + ASSERT_STREQ("doc/REFMAN", (*it).name); + } } TEST_F(ReadingTest, access) { - { - Archive::iterator it = m_archive.begin(); + { + Archive::iterator it = m_archive.begin(); - ASSERT_STREQ("README", it->name); - ASSERT_STREQ("INSTALL", it[1].name); - } + ASSERT_STREQ("README", it->name); + ASSERT_STREQ("INSTALL", it[1].name); + } - { - Archive::const_iterator it = m_archive.cbegin(); + { + Archive::const_iterator it = m_archive.cbegin(); - ASSERT_STREQ("README", it->name); - ASSERT_STREQ("INSTALL", it[1].name); - } + ASSERT_STREQ("README", it->name); + ASSERT_STREQ("INSTALL", it[1].name); + } } TEST_F(ReadingTest, loop) { - std::vector<std::string> names{"README", "INSTALL", "doc/", "doc/REFMAN"}; - int i = 0; + std::vector<std::string> names{"README", "INSTALL", "doc/", "doc/REFMAN"}; + int i = 0; - for (const Stat &s : m_archive) - ASSERT_STREQ(names[i++].c_str(), s.name); + for (const Stat &s : m_archive) + ASSERT_STREQ(names[i++].c_str(), s.name); } int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); }
--- a/modules/zip/zippy.hpp Wed Jun 15 11:59:17 2016 +0200 +++ b/modules/zip/zippy.hpp Wed Jun 15 13:13:26 2016 +0200 @@ -106,82 +106,82 @@ */ class File { private: - std::unique_ptr<struct zip_file, int (*)(struct zip_file *)> m_handle; + std::unique_ptr<struct zip_file, int (*)(struct zip_file *)> m_handle; - File(const File &) = delete; - File &operator=(const File &) = delete; + File(const File &) = delete; + File &operator=(const File &) = delete; public: - /** - * Create a File with a zip_file structure. - * - * \param file the file ready to be used - */ - inline File(struct zip_file *file) noexcept - : m_handle(file, zip_fclose) - { - } + /** + * Create a File with a zip_file structure. + * + * \param file the file ready to be used + */ + inline File(struct zip_file *file) noexcept + : m_handle(file, zip_fclose) + { + } - /** - * Move constructor defaulted. - * - * \param other the other File - */ - File(File &&other) noexcept = default; + /** + * Move constructor defaulted. + * + * \param other the other File + */ + File(File &&other) noexcept = default; - /** - * Move operator defaulted. - * - * \return *this - */ - File &operator=(File &&) noexcept = default; + /** + * Move operator defaulted. + * + * \return *this + */ + File &operator=(File &&) noexcept = default; - /** - * Read some data. - * - * \param data the destination buffer - * \param length the length - * \return the number of bytes written or -1 on failure - */ - inline int read(void *data, Uint64 length) noexcept - { - return zip_fread(m_handle.get(), data, length); - } + /** + * Read some data. + * + * \param data the destination buffer + * \param length the length + * \return the number of bytes written or -1 on failure + */ + inline int read(void *data, Uint64 length) noexcept + { + return zip_fread(m_handle.get(), data, length); + } - /** - * Read some data to a fixed size array. - * - * \param data the array - * \return the number of bytes written or -1 on failure - */ - template <size_t Size> - inline int read(char (&data)[Size]) noexcept - { - return read(data, Size); - } + /** + * Read some data to a fixed size array. + * + * \param data the array + * \return the number of bytes written or -1 on failure + */ + template <size_t Size> + inline int read(char (&data)[Size]) noexcept + { + return read(data, Size); + } - /** - * Optimized function for reading all characters with only one allocation. - * Ideal for combining with Archive::stat. - * - * \param length the length of the file - * \return the whole string - * \see Archive::stat - */ - std::string read(Uint64 length) - { - std::string result; + /** + * Optimized function for reading all characters with only one allocation. + * Ideal for combining with Archive::stat. + * + * \param length the length of the file + * \return the whole string + * \see Archive::stat + */ + std::string read(Uint64 length) + { + std::string result; - result.resize(length); - auto count = read(&result[0], length); + result.resize(length); + auto count = read(&result[0], length); - if (count < 0) - return ""; + if (count < 0) + return ""; - result.resize(count); + result.resize(count); - return result; - } + return result; + } }; /** @@ -211,24 +211,24 @@ */ inline Source buffer(std::string data) noexcept { - return [=] (struct zip *archive) -> struct zip_source * { - auto size = data.size(); - auto ptr = static_cast<char *>(std::malloc(size)); + return [=] (struct zip *archive) -> struct zip_source * { + auto size = data.size(); + auto ptr = static_cast<char *>(std::malloc(size)); - if (ptr == nullptr) - throw std::runtime_error(std::strerror(errno)); + if (ptr == nullptr) + throw std::runtime_error(std::strerror(errno)); - std::memcpy(ptr, data.data(), size); + std::memcpy(ptr, data.data(), size); - auto src = zip_source_buffer(archive, ptr, size, 1); + auto src = zip_source_buffer(archive, ptr, size, 1); - if (src == nullptr) { - std::free(ptr); - throw std::runtime_error(zip_strerror(archive)); - } + if (src == nullptr) { + std::free(ptr); + throw std::runtime_error(zip_strerror(archive)); + } - return src; - }; + return src; + }; } /** @@ -241,14 +241,14 @@ */ inline Source file(std::string path, Uint64 start = 0, Int64 length = -1) noexcept { - return [=] (struct zip *archive) -> struct zip_source * { - auto src = zip_source_file(archive, path.c_str(), start, length); + return [=] (struct zip *archive) -> struct zip_source * { + auto src = zip_source_file(archive, path.c_str(), start, length); - if (src == nullptr) - throw std::runtime_error(zip_strerror(archive)); + if (src == nullptr) + throw std::runtime_error(zip_strerror(archive)); - return src; - }; + return src; + }; } } // !source @@ -259,58 +259,58 @@ */ class StatPtr { private: - Stat m_stat; + Stat m_stat; public: - /** - * Constructor. - * - * \param stat the file stat - */ - inline StatPtr(Stat stat) noexcept - : m_stat(stat) - { - } + /** + * Constructor. + * + * \param stat the file stat + */ + inline StatPtr(Stat stat) noexcept + : m_stat(stat) + { + } - /** - * Get the reference. - * - * \return the reference - */ - inline Stat &operator*() noexcept - { - return m_stat; - } + /** + * Get the reference. + * + * \return the reference + */ + inline Stat &operator*() noexcept + { + return m_stat; + } - /** - * Get the reference. - * - * \return the reference - */ - inline const Stat &operator*() const noexcept - { - return m_stat; - } + /** + * Get the reference. + * + * \return the reference + */ + inline const Stat &operator*() const noexcept + { + return m_stat; + } - /** - * Access the object. - * - * \return the pointer - */ - inline Stat *operator->() noexcept - { - return &m_stat; - } + /** + * Access the object. + * + * \return the pointer + */ + inline Stat *operator->() noexcept + { + return &m_stat; + } - /** - * Access the object. - * - * \return the pointer - */ - inline const Stat *operator->() const noexcept - { - return &m_stat; - } + /** + * Access the object. + * + * \return the pointer + */ + inline const Stat *operator->() const noexcept + { + return &m_stat; + } }; /** @@ -319,677 +319,677 @@ */ class Archive { private: - using Handle = std::unique_ptr<struct zip, int (*)(struct zip *)>; + using Handle = std::unique_ptr<struct zip, int (*)(struct zip *)>; - Handle m_handle; + Handle m_handle; - Archive(const Archive &) = delete; - Archive &operator=(const Archive &) = delete; + Archive(const Archive &) = delete; + Archive &operator=(const Archive &) = delete; public: - /** - * \brief Base iterator class - */ - class Iterator : public std::iterator<std::random_access_iterator_tag, Stat> { - private: - friend class Archive; + /** + * \brief Base iterator class + */ + class Iterator : public std::iterator<std::random_access_iterator_tag, Stat> { + private: + friend class Archive; - Archive *m_archive{nullptr}; - Uint64 m_index{0}; - - inline Iterator(Archive *archive, Uint64 index = 0) noexcept - : m_archive(archive) - , m_index(index) - { - } - - public: - /** - * Default iterator. - */ - Iterator() noexcept = default; - - /** - * Dereference the iterator. - * - * \return the stat information - */ - inline Stat operator*() const - { - assert(m_archive); - - return m_archive->stat(m_index); - } - - /** - * Dereference the iterator. - * - * \return the stat information as point - */ - inline StatPtr operator->() const - { - assert(m_archive); - - return StatPtr(m_archive->stat(m_index)); - } - - /** - * Post increment. - * - * \return this - */ - inline Iterator &operator++() noexcept - { - ++ m_index; - - return *this; - } - - /** - * Pre increment. - * - * \return this - */ - inline Iterator operator++(int) noexcept - { - Iterator save = *this; - - ++ m_index; - - return save; - } - - /** - * Post decrement. - * - * \return this - */ - inline Iterator &operator--() noexcept - { - -- m_index; - - return *this; - } - - /** - * Pre decrement. - * - * \return this - */ - inline Iterator operator--(int) noexcept - { - Iterator save = *this; - - -- m_index; - - return save; - } - - /** - * Increment. - * - * \param inc the number - * \return the new iterator - */ - inline Iterator operator+(int inc) const noexcept - { - return Iterator(m_archive, m_index + inc); - } - - /** - * Decrement. - * - * \param dec the number - * \return the new iterator - */ - inline Iterator operator-(int dec) const noexcept - { - return Iterator(m_archive, m_index - dec); - } - - /** - * Compare equality. - * - * \param other the other iterator - * \return true if same - */ - inline bool operator==(const Iterator &other) const noexcept - { - return m_index == other.m_index; - } - - /** - * Compare equality. - * - * \param other the other iterator - * \return true if different - */ - inline bool operator!=(const Iterator &other) const noexcept - { - return m_index != other.m_index; - } - - /** - * Access a stat information at the specified index. - * - * \pre must not be default-constructed - * \param index the new index - * \return stat information - * \throw std::runtime_error on errors - */ - inline Stat operator[](int index) - { - assert(m_archive); - - return m_archive->stat(m_index + index); - } - }; + Archive *m_archive{nullptr}; + Uint64 m_index{0}; + + inline Iterator(Archive *archive, Uint64 index = 0) noexcept + : m_archive(archive) + , m_index(index) + { + } + + public: + /** + * Default iterator. + */ + Iterator() noexcept = default; + + /** + * Dereference the iterator. + * + * \return the stat information + */ + inline Stat operator*() const + { + assert(m_archive); + + return m_archive->stat(m_index); + } + + /** + * Dereference the iterator. + * + * \return the stat information as point + */ + inline StatPtr operator->() const + { + assert(m_archive); + + return StatPtr(m_archive->stat(m_index)); + } + + /** + * Post increment. + * + * \return this + */ + inline Iterator &operator++() noexcept + { + ++ m_index; + + return *this; + } + + /** + * Pre increment. + * + * \return this + */ + inline Iterator operator++(int) noexcept + { + Iterator save = *this; + + ++ m_index; + + return save; + } + + /** + * Post decrement. + * + * \return this + */ + inline Iterator &operator--() noexcept + { + -- m_index; + + return *this; + } + + /** + * Pre decrement. + * + * \return this + */ + inline Iterator operator--(int) noexcept + { + Iterator save = *this; + + -- m_index; + + return save; + } + + /** + * Increment. + * + * \param inc the number + * \return the new iterator + */ + inline Iterator operator+(int inc) const noexcept + { + return Iterator(m_archive, m_index + inc); + } + + /** + * Decrement. + * + * \param dec the number + * \return the new iterator + */ + inline Iterator operator-(int dec) const noexcept + { + return Iterator(m_archive, m_index - dec); + } + + /** + * Compare equality. + * + * \param other the other iterator + * \return true if same + */ + inline bool operator==(const Iterator &other) const noexcept + { + return m_index == other.m_index; + } + + /** + * Compare equality. + * + * \param other the other iterator + * \return true if different + */ + inline bool operator!=(const Iterator &other) const noexcept + { + return m_index != other.m_index; + } + + /** + * Access a stat information at the specified index. + * + * \pre must not be default-constructed + * \param index the new index + * \return stat information + * \throw std::runtime_error on errors + */ + inline Stat operator[](int index) + { + assert(m_archive); + + return m_archive->stat(m_index + index); + } + }; public: - /** - * Iterator conversion to Stat. - */ - using value_type = Stat; + /** + * Iterator conversion to Stat. + */ + using value_type = Stat; - /** - * Reference is a copy of Stat. - */ - using reference = Stat; + /** + * Reference is a copy of Stat. + */ + using reference = Stat; - /** - * Const reference is a copy of Stat. - */ - using const_refernce = Stat; + /** + * Const reference is a copy of Stat. + */ + using const_refernce = Stat; - /** - * Pointer is a small wrapper - */ - using pointer = StatPtr; + /** + * Pointer is a small wrapper + */ + using pointer = StatPtr; - /** - * Type of difference. - */ - using size_type = unsigned; + /** + * Type of difference. + */ + using size_type = unsigned; - /** - * Random access iterator. - */ - using iterator = Iterator; + /** + * Random access iterator. + */ + using iterator = Iterator; - /** - * Const random access iterator. - */ - using const_iterator = Iterator; + /** + * Const random access iterator. + */ + using const_iterator = Iterator; public: - /** - * Open an archive on the disk. - * - * \param path the path - * \param flags the optional flags - * \throw std::runtime_error on errors - */ - Archive(const std::string &path, Flags flags = 0) - : m_handle(nullptr, nullptr) - { - int error; - struct zip *archive = zip_open(path.c_str(), flags, &error); + /** + * Open an archive on the disk. + * + * \param path the path + * \param flags the optional flags + * \throw std::runtime_error on errors + */ + Archive(const std::string &path, Flags flags = 0) + : m_handle(nullptr, nullptr) + { + int error; + struct zip *archive = zip_open(path.c_str(), flags, &error); - if (archive == nullptr) { - char buf[128]{0}; + if (archive == nullptr) { + char buf[128]{0}; - zip_error_to_str(buf, sizeof (buf), error, errno); + zip_error_to_str(buf, sizeof (buf), error, errno); - throw std::runtime_error(buf); - } + throw std::runtime_error(buf); + } - m_handle = { archive, zip_close }; - } + m_handle = { archive, zip_close }; + } - /** - * Move constructor defaulted. - * - * \param other the other Archive - */ - Archive(Archive &&other) noexcept = default; + /** + * Move constructor defaulted. + * + * \param other the other Archive + */ + Archive(Archive &&other) noexcept = default; - /** - * Move operator defaulted. - * - * \param other the other Archive - * \return *this - */ - Archive &operator=(Archive &&other) noexcept = default; + /** + * Move operator defaulted. + * + * \param other the other Archive + * \return *this + */ + Archive &operator=(Archive &&other) noexcept = default; - /** - * Get an iterator to the beginning. - * - * \return the iterator - */ - inline iterator begin() noexcept - { - return iterator(this); - } + /** + * Get an iterator to the beginning. + * + * \return the iterator + */ + inline iterator begin() noexcept + { + return iterator(this); + } - /** - * Overloaded function. - * - * \return the iterator - */ - inline const_iterator begin() const noexcept - { - return const_iterator(const_cast<Archive *>(this)); - } + /** + * Overloaded function. + * + * \return the iterator + */ + inline const_iterator begin() const noexcept + { + return const_iterator(const_cast<Archive *>(this)); + } - /** - * Overloaded function. - * - * \return the iterator - */ - inline const_iterator cbegin() const noexcept - { - return const_iterator(const_cast<Archive *>(this)); - } + /** + * Overloaded function. + * + * \return the iterator + */ + inline const_iterator cbegin() const noexcept + { + return const_iterator(const_cast<Archive *>(this)); + } - /** - * Get an iterator to the end. - * - * \return the iterator - */ - inline iterator end() noexcept - { - return iterator(this, numEntries()); - } + /** + * Get an iterator to the end. + * + * \return the iterator + */ + inline iterator end() noexcept + { + return iterator(this, numEntries()); + } - /** - * Overloaded function. - * - * \return the iterator - */ - inline const_iterator end() const noexcept - { - return const_iterator(const_cast<Archive *>(this), numEntries()); - } + /** + * Overloaded function. + * + * \return the iterator + */ + inline const_iterator end() const noexcept + { + return const_iterator(const_cast<Archive *>(this), numEntries()); + } - /** - * Overloaded function. - * - * \return the iterator - */ - inline const_iterator cend() const noexcept - { - return const_iterator(const_cast<Archive *>(this), numEntries()); - } + /** + * Overloaded function. + * + * \return the iterator + */ + inline const_iterator cend() const noexcept + { + return const_iterator(const_cast<Archive *>(this), numEntries()); + } - /** - * Set a comment on a file. - * - * \param index the file index in the archive - * \param text the text or empty to remove the comment - * \param flags the optional flags - * \throw std::runtime_error on errors - */ - void setFileComment(Uint64 index, const std::string &text = "", Flags flags = 0) - { - auto size = text.size(); - auto cstr = (size == 0) ? nullptr : text.c_str(); + /** + * Set a comment on a file. + * + * \param index the file index in the archive + * \param text the text or empty to remove the comment + * \param flags the optional flags + * \throw std::runtime_error on errors + */ + void setFileComment(Uint64 index, const std::string &text = "", Flags flags = 0) + { + auto size = text.size(); + auto cstr = (size == 0) ? nullptr : text.c_str(); - if (zip_file_set_comment(m_handle.get(), index, cstr, size, flags) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + if (zip_file_set_comment(m_handle.get(), index, cstr, size, flags) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Get a comment from a file. - * - * \param index the file index in the archive - * \param flags the optional flags - * \return the comment - * \throw std::runtime_error on errors - */ - std::string fileComment(Uint64 index, Flags flags = 0) const - { - zip_uint32_t length = 0; - auto text = zip_file_get_comment(m_handle.get(), index, &length, flags); + /** + * Get a comment from a file. + * + * \param index the file index in the archive + * \param flags the optional flags + * \return the comment + * \throw std::runtime_error on errors + */ + std::string fileComment(Uint64 index, Flags flags = 0) const + { + zip_uint32_t length = 0; + auto text = zip_file_get_comment(m_handle.get(), index, &length, flags); - if (text == nullptr) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (text == nullptr) + throw std::runtime_error(zip_strerror(m_handle.get())); - return std::string(text, length); - } + return std::string(text, length); + } - /** - * Set the archive comment. - * - * \param comment the comment - * \throw std::runtime_error on errors - */ - void setComment(const std::string &comment) - { - if (zip_set_archive_comment(m_handle.get(), comment.c_str(), comment.size()) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Set the archive comment. + * + * \param comment the comment + * \throw std::runtime_error on errors + */ + void setComment(const std::string &comment) + { + if (zip_set_archive_comment(m_handle.get(), comment.c_str(), comment.size()) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Get the archive comment. - * - * \param flags the optional flags - * \return the comment - * \throw std::runtime_error on errors - */ - std::string comment(Flags flags = 0) const - { - int length = 0; - auto text = zip_get_archive_comment(m_handle.get(), &length, flags); + /** + * Get the archive comment. + * + * \param flags the optional flags + * \return the comment + * \throw std::runtime_error on errors + */ + std::string comment(Flags flags = 0) const + { + int length = 0; + auto text = zip_get_archive_comment(m_handle.get(), &length, flags); - if (text == nullptr) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (text == nullptr) + throw std::runtime_error(zip_strerror(m_handle.get())); - return std::string(text, static_cast<std::size_t>(length)); - } + return std::string(text, static_cast<std::size_t>(length)); + } - /** - * Check if a file exists on the archive. - * - * \param name the name - * \param flags the optional flags - * \return if the file exists - */ - bool exists(const std::string &name, Flags flags = 0) const noexcept - { - return zip_name_locate(m_handle.get(), name.c_str(), flags) >= 0; - } + /** + * Check if a file exists on the archive. + * + * \param name the name + * \param flags the optional flags + * \return if the file exists + */ + bool exists(const std::string &name, Flags flags = 0) const noexcept + { + return zip_name_locate(m_handle.get(), name.c_str(), flags) >= 0; + } - /** - * Locate a file on the archive. - * - * \param name the name - * \param flags the optional flags - * \return the index - * \throw std::runtime_error on errors - */ - Int64 find(const std::string &name, Flags flags = 0) const - { - auto index = zip_name_locate(m_handle.get(), name.c_str(), flags); + /** + * Locate a file on the archive. + * + * \param name the name + * \param flags the optional flags + * \return the index + * \throw std::runtime_error on errors + */ + Int64 find(const std::string &name, Flags flags = 0) const + { + auto index = zip_name_locate(m_handle.get(), name.c_str(), flags); - if (index < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (index < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); - return index; - } + return index; + } - /** - * Get information about a file. - * - * \param name the name - * \param flags the optional flags - * \return the structure - * \throw std::runtime_error on errors - */ - Stat stat(const std::string &name, Flags flags = 0) const - { - Stat st; + /** + * Get information about a file. + * + * \param name the name + * \param flags the optional flags + * \return the structure + * \throw std::runtime_error on errors + */ + Stat stat(const std::string &name, Flags flags = 0) const + { + Stat st; - if (zip_stat(m_handle.get(), name.c_str(), flags, &st) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (zip_stat(m_handle.get(), name.c_str(), flags, &st) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); - return st; - } + return st; + } - /** - * Get information about a file. Overloaded function. - * - * \param index the file index in the archive - * \param flags the optional flags - * \return the structure - * \throw std::runtime_error on errors - */ - Stat stat(Uint64 index, Flags flags = 0) const - { - Stat st; + /** + * Get information about a file. Overloaded function. + * + * \param index the file index in the archive + * \param flags the optional flags + * \return the structure + * \throw std::runtime_error on errors + */ + Stat stat(Uint64 index, Flags flags = 0) const + { + Stat st; - if (zip_stat_index(m_handle.get(), index, flags, &st) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (zip_stat_index(m_handle.get(), index, flags, &st) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); - return st; - } + return st; + } - /** - * Add a file to the archive. - * - * \param source the source - * \param name the name entry in the archive - * \param flags the optional flags - * \return the new index in the archive - * \throw std::runtime_error on errors - * \see source::file - * \see source::buffer - */ - Int64 add(const Source &source, const std::string &name, Flags flags = 0) - { - auto src = source(m_handle.get()); - auto ret = zip_file_add(m_handle.get(), name.c_str(), src, flags); + /** + * Add a file to the archive. + * + * \param source the source + * \param name the name entry in the archive + * \param flags the optional flags + * \return the new index in the archive + * \throw std::runtime_error on errors + * \see source::file + * \see source::buffer + */ + Int64 add(const Source &source, const std::string &name, Flags flags = 0) + { + auto src = source(m_handle.get()); + auto ret = zip_file_add(m_handle.get(), name.c_str(), src, flags); - if (ret < 0) { - zip_source_free(src); - throw std::runtime_error(zip_strerror(m_handle.get())); - } + if (ret < 0) { + zip_source_free(src); + throw std::runtime_error(zip_strerror(m_handle.get())); + } - return ret; - } + return ret; + } - /** - * Create a directory in the archive. - * - * \param directory the directory name - * \param flags the optional flags - * \return the new index in the archive - * \throw std::runtime_error on errors - */ - Int64 mkdir(const std::string &directory, Flags flags = 0) - { - auto ret = zip_dir_add(m_handle.get(), directory.c_str(), flags); + /** + * Create a directory in the archive. + * + * \param directory the directory name + * \param flags the optional flags + * \return the new index in the archive + * \throw std::runtime_error on errors + */ + Int64 mkdir(const std::string &directory, Flags flags = 0) + { + auto ret = zip_dir_add(m_handle.get(), directory.c_str(), flags); - if (ret < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (ret < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); - return ret; - } + return ret; + } - /** - * Replace an existing file in the archive. - * - * \param source the source - * \param index the file index in the archiev - * \param flags the optional flags - * \throw std::runtime_error on errors - */ - void replace(const Source &source, Uint64 index, Flags flags = 0) - { - auto src = source(m_handle.get()); + /** + * Replace an existing file in the archive. + * + * \param source the source + * \param index the file index in the archiev + * \param flags the optional flags + * \throw std::runtime_error on errors + */ + void replace(const Source &source, Uint64 index, Flags flags = 0) + { + auto src = source(m_handle.get()); - if (zip_file_replace(m_handle.get(), index, src, flags) < 0) { - zip_source_free(src); - throw std::runtime_error(zip_strerror(m_handle.get())); - } - } + if (zip_file_replace(m_handle.get(), index, src, flags) < 0) { + zip_source_free(src); + throw std::runtime_error(zip_strerror(m_handle.get())); + } + } - /** - * Open a file in the archive. - * - * \param name the name - * \param flags the optional flags - * \param password the optional password - * \return the opened file - * \throw std::runtime_error on errors - */ - File open(const std::string &name, Flags flags = 0, const std::string &password = "") - { - struct zip_file *file; + /** + * Open a file in the archive. + * + * \param name the name + * \param flags the optional flags + * \param password the optional password + * \return the opened file + * \throw std::runtime_error on errors + */ + File open(const std::string &name, Flags flags = 0, const std::string &password = "") + { + struct zip_file *file; - if (password.size() > 0) - file = zip_fopen_encrypted(m_handle.get(), name.c_str(), flags, password.c_str()); - else - file = zip_fopen(m_handle.get(), name.c_str(), flags); + if (password.size() > 0) + file = zip_fopen_encrypted(m_handle.get(), name.c_str(), flags, password.c_str()); + else + file = zip_fopen(m_handle.get(), name.c_str(), flags); - if (file == nullptr) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (file == nullptr) + throw std::runtime_error(zip_strerror(m_handle.get())); - return file; - } + return file; + } - /** - * Open a file in the archive. Overloaded function. - * - * \param index the file index in the archive - * \param flags the optional flags - * \param password the optional password - * \return the opened file - * \throw std::runtime_error on errors - */ - File open(Uint64 index, Flags flags = 0, const std::string &password = "") - { - struct zip_file *file; + /** + * Open a file in the archive. Overloaded function. + * + * \param index the file index in the archive + * \param flags the optional flags + * \param password the optional password + * \return the opened file + * \throw std::runtime_error on errors + */ + File open(Uint64 index, Flags flags = 0, const std::string &password = "") + { + struct zip_file *file; - if (password.size() > 0) - file = zip_fopen_index_encrypted(m_handle.get(), index, flags, password.c_str()); - else - file = zip_fopen_index(m_handle.get(), index, flags); + if (password.size() > 0) + file = zip_fopen_index_encrypted(m_handle.get(), index, flags, password.c_str()); + else + file = zip_fopen_index(m_handle.get(), index, flags); - if (file == nullptr) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (file == nullptr) + throw std::runtime_error(zip_strerror(m_handle.get())); - return file; - } + return file; + } - /** - * Rename an existing entry in the archive. - * - * \param index the file index in the archive - * \param name the new name - * \param flags the optional flags - * \throw std::runtime_error on errors - */ - inline void rename(Uint64 index, const std::string &name, Flags flags = 0) - { - if (zip_file_rename(m_handle.get(), index, name.c_str(), flags) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Rename an existing entry in the archive. + * + * \param index the file index in the archive + * \param name the new name + * \param flags the optional flags + * \throw std::runtime_error on errors + */ + inline void rename(Uint64 index, const std::string &name, Flags flags = 0) + { + if (zip_file_rename(m_handle.get(), index, name.c_str(), flags) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Set file compression. - * - * \param index the file index in the archive - * \param comp the compression - * \param flags the optional flags - * \throw std::runtime_error on errors - */ - inline void setFileCompression(Uint64 index, Int32 comp, Uint32 flags = 0) - { - if (zip_set_file_compression(m_handle.get(), index, comp, flags) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Set file compression. + * + * \param index the file index in the archive + * \param comp the compression + * \param flags the optional flags + * \throw std::runtime_error on errors + */ + inline void setFileCompression(Uint64 index, Int32 comp, Uint32 flags = 0) + { + if (zip_set_file_compression(m_handle.get(), index, comp, flags) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Delete a file from the archive. - * - * \param index the file index in the archive - * \throw std::runtime_error on errors - */ - inline void remove(Uint64 index) - { - if (zip_delete(m_handle.get(), index) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Delete a file from the archive. + * + * \param index the file index in the archive + * \throw std::runtime_error on errors + */ + inline void remove(Uint64 index) + { + if (zip_delete(m_handle.get(), index) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Get the number of entries in the archive. - * - * \param flags the optional flags - * \return the number of entries - */ - inline Int64 numEntries(Flags flags = 0) const noexcept - { - return zip_get_num_entries(m_handle.get(), flags); - } + /** + * Get the number of entries in the archive. + * + * \param flags the optional flags + * \return the number of entries + */ + inline Int64 numEntries(Flags flags = 0) const noexcept + { + return zip_get_num_entries(m_handle.get(), flags); + } - /** - * Revert changes on the file. - * - * \param index the index - * \throw std::runtime_error on errors - */ - inline void unchange(Uint64 index) - { - if (zip_unchange(m_handle.get(), index) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Revert changes on the file. + * + * \param index the index + * \throw std::runtime_error on errors + */ + inline void unchange(Uint64 index) + { + if (zip_unchange(m_handle.get(), index) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Revert all changes. - * - * \throw std::runtime_error on errors - */ - inline void unchangeAll() - { - if (zip_unchange_all(m_handle.get()) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Revert all changes. + * + * \throw std::runtime_error on errors + */ + inline void unchangeAll() + { + if (zip_unchange_all(m_handle.get()) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Revert changes to archive. - * - * \throw std::runtime_error on errors - */ - void unchangeArchive() - { - if (zip_unchange_archive(m_handle.get()) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Revert changes to archive. + * + * \throw std::runtime_error on errors + */ + void unchangeArchive() + { + if (zip_unchange_archive(m_handle.get()) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Set the defaut password. - * - * \param password the password or empty to unset it - * \throw std::runtime_error on errors - */ - void setDefaultPassword(const std::string &password = "") - { - auto cstr = (password.size() > 0) ? password.c_str() : nullptr; + /** + * Set the defaut password. + * + * \param password the password or empty to unset it + * \throw std::runtime_error on errors + */ + void setDefaultPassword(const std::string &password = "") + { + auto cstr = (password.size() > 0) ? password.c_str() : nullptr; - if (zip_set_default_password(m_handle.get(), cstr) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + if (zip_set_default_password(m_handle.get(), cstr) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Set an archive flag. - * - * \param flag the flag to set - * \param value the value - * \throw std::runtime_error on errors - */ - inline void setFlag(Flags flag, int value) - { - if (zip_set_archive_flag(m_handle.get(), flag, value) < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); - } + /** + * Set an archive flag. + * + * \param flag the flag to set + * \param value the value + * \throw std::runtime_error on errors + */ + inline void setFlag(Flags flag, int value) + { + if (zip_set_archive_flag(m_handle.get(), flag, value) < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); + } - /** - * Get an archive flag. - * - * \param which which flag - * \param flags the optional flags - * \return the value - * \throw std::runtime_error on errors - */ - inline int flag(Flags which, Flags flags = 0) const - { - auto ret = zip_get_archive_flag(m_handle.get(), which, flags); + /** + * Get an archive flag. + * + * \param which which flag + * \param flags the optional flags + * \return the value + * \throw std::runtime_error on errors + */ + inline int flag(Flags which, Flags flags = 0) const + { + auto ret = zip_get_archive_flag(m_handle.get(), which, flags); - if (ret < 0) - throw std::runtime_error(zip_strerror(m_handle.get())); + if (ret < 0) + throw std::runtime_error(zip_strerror(m_handle.get())); - return ret; - } + return ret; + } }; } // !zippy
--- a/port/C/asprintf.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/asprintf.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * asprintf.c -- basic port of asprintf / vsprintf functions * - * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -39,17 +39,17 @@ int vasprintf(char **res, const char *fmt, va_list ap) { - int total = _vscprintf(fmt, ap); + int total = _vscprintf(fmt, ap); - if (total < 0) { - *res = NULL; - return -1; - } + if (total < 0) { + *res = NULL; + return -1; + } - if ((*res = (char *)malloc(sizeof (total) + 1)) == NULL) - return -1; + if ((*res = (char *)malloc(sizeof (total) + 1)) == NULL) + return -1; - return vsprintf_s(*res, total + 1, fmt, ap); + return vsprintf_s(*res, total + 1, fmt, ap); } #elif __STDC_VERSION__ >= 199901L @@ -60,29 +60,29 @@ int vasprintf(char **res, const char *fmt, va_list ap) { - int total, nwritten; - va_list copy; + int total, nwritten; + va_list copy; - va_copy(copy, ap); - total = vsnprintf(NULL, 0, fmt, copy); - va_end(copy); + va_copy(copy, ap); + total = vsnprintf(NULL, 0, fmt, copy); + va_end(copy); - if (total < 0) { - *res = NULL; - return total; - } + if (total < 0) { + *res = NULL; + return total; + } - if ((*res = malloc(total + 1)) == NULL) - return -1; + if ((*res = malloc(total + 1)) == NULL) + return -1; - if ((nwritten = vsnprintf(*res, total + 1, fmt, ap)) < 0) { - free(*res); - *res = NULL; + if ((nwritten = vsnprintf(*res, total + 1, fmt, ap)) < 0) { + free(*res); + *res = NULL; - return -1; - } + return -1; + } - return nwritten; + return nwritten; } #else @@ -93,24 +93,24 @@ int vasprintf(char **res, const char *format, va_list ap) { - int rvalue, ok; - size_t base = 80; + int rvalue, ok; + size_t base = 80; - if ((*res = malloc(base)) == NULL) - return -1; + if ((*res = malloc(base)) == NULL) + return -1; - ok = 0; - do { - rvalue = vsnprintf(*res, base, format, ap); + ok = 0; + do { + rvalue = vsnprintf(*res, base, format, ap); - if ((signed int)base <= rvalue || rvalue < 0) { - *res = realloc(*res, base * 2); - base *= 2; - } else - ok = 1; - } while (!ok && *res != NULL); + if ((signed int)base <= rvalue || rvalue < 0) { + *res = realloc(*res, base * 2); + base *= 2; + } else + ok = 1; + } while (!ok && *res != NULL); - return rvalue; + return rvalue; } #endif @@ -118,12 +118,12 @@ int asprintf(char **res, const char *fmt, ...) { - va_list ap; - int rvalue; + va_list ap; + int rvalue; - va_start(ap, fmt); - rvalue = vasprintf(res, fmt, ap); - va_end(ap); + va_start(ap, fmt); + rvalue = vasprintf(res, fmt, ap); + va_end(ap); - return rvalue; + return rvalue; }
--- a/port/C/asprintf.h Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/asprintf.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * asprintf.h -- basic port of asprintf / vsprintf functions * - * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,6 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef ASPRINTF_H +#define ASPRINTF_H + #include <stdarg.h> #ifdef __cplusplus @@ -23,14 +26,19 @@ #endif #ifdef __GNUC__ -# define _asp_at_printf(i1, i2) __attribute__ ((format (printf, i1, i2))) +# define ASPRINTF_FMT(i1, i2) __attribute__ ((format (printf, i1, i2))) #else -# define _asp_at_printf(i1, i2) +# define ASPRINTF_FMT(i1, i2) #endif -int asprintf(char **, const char *, ...) _asp_at_printf(2, 3); -int vasprintf(char **, const char *, va_list); +int +asprintf(char **, const char *, ...) ASPRINTF_FMT(2, 3); + +int +vasprintf(char **, const char *, va_list); #ifdef __cplusplus } #endif + +#endif /* !ASPRINTF_H */
--- a/port/C/err.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/err.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * err.c -- formtted error messages (portable version) * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -33,82 +33,82 @@ void err(int val, const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - verr(val, fmt, ap); - va_end(ap); + va_start(ap, fmt); + verr(val, fmt, ap); + va_end(ap); } void verr(int val, const char *fmt, va_list ap) { - if (fmt) { - vfprintf(stderr, fmt, ap); - fprintf(stderr, ": "); - } + if (fmt) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } - fprintf(stderr, "%s\n", strerror(errno)); - exit(val); + fprintf(stderr, "%s\n", strerror(errno)); + exit(val); } void errx(int val, const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - verrx(val, fmt, ap); - va_end(ap); + va_start(ap, fmt); + verrx(val, fmt, ap); + va_end(ap); } void verrx(int val, const char *fmt, va_list ap) { - if (fmt) - vfprintf(stderr, fmt, ap); + if (fmt) + vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); - exit(val); + exit(val); } void warn(const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - vwarn(fmt, ap); - va_end(ap); + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); } void vwarn(const char *fmt, va_list ap) { - if (fmt) { - vfprintf(stderr, fmt, ap); - fprintf(stderr, ": "); - } + if (fmt) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } - fprintf(stderr, "%s\n", strerror(errno)); + fprintf(stderr, "%s\n", strerror(errno)); } void warnx(const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - vwarnx(fmt, ap); - va_end(ap); + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); } void vwarnx(const char *fmt, va_list ap) { - if (fmt) - vfprintf(stderr, fmt, ap); + if (fmt) + vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); }
--- a/port/C/err.h Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/err.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * err.h -- formtted error messages (portable version) * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef _ERR_H_ -#define _ERR_H_ +#ifndef ERR_H +#define ERR_H #include <stdarg.h> @@ -25,58 +25,38 @@ extern "C" { #endif -/* - * Attribute noreturn may helps. This may produce a warning with GCC 4.5: - * - * int a; - * - * if ((a = getstate() < 0) - * errx(1, "State failed"); - * - * Because compilator does not know that errx will call exit may produce - * a warning like `a may be used uninitialized'. - */ - #if defined(__GNUC__) -# define __at_noreturn __attribute__ ((noreturn)) +# define ERR_NORETURN __attribute__ ((noreturn)) #elif defined(_MSC_VER) -# define __at_noreturn __declspec(noreturn) +# define ERR_NORETURN __declspec(noreturn) #endif -/* - * err() functions append the format message to the stderr FILE pointer. They - * also append the system error using strerror(errno). Then the functions exit - * with the error code given as first argument. - */ +void +err(int, const char *, ...) ERR_NORETURN; + +void +verr(int, const char *, va_list) ERR_NORETURN; -void err(int, const char *, ...) __at_noreturn; -void verr(int, const char *, va_list) __at_noreturn; +void +errx(int, const char *, ...) ERR_NORETURN; -/* - * errx() functions are similar to err() except that they do not append the - * system error message. - */ +void +verrx(int, const char *, va_list) ERR_NORETURN; -void errx(int, const char *, ...) __at_noreturn; -void verrx(int, const char *, va_list) __at_noreturn; +void +warn(const char *, ...); -/* - * warn() functions are similar to err() but they do not call exit(). - */ +void +vwarn(const char *, va_list); -void warn(const char *, ...); -void vwarn(const char *, va_list); +void +warnx(const char *, ...); -/* - * warnx() functions are similar to warn() except that they do not append the - * system error message. - */ - -void warnx(const char *, ...); -void vwarnx(const char *, va_list); +void +vwarnx(const char *, va_list); #ifdef __cplusplus } #endif -#endif /* _ERR_H_ */ +#endif /* ERR_H */
--- a/port/C/setprogname.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/setprogname.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * setprogname.c -- get or set the program name * - * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,22 +24,22 @@ * Do not return NULL if the developer didn't call setprogname to * prevent useless segfault. */ -static const char *g_pname = ""; +static const char *g_pname = ""; void setprogname(const char *progname) { - const char *p; + const char *p; - /* Seek last / or \ on windows */ - if ((p = strrchr(progname, '/')) || (p = strrchr(progname, '\\'))) - g_pname = &p[1]; - else - g_pname = progname; + /* Seek last / or \ on windows */ + if ((p = strrchr(progname, '/')) || (p = strrchr(progname, '\\'))) + g_pname = &p[1]; + else + g_pname = progname; } const char * getprogname(void) { - return g_pname; + return g_pname; }
--- a/port/C/setprogname.h Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/setprogname.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * setprogname.h -- get or set the program name * - * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,13 +16,21 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef SETPROGNAME_H +#define SETPROGNAME_H + #ifdef __cplusplus extern "C" { #endif -void setprogname(const char *); -const char *getprogname(void); +void +setprogname(const char *); + +const char * +getprogname(void); #ifdef __cplusplus } #endif + +#endif /* !SETPROGNAME_H */
--- a/port/C/strdup.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/strdup.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * strdup.c -- duplicate a string * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,13 +23,13 @@ char * strdup(const char *src) { - char *dst; - size_t len; + char *dst; + size_t len; - len = strlen(src); + len = strlen(src); - if ((dst = calloc(len + 1, sizeof (char))) == NULL) - return NULL; + if ((dst = calloc(len + 1, sizeof (char))) == NULL) + return NULL; - return strcpy(dst, src); + return strcpy(dst, src); }
--- a/port/C/strdup.h Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/strdup.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * strdup.h -- duplicate a string * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,13 +16,18 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef STRDUP_H +#define STRDUP_H + #ifdef __cplusplus extern "C" { #endif -char *strdup(const char *); +char * +strdup(const char *); #ifdef __cplusplus } #endif +#endif /* !STRDUP_H */ \ No newline at end of file
--- a/port/C/strndup.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/strndup.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * strndup.c -- duplicate a string * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,14 +23,14 @@ char * strndup(const char *src, size_t len) { - size_t tocopy; - char *dst; + size_t tocopy; + char *dst; - for (tocopy = 0; tocopy < len && src[tocopy] != '\0'; ++tocopy) - continue; + for (tocopy = 0; tocopy < len && src[tocopy] != '\0'; ++tocopy) + continue; - if ((dst = calloc(tocopy + 1, 1)) != NULL) - strncpy(dst, src, tocopy); + if ((dst = calloc(tocopy + 1, 1)) != NULL) + strncpy(dst, src, tocopy); - return dst; + return dst; }
--- a/port/C/strndup.h Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/strndup.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * strndup.h -- duplicate a string * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,12 +16,18 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef STRNDUP_H +#define STRNDUP_H + #ifdef __cplusplus extern "C" { #endif -char *strndup(const char *, size_t); +char * +strndup(const char *, size_t); #ifdef __cplusplus } #endif + +#endif /* !STRNDUP_H */ \ No newline at end of file
--- a/port/C/strsep.c Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/strsep.c Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * strsep.c -- separate a string by delimiters * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -22,19 +22,19 @@ char * strsep(char **stringp, const char *delim) { - char *item, *ptr; + char *item, *ptr; - if (*stringp == NULL || delim[0] == '\0') - return NULL; + if (*stringp == NULL || delim[0] == '\0') + return NULL; - item = *stringp; - if ((ptr = strpbrk(*stringp, delim)) == NULL) { - *stringp = NULL; - return item; - } + item = *stringp; + if ((ptr = strpbrk(*stringp, delim)) == NULL) { + *stringp = NULL; + return item; + } - *ptr = '\0'; - *stringp = ptr + 1; + *ptr = '\0'; + *stringp = ptr + 1; - return item; + return item; }
--- a/port/C/strsep.h Wed Jun 15 11:59:17 2016 +0200 +++ b/port/C/strsep.h Wed Jun 15 13:13:26 2016 +0200 @@ -1,7 +1,7 @@ /* * strsep.h -- separate a string by delimiters * - * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> + * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,12 +16,18 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef STRSEP_H +#define STRSEP_H + #ifdef __cplusplus extern "C" { #endif -char *strsep(char **, const char *); +char * +strsep(char **, const char *); #ifdef __cplusplus } #endif + +#endif /* !STRSEP_H */ \ No newline at end of file