Update ICU testing and usage.

This commit is contained in:
jzmaddock
2021-10-10 15:51:51 +01:00
parent 732d9755bd
commit fc25325cd2
6 changed files with 162 additions and 21 deletions

View File

@ -27,7 +27,7 @@ jobs:
- name: Add repository
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
- name: Install packages
run: sudo apt install g++-9 g++-10 clang-9 clang-10
run: sudo apt install g++-9 g++-10 clang-9 clang-10 libicu-dev
- name: Checkout main boost
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
- name: Update tools/boostdep
@ -78,7 +78,7 @@ jobs:
- name: Add repository
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
- name: Install packages
run: sudo apt install g++-7 g++-8 clang-7 clang-8
run: sudo apt install g++-7 g++-8 clang-7 clang-8 libicu-dev
- name: Checkout main boost
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
- name: Update tools/boostdep
@ -331,6 +331,8 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Install packages
run: sudo apt install libicu-dev
- name: Checkout main boost
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
- name: Update tools/boostdep
@ -352,3 +354,15 @@ jobs:
cmake ..
cmake --build .
cmake --build . --target check
rm -rf *
cmake -DBOOST_REGEX_STANDALONE ..
cmake --build .
cmake --build . --target check
cd ../cmake_subdir_test_icu && mkdir __build__ && cd __build__
cmake ..
cmake --build .
cmake --build . --target check
rm -rf *
cmake -DBOOST_REGEX_STANDALONE ..
cmake --build .
cmake --build . --target check

View File

@ -13,11 +13,57 @@ add_library(Boost::regex ALIAS boost_regex)
target_include_directories(boost_regex INTERFACE include)
target_link_libraries(boost_regex
INTERFACE
Boost::config
Boost::throw_exception
Boost::predef
Boost::assert
)
option(BOOST_REGEX_STANDALONE "Boost.Regex: Enable Standalone Mode (i.e. no Boost dependencies)")
if(NOT BOOST_REGEX_STANDALONE)
target_link_libraries(boost_regex
INTERFACE
Boost::config
Boost::throw_exception
Boost::predef
Boost::assert
)
else()
target_compile_definitions(boost_regex
INTERFACE BOOST_REGEX_STANDALONE
)
endif()
find_package(ICU COMPONENTS data i18n uc QUIET)
#option(BOOST_REGEX_ENABLE_ICU "Boost.Regex: enable ICU support" ${ICU_FOUND})
if(ICU_FOUND)
add_library(boost_regex_icu INTERFACE)
add_library(Boost::regex_icu ALIAS boost_regex_icu)
target_include_directories(boost_regex_icu INTERFACE include)
if(NOT BOOST_REGEX_STANDALONE)
target_link_libraries(boost_regex_icu
INTERFACE
Boost::config
Boost::throw_exception
Boost::predef
Boost::assert
)
else()
target_compile_definitions(boost_regex_icu
INTERFACE BOOST_REGEX_STANDALONE
)
endif()
find_package(ICU COMPONENTS data i18n uc REQUIRED)
target_link_libraries(boost_regex_icu INTERFACE ICU::data ICU::i18n ICU::uc)
endif()

View File

@ -35,6 +35,10 @@ in order to do this you must either:
then the library will automoatically enter standalone mode. Or:
* Define BOOST_REGEX_STANDALONE when building.
If you are using this library with ICU, note that since it is now header only, it will be up to you
to link to the ICU libraries if you use `<boost/regex/icu.hpp>`. Also note that the installed CMake file
for Boost.Regex [/does not] list ICU as a dependency.
[h4 [*C++03 users only (Deprecated)] Building with bjam]
This is now the preferred method for building and installing this library,

View File

@ -0,0 +1,22 @@
# Copyright 2018, 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/regex)
add_subdirectory(../../../config boostorg/config)
add_subdirectory(../../../core boostorg/core)
add_subdirectory(../../../assert boostorg/assert)
add_subdirectory(../../../throw_exception boostorg/throw_exception)
add_subdirectory(../../../predef boostorg/predef)
add_executable(quick_icu ../quick_icu.cpp)
target_link_libraries(quick_icu Boost::regex_icu)
enable_testing()
add_test(quick_icu quick_icu)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@ -10,7 +10,7 @@
// See library home page at http://www.boost.org/libs/regex
#include <boost/regex.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cassert>
#include <string>
bool validate_card_format(const std::string& s)
@ -37,19 +37,19 @@ int main()
{
std::string s[ 4 ] = { "0000111122223333", "0000 1111 2222 3333", "0000-1111-2222-3333", "000-1111-2222-3333" };
BOOST_TEST( !validate_card_format( s[0] ) );
BOOST_TEST_EQ( machine_readable_card_number( s[0] ), s[0] );
BOOST_TEST_EQ( human_readable_card_number( s[0] ), s[2] );
assert(!validate_card_format(s[0]));
assert(machine_readable_card_number(s[0]) == s[0]);
assert(human_readable_card_number(s[0]) == s[2]);
BOOST_TEST( validate_card_format( s[1] ) );
BOOST_TEST_EQ( machine_readable_card_number( s[1] ), s[0] );
BOOST_TEST_EQ( human_readable_card_number( s[1] ), s[2] );
assert(validate_card_format(s[1]));
assert(machine_readable_card_number(s[1]) == s[0]);
assert(human_readable_card_number(s[1]) == s[2]);
BOOST_TEST( validate_card_format( s[2] ) );
BOOST_TEST_EQ( machine_readable_card_number( s[2] ), s[0] );
BOOST_TEST_EQ( human_readable_card_number( s[2] ), s[2] );
assert(validate_card_format(s[2]));
assert(machine_readable_card_number(s[2]) == s[0]);
assert(human_readable_card_number(s[2]) == s[2]);
BOOST_TEST( !validate_card_format( s[3] ) );
assert(!validate_card_format(s[3]));
return boost::report_errors();
return 0;
}

55
test/quick_icu.cpp Normal file
View File

@ -0,0 +1,55 @@
// Copyright 1998-2002 John Maddock
// Copyright 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/regex
#include <boost/regex/icu.hpp>
#include <cassert>
#include <string>
bool validate_card_format(const std::string& s)
{
static const boost::u32regex e = boost::make_u32regex("(\\d{4}[- ]){3}\\d{4}");
return boost::u32regex_match(s, e);
}
const boost::u32regex card_rx = boost::make_u32regex("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
const std::string machine_format("\\1\\2\\3\\4");
const std::string human_format("\\1-\\2-\\3-\\4");
std::string machine_readable_card_number(const std::string& s)
{
return boost::u32regex_replace(s, card_rx, machine_format, boost::match_default | boost::format_sed);
}
std::string human_readable_card_number(const std::string& s)
{
return boost::u32regex_replace(s, card_rx, human_format, boost::match_default | boost::format_sed);
}
int main()
{
std::string s[ 4 ] = { "0000111122223333", "0000 1111 2222 3333", "0000-1111-2222-3333", "000-1111-2222-3333" };
assert( !validate_card_format( s[0] ) );
assert( machine_readable_card_number( s[0] ) == s[0] );
assert( human_readable_card_number( s[0] ) == s[2] );
assert( validate_card_format( s[1] ) );
assert( machine_readable_card_number( s[1] ) == s[0] );
assert( human_readable_card_number( s[1] ) == s[2] );
assert( validate_card_format( s[2] ) );
assert( machine_readable_card_number( s[2] ) == s[0] );
assert( human_readable_card_number( s[2] ) == s[2] );
assert( !validate_card_format( s[3] ) );
return 0;
}