locale/build/has_icu_test.cpp
Alexander Grund ec1676280e
Raise minimum ICU version to 4.8.1
A lot of checks and a major workaround are for ICU 4.8 or earlier which
can be removed.
An annoying bug (Parsing of timezones like "GMT" in "full" format followed by unrelated text)
fixed in 4.8.1 is worth avoiding by requiring this version over 4.8.0.
2024-12-27 12:14:43 +01:00

48 lines
1.6 KiB
C++

// Copyright (c) 2010 John Maddock
// Copyright (c) 2022-2024 Alexander Grund
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <unicode/coll.h>
#include <unicode/locid.h>
#include <unicode/numfmt.h>
#include <unicode/stringpiece.h>
#include <unicode/uchar.h>
#include <unicode/utypes.h>
#include <unicode/uversion.h>
// Sanity check to avoid false negatives for version checks
#ifndef U_ICU_VERSION_MAJOR_NUM
# error "U_ICU_VERSION_MAJOR_NUM is missing"
#endif
#ifndef U_ICU_VERSION_MINOR_NUM
# error "U_ICU_VERSION_MINOR_NUM is missing"
#endif
#ifndef U_ICU_VERSION_PATCHLEVEL_NUM
# error "U_ICU_VERSION_PATCHLEVEL_NUM is missing"
#endif
#define BOOST_LOCALE_MAKE_VERSION(maj, min, patch) (((maj)*100 + (min)) * 100 + patch)
#define BOOST_LOCALE_ICU_VERSION \
BOOST_LOCALE_MAKE_VERSION(U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM)
#if BOOST_LOCALE_ICU_VERSION < BOOST_LOCALE_MAKE_VERSION(4, 8, 1)
// 4.8.0 fails parsing "GMT" as a full time zone if followed by unrelated text
# error "ICU 4.8.1 or higher is required"
#endif
#if BOOST_LOCALE_ICU_VERSION == BOOST_LOCALE_MAKE_VERSION(50, 1, 0)
// https://unicode-org.atlassian.net/browse/ICU-9780
# error "ICU 50.1.0 has a bug with integer parsing and cannot be used reliably"
#endif
int main()
{
icu::Locale loc;
UErrorCode err = U_ZERO_ERROR;
UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, "GREEK SMALL LETTER ALPHA", &err);
delete icu::NumberFormat::createInstance(loc, UNUM_CURRENCY_ISO, err);
icu::StringPiece sp;
return U_SUCCESS(err) && sp.empty() && (c != 0u);
}