Skip to content

Commit c9ca5c6

Browse files
committed
Raise minimum ICU version to 4.2
StringPiece is only available in 4.2+ and is required for proper parsing and formatting. As this version is now "old enough", just assume 4.2+ removing many conditionals.
1 parent 8e8ce12 commit c9ca5c6

File tree

7 files changed

+16
-71
lines changed

7 files changed

+16
-71
lines changed

doc/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- 1.88.0
1212
- Fix parsing of numbers in floating point format to integers
13+
- Require ICU 4.2 or later
1314
- 1.86.0
1415
- Make ICU implementation of `to_title` threadsafe
1516
- Add allocator support to `utf_to_utf`

src/boost/locale/icu/collator.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@
1616
#include <limits>
1717
#include <memory>
1818
#include <unicode/coll.h>
19+
#include <unicode/stringpiece.h>
1920
#include <vector>
20-
#if BOOST_LOCALE_ICU_VERSION >= 402
21-
# define BOOST_LOCALE_WITH_STRINGPIECE 1
22-
# include <unicode/stringpiece.h>
23-
#else
24-
# define BOOST_LOCALE_WITH_STRINGPIECE 0
25-
#endif
2621

2722
#ifdef BOOST_MSVC
2823
# pragma warning(disable : 4244) // 'argument' : conversion from 'int'
@@ -43,7 +38,6 @@ namespace boost { namespace locale { namespace impl_icu {
4338
return res;
4439
}
4540

46-
#if BOOST_LOCALE_WITH_STRINGPIECE
4741
int do_utf8_compare(collate_level level,
4842
const char* b1,
4943
const char* e1,
@@ -55,7 +49,6 @@ namespace boost { namespace locale { namespace impl_icu {
5549
icu::StringPiece right(b2, e2 - b2);
5650
return get_collator(level).compareUTF8(left, right, status);
5751
}
58-
#endif
5952

6053
int do_ustring_compare(collate_level level,
6154
const CharType* b1,
@@ -159,7 +152,6 @@ namespace boost { namespace locale { namespace impl_icu {
159152
bool is_utf8_;
160153
};
161154

162-
#if BOOST_LOCALE_WITH_STRINGPIECE
163155
template<>
164156
int collate_impl<char>::do_real_compare(collate_level level,
165157
const char* b1,
@@ -173,7 +165,7 @@ namespace boost { namespace locale { namespace impl_icu {
173165
else
174166
return do_ustring_compare(level, b1, e1, b2, e2, status);
175167
}
176-
#endif
168+
177169
std::locale create_collate(const std::locale& in, const cdata& cd, char_facet_t type)
178170
{
179171
switch(type) {

src/boost/locale/icu/conversion.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
#include <limits>
1414
#include <unicode/locid.h>
1515
#include <unicode/normlzr.h>
16+
#include <unicode/ucasemap.h>
1617
#include <unicode/ustring.h>
17-
#if BOOST_LOCALE_ICU_VERSION >= 308
18-
# include <unicode/ucasemap.h>
19-
# define BOOST_LOCALE_WITH_CASEMAP
20-
#endif
2118
#include <vector>
2219

2320
namespace boost { namespace locale { namespace impl_icu {
@@ -72,7 +69,6 @@ namespace boost { namespace locale { namespace impl_icu {
7269
std::string encoding_;
7370
}; // converter_impl
7471

75-
#ifdef BOOST_LOCALE_WITH_CASEMAP
7672
template<typename T>
7773
struct get_casemap_size_type;
7874

@@ -193,26 +189,17 @@ namespace boost { namespace locale { namespace impl_icu {
193189
raii_casemap<U8Char> map_;
194190
}; // converter_impl
195191

196-
#endif // BOOST_LOCALE_WITH_CASEMAP
197-
198192
std::locale create_convert(const std::locale& in, const cdata& cd, char_facet_t type)
199193
{
200194
switch(type) {
201195
case char_facet_t::nochar: break;
202196
case char_facet_t::char_f:
203-
#ifdef BOOST_LOCALE_WITH_CASEMAP
204197
if(cd.is_utf8())
205198
return std::locale(in, new utf8_converter_impl<char>(cd));
206-
#endif
207199
return std::locale(in, new converter_impl<char>(cd));
208200
case char_facet_t::wchar_f: return std::locale(in, new converter_impl<wchar_t>(cd));
209201
#ifndef BOOST_LOCALE_NO_CXX20_STRING8
210-
case char_facet_t::char8_f:
211-
# if defined(BOOST_LOCALE_WITH_CASEMAP)
212-
return std::locale(in, new utf8_converter_impl<char8_t>(cd));
213-
# else
214-
return std::locale(in, new converter_impl<char8_t>(cd));
215-
# endif
202+
case char_facet_t::char8_f: return std::locale(in, new utf8_converter_impl<char8_t>(cd));
216203
#elif defined(__cpp_char8_t)
217204
case char_facet_t::char8_f: break;
218205
#endif

src/boost/locale/icu/date_time.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ namespace boost { namespace locale { namespace impl_icu {
6767
const double rounded_time = std::floor(calendar_->getTime(err) / U_MILLIS_PER_SECOND) * U_MILLIS_PER_SECOND;
6868
calendar_->setTime(rounded_time, err);
6969
check_and_throw_dt(err);
70-
#if BOOST_LOCALE_ICU_VERSION < 402
71-
// workaround old/invalid data, it should be 4 in general
72-
calendar_->setMinimalDaysInFirstWeek(4);
73-
#endif
7470
encoding_ = dat.encoding();
7571
}
7672
calendar_impl(const calendar_impl& other)
@@ -79,15 +75,9 @@ namespace boost { namespace locale { namespace impl_icu {
7975
encoding_ = other.encoding_;
8076
}
8177

82-
calendar_impl* clone() const override
83-
{
84-
return new calendar_impl(*this);
85-
}
78+
calendar_impl* clone() const override { return new calendar_impl(*this); }
8679

87-
void set_value(period::marks::period_mark p, int value) override
88-
{
89-
calendar_->set(to_icu(p), int32_t(value));
90-
}
80+
void set_value(period::marks::period_mark p, int value) override { calendar_->set(to_icu(p), int32_t(value)); }
9181

9282
int get_value(period::marks::period_mark p, value_type type) const override
9383
{
@@ -202,10 +192,7 @@ namespace boost { namespace locale { namespace impl_icu {
202192
check_and_throw_dt(err);
203193
return diff;
204194
}
205-
void set_timezone(const std::string& tz) override
206-
{
207-
calendar_->adoptTimeZone(get_time_zone(tz));
208-
}
195+
void set_timezone(const std::string& tz) override { calendar_->adoptTimeZone(get_time_zone(tz)); }
209196
std::string get_timezone() const override
210197
{
211198
icu::UnicodeString tz;

src/boost/locale/icu/formatters_cache.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,13 @@ namespace boost { namespace locale { namespace impl_icu {
9292
case num_fmt_type::curr_iso:
9393
return icu::NumberFormat::createInstance(locale_, UNUM_CURRENCY_ISO, err);
9494
break;
95-
#elif BOOST_LOCALE_ICU_VERSION >= 402
95+
#else
9696
case num_fmt_type::curr_nat:
9797
return icu::NumberFormat::createInstance(locale_, icu::NumberFormat::kCurrencyStyle, err);
9898
break;
9999
case num_fmt_type::curr_iso:
100100
return icu::NumberFormat::createInstance(locale_, icu::NumberFormat::kIsoCurrencyStyle, err);
101101
break;
102-
#else
103-
case num_fmt_type::curr_nat:
104-
case num_fmt_type::curr_iso: return icu::NumberFormat::createCurrencyInstance(locale_, err); break;
105102
#endif
106103
case num_fmt_type::percent: return icu::NumberFormat::createPercentInstance(locale_, err); break;
107104
case num_fmt_type::spell: return new icu::RuleBasedNumberFormat(icu::URBNF_SPELLOUT, locale_, err); break;

src/boost/locale/icu/time_zone.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313
// Bug - when ICU tries to find a file that is equivalent to /etc/localtime it finds /usr/share/zoneinfo/localtime
1414
// that is just a symbolic link to /etc/localtime.
1515
//
16-
// It started in 4.0 and was fixed in version 4.6, also the fix was backported to the 4.4 branch so it should be
16+
// It was fixed in version 4.6, also the fix was backported to the 4.4 branch so it should be
1717
// available from 4.4.3... So we test if the workaround is required
1818
//
1919
// It is also relevant only for Linux, BSD and Apple (as I see in ICU code)
2020
//
2121

22-
#if BOOST_LOCALE_ICU_VERSION >= 400 && BOOST_LOCALE_ICU_VERSION <= 406 \
23-
&& (BOOST_LOCALE_ICU_VERSION != 404 || U_ICU_VERSION_PATCHLEVEL_NUM >= 3)
22+
#if BOOST_LOCALE_ICU_VERSION <= 406 && (BOOST_LOCALE_ICU_VERSION != 404 || U_ICU_VERSION_PATCHLEVEL_NUM >= 3)
2423
# if BOOST_OS_LINUX || BOOST_OS_BSD_FREE || defined(__APPLE__)
2524
# define BOOST_LOCALE_WORKAROUND_ICU_BUG
2625
# endif

test/test_formatting.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@ std::string from_icu_string(const icu::UnicodeString& str)
4949
# define BOOST_LOCALE_ICU_VERSION_EXACT 0
5050
#endif
5151

52-
// Currency style changes between ICU versions, so get "real" value from ICU
53-
#if BOOST_LOCALE_ICU_VERSION >= 402
54-
5552
std::string get_icu_currency_iso(const double value)
5653
{
57-
# if BOOST_LOCALE_ICU_VERSION >= 408
54+
#if BOOST_LOCALE_ICU_VERSION >= 408
5855
auto styleIso = UNUM_CURRENCY_ISO;
59-
# else
56+
#else
6057
auto styleIso = icu::NumberFormat::kIsoCurrencyStyle;
61-
# endif
58+
#endif
6259
UErrorCode err = U_ZERO_ERROR;
6360
std::unique_ptr<icu::NumberFormat> fmt(icu::NumberFormat::createInstance(get_icu_test_locale(), styleIso, err));
6461
TEST_REQUIRE(U_SUCCESS(err) && fmt.get());
@@ -67,8 +64,6 @@ std::string get_icu_currency_iso(const double value)
6764
return from_icu_string(fmt->format(value, tmp));
6865
}
6966

70-
#endif
71-
7267
using format_style_t = std::ios_base&(std::ios_base&);
7368

7469
#ifdef BOOST_LOCALE_WITH_ICU
@@ -425,12 +420,11 @@ void test_manip(std::string e_charset = "UTF-8")
425420

426421
TEST_PARSE_FAILS(as::currency, "$", double);
427422

428-
#if BOOST_LOCALE_ICU_VERSION >= 402
429423
TEST_FMT_PARSE_2(as::currency, as::currency_national, 1345, "$1,345.00");
430424
TEST_FMT_PARSE_2(as::currency, as::currency_national, 1345.34, "$1,345.34");
431425
TEST_FMT_PARSE_2(as::currency, as::currency_iso, 1345, get_icu_currency_iso(1345));
432426
TEST_FMT_PARSE_2(as::currency, as::currency_iso, 1345.34, get_icu_currency_iso(1345.34));
433-
#endif
427+
434428
TEST_FMT_PARSE_1(as::spellout, 10, "ten");
435429
#if 402 <= BOOST_LOCALE_ICU_VERSION && BOOST_LOCALE_ICU_VERSION < 408
436430
if(e_charset == "UTF-8")
@@ -503,15 +497,13 @@ void test_manip(std::string e_charset = "UTF-8")
503497
a_datetime,
504498
icu_time_long,
505499
a_time + a_timesec);
506-
#if !(BOOST_LOCALE_ICU_VERSION == 308 && defined(__CYGWIN__)) // Known failure due to ICU issue
507500
TEST_PARSE(as::time >> as::time_full >> as::time_zone("GMT+01:00"), "4:33:13 PM GMT+01:00", a_time + a_timesec);
508501
TEST_FMT_PARSE_3_2(as::time,
509502
as::time_full,
510503
as::time_zone("GMT+01:00"),
511504
a_datetime,
512505
icu_time_full,
513506
a_time + a_timesec);
514-
#endif
515507

516508
const std::string icu_def = get_ICU_datetime(as::time, a_datetime);
517509
const std::string icu_short = get_ICU_datetime(as::time_short, a_datetime);
@@ -760,11 +752,7 @@ void test_format_class(std::string charset = "UTF-8")
760752

761753
// format with locale & encoding
762754
{
763-
#if BOOST_LOCALE_ICU_VERSION >= 400
764755
const auto expected = boost::locale::conv::utf_to_utf<CharType>("10,00\xC2\xA0");
765-
#else
766-
const auto expected = boost::locale::conv::utf_to_utf<CharType>("10,00 €"); // LCOV_EXCL_LINE
767-
#endif
768756
TEST_EQ(do_format<CharType>(loc, "{1,cur,locale=de_DE.UTF-8}", 10), expected);
769757
}
770758

@@ -792,20 +780,14 @@ void test_format_class(std::string charset = "UTF-8")
792780
TEST_FORMAT_CLS("{1,cur}", 1234, "$1,234.00");
793781
TEST_FORMAT_CLS("{1,currency}", 1234, "$1,234.00");
794782
if(charset == "UTF-8") {
795-
#if BOOST_LOCALE_ICU_VERSION >= 400
796783
TEST_FORMAT_CLS("{1,cur,locale=de_DE}", 10, "10,00\xC2\xA0");
797-
#else
798-
TEST_FORMAT_CLS("{1,cur,locale=de_DE}", 10, "10,00 €"); // LCOV_EXCL_LINE
799-
#endif
800784
}
801-
#if BOOST_LOCALE_ICU_VERSION >= 402
802785
TEST_FORMAT_CLS("{1,cur=nat}", 1234, "$1,234.00");
803786
TEST_FORMAT_CLS("{1,cur=national}", 1234, "$1,234.00");
804787
TEST_FORMAT_CLS("{1,cur=iso}", 1234, get_icu_currency_iso(1234));
805-
#endif
806788
TEST_FORMAT_CLS("{1,spell}", 10, "ten");
807789
TEST_FORMAT_CLS("{1,spellout}", 10, "ten");
808-
#if 402 <= BOOST_LOCALE_ICU_VERSION && BOOST_LOCALE_ICU_VERSION < 408
790+
#if BOOST_LOCALE_ICU_VERSION < 408
809791
if(charset == "UTF-8") {
810792
TEST_FORMAT_CLS("{1,ord}", 1, "1\xcb\xa2\xe1\xb5\x97");
811793
TEST_FORMAT_CLS("{1,ordinal}", 1, "1\xcb\xa2\xe1\xb5\x97");

0 commit comments

Comments
 (0)