Allow Collators to have their language specified, and specify it for tests.
authorCarl Hetherington <cth@carlh.net>
Tue, 17 Jan 2023 20:50:59 +0000 (21:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 17 Jan 2023 21:41:46 +0000 (22:41 +0100)
src/lib/collator.cc
src/lib/collator.h
test/collator_test.cc

index ba504fb6e62ba83dbfc6c449852c599816849cd4..8de1857abeb6c24c988f9e5b2536be94b67b2c6a 100644 (file)
@@ -36,10 +36,10 @@ using std::string;
 using std::vector;
 
 
 using std::vector;
 
 
-Collator::Collator()
+Collator::Collator(char const* locale)
 {
        UErrorCode status = U_ZERO_ERROR;
 {
        UErrorCode status = U_ZERO_ERROR;
-       _collator = ucol_open(nullptr, &status);
+       _collator = ucol_open(locale, &status);
        if (_collator) {
                ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
                /* Ignore case and character encoding (and probably some other things) */
        if (_collator) {
                ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
                /* Ignore case and character encoding (and probably some other things) */
index 1768c43c09595d3ef880b79b67549343a7ea5c28..3cbb407487b7dd7fa0a18406456fc9f43baa7f64 100644 (file)
@@ -32,7 +32,7 @@ struct UCollator;
 class Collator
 {
 public:
 class Collator
 {
 public:
-       Collator();
+       Collator(char const* locale = nullptr);
        ~Collator();
 
        Collator(Collator const &) = delete;
        ~Collator();
 
        Collator(Collator const &) = delete;
index e88d71b06d27a0510b0f534f8ee77746270feefe..477b3747f0b2b90cfb99f33cde2e3720c5212c0c 100644 (file)
@@ -25,7 +25,7 @@
 
 BOOST_AUTO_TEST_CASE(collator_compare_works_and_ignores_case)
 {
 
 BOOST_AUTO_TEST_CASE(collator_compare_works_and_ignores_case)
 {
-       Collator collator;
+       Collator collator("en");
 
        BOOST_CHECK_EQUAL(collator.compare("So often YOU won't even notice", "SO OFTEN you won't even NOTiCE"), 0);
        BOOST_CHECK_EQUAL(collator.compare("So often YOU won't even notice", "SO OFTEN you won't even see"), -1);
 
        BOOST_CHECK_EQUAL(collator.compare("So often YOU won't even notice", "SO OFTEN you won't even NOTiCE"), 0);
        BOOST_CHECK_EQUAL(collator.compare("So often YOU won't even notice", "SO OFTEN you won't even see"), -1);
@@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(collator_compare_works_and_ignores_case)
 
 BOOST_AUTO_TEST_CASE(collator_search_works_and_ignores_case)
 {
 
 BOOST_AUTO_TEST_CASE(collator_search_works_and_ignores_case)
 {
-       Collator collator;
+       Collator collator("en");
 
        BOOST_CHECK(collator.find("outh", "With filthy mouths, and bad attitudes"));
        BOOST_CHECK(collator.find("with", "With filthy mouths, and bad attitudes"));
 
        BOOST_CHECK(collator.find("outh", "With filthy mouths, and bad attitudes"));
        BOOST_CHECK(collator.find("with", "With filthy mouths, and bad attitudes"));