mirror of
https://github.com/boostorg/locale.git
synced 2026-01-19 04:22:08 +00:00
Modernize using nullptr
This commit is contained in:
@@ -21,12 +21,13 @@ int main()
|
||||
std::cout.imbue(loc);
|
||||
// Set as default locale for output
|
||||
|
||||
std::cout << format("Today {1,date} at {1,time} we had run our first localization example") % time(0) << std::endl;
|
||||
std::cout << format("Today {1,date} at {1,time} we had run our first localization example") % std::time(nullptr)
|
||||
<< std::endl;
|
||||
|
||||
std::cout << "This is how we show numbers in this locale " << as::number << 103.34 << std::endl;
|
||||
std::cout << "This is how we show currency in this locale " << as::currency << 103.34 << std::endl;
|
||||
std::cout << "This is typical date in the locale " << as::date << std::time(0) << std::endl;
|
||||
std::cout << "This is typical time in the locale " << as::time << std::time(0) << std::endl;
|
||||
std::cout << "This is typical date in the locale " << as::date << std::time(nullptr) << std::endl;
|
||||
std::cout << "This is typical time in the locale " << as::time << std::time(nullptr) << std::endl;
|
||||
std::cout << "This is upper case " << to_upper("Hello World!") << std::endl;
|
||||
std::cout << "This is lower case " << to_lower("Hello World!") << std::endl;
|
||||
std::cout << "This is title case " << to_title("Hello World!") << std::endl;
|
||||
|
||||
@@ -27,7 +27,8 @@ int main(int argc, char** argv)
|
||||
for(int i = 0; i < 100000; i++) {
|
||||
std::ostringstream ss;
|
||||
for(int j = 0; j < 5; j++) {
|
||||
ss << boost::locale::as::datetime << std::time(0) << " " << boost::locale::as::number << 13456.345 << "\n";
|
||||
ss << boost::locale::as::datetime << std::time(nullptr) << " " << boost::locale::as::number << 13456.345
|
||||
<< "\n";
|
||||
}
|
||||
if(i == 0)
|
||||
std::cout << ss.str() << std::endl;
|
||||
|
||||
@@ -22,13 +22,13 @@ int main()
|
||||
// converting strings to narrow on some platforms
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
|
||||
std::wcout << wformat(L"Today {1,date} at {1,time} we had run our first localization example") % time(0)
|
||||
std::wcout << wformat(L"Today {1,date} at {1,time} we had run our first localization example") % std::time(nullptr)
|
||||
<< std::endl;
|
||||
|
||||
std::wcout << L"This is how we show numbers in this locale " << as::number << 103.34 << std::endl;
|
||||
std::wcout << L"This is how we show currency in this locale " << as::currency << 103.34 << std::endl;
|
||||
std::wcout << L"This is typical date in the locale " << as::date << std::time(0) << std::endl;
|
||||
std::wcout << L"This is typical time in the locale " << as::time << std::time(0) << std::endl;
|
||||
std::wcout << L"This is typical date in the locale " << as::date << std::time(nullptr) << std::endl;
|
||||
std::wcout << L"This is typical time in the locale " << as::time << std::time(nullptr) << std::endl;
|
||||
std::wcout << L"This is upper case " << to_upper(L"Hello World!") << std::endl;
|
||||
std::wcout << L"This is lower case " << to_lower(L"Hello World!") << std::endl;
|
||||
std::wcout << L"This is title case " << to_title(L"Hello World!") << std::endl;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace boost { namespace locale { namespace boundary {
|
||||
typedef mapping<base_iterator> mapping_type;
|
||||
typedef segment<base_iterator> segment_type;
|
||||
|
||||
segment_index_iterator() : current_(0, 0), map_(0), mask_(0), full_select_(false) {}
|
||||
segment_index_iterator() : current_(0, 0), map_(nullptr), mask_(0), full_select_(false) {}
|
||||
|
||||
segment_index_iterator(base_iterator p, const mapping_type* map, rule_type mask, bool full_select) :
|
||||
map_(map), mask_(mask), full_select_(full_select)
|
||||
@@ -296,7 +296,7 @@ namespace boost { namespace locale { namespace boundary {
|
||||
typedef mapping<base_iterator> mapping_type;
|
||||
typedef boundary_point<base_iterator> boundary_point_type;
|
||||
|
||||
boundary_point_index_iterator() : current_(0), map_(0), mask_(0) {}
|
||||
boundary_point_index_iterator() : current_(0), map_(nullptr), mask_(0) {}
|
||||
|
||||
boundary_point_index_iterator(bool is_begin, const mapping_type* map, rule_type mask) :
|
||||
map_(map), mask_(mask)
|
||||
|
||||
@@ -710,7 +710,7 @@ namespace boost { namespace locale {
|
||||
///
|
||||
/// For example:
|
||||
/// \code
|
||||
/// date_time now(time(0),hebrew_calendar)
|
||||
/// date_time now(time(nullptr),hebrew_calendar)
|
||||
/// std::cout << "Year: " << period::year(now) << " Full Date:" << now;
|
||||
/// \endcode
|
||||
///
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace boost { namespace locale {
|
||||
typedef std::basic_ostream<CharType> stream_type;
|
||||
typedef void (*writer_type)(stream_type& output, const void* ptr);
|
||||
|
||||
formattible() : pointer_(0), writer_(&formattible::void_write) {}
|
||||
formattible() : pointer_(nullptr), writer_(&formattible::void_write) {}
|
||||
|
||||
formattible(const formattible&) = default;
|
||||
formattible(formattible&&) = default;
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace boost { namespace locale {
|
||||
template<typename Char>
|
||||
std::basic_string<Char> get() const
|
||||
{
|
||||
if(type == 0 || *type != typeid(Char))
|
||||
if(type == nullptr || *type != typeid(Char))
|
||||
throw std::bad_cast();
|
||||
std::basic_string<Char> result = reinterpret_cast<const Char*>(ptr);
|
||||
return result;
|
||||
|
||||
@@ -150,25 +150,25 @@ namespace boost { namespace locale {
|
||||
typedef message_format<char_type> facet_type; ///< The type of the facet the messages are fetched with
|
||||
|
||||
/// Create default empty message
|
||||
basic_message() : n_(0), c_id_(0), c_context_(0), c_plural_(0) {}
|
||||
basic_message() : n_(0), c_id_(nullptr), c_context_(nullptr), c_plural_(nullptr) {}
|
||||
|
||||
/// Create a simple message from 0 terminated string. The string should exist
|
||||
/// until the message is destroyed. Generally useful with static constant strings
|
||||
explicit basic_message(const char_type* id) : n_(0), c_id_(id), c_context_(0), c_plural_(0) {}
|
||||
explicit basic_message(const char_type* id) : n_(0), c_id_(id), c_context_(nullptr), c_plural_(nullptr) {}
|
||||
|
||||
/// Create a simple plural form message from 0 terminated strings. The strings should exist
|
||||
/// until the message is destroyed. Generally useful with static constant strings.
|
||||
///
|
||||
/// \a n is the number, \a single and \a plural are singular and plural forms of the message
|
||||
explicit basic_message(const char_type* single, const char_type* plural, count_type n) :
|
||||
n_(n), c_id_(single), c_context_(0), c_plural_(plural)
|
||||
n_(n), c_id_(single), c_context_(nullptr), c_plural_(plural)
|
||||
{}
|
||||
|
||||
/// Create a simple message from 0 terminated strings, with context
|
||||
/// information. The string should exist
|
||||
/// until the message is destroyed. Generally useful with static constant strings
|
||||
explicit basic_message(const char_type* context, const char_type* id) :
|
||||
n_(0), c_id_(id), c_context_(context), c_plural_(0)
|
||||
n_(0), c_id_(id), c_context_(context), c_plural_(nullptr)
|
||||
{}
|
||||
|
||||
/// Create a simple plural form message from 0 terminated strings, with context. The strings should exist
|
||||
@@ -184,18 +184,20 @@ namespace boost { namespace locale {
|
||||
{}
|
||||
|
||||
/// Create a simple message from a string.
|
||||
explicit basic_message(const string_type& id) : n_(0), c_id_(0), c_context_(0), c_plural_(0), id_(id) {}
|
||||
explicit basic_message(const string_type& id) :
|
||||
n_(0), c_id_(nullptr), c_context_(nullptr), c_plural_(nullptr), id_(id)
|
||||
{}
|
||||
|
||||
/// Create a simple plural form message from strings.
|
||||
///
|
||||
/// \a n is the number, \a single and \a plural are single and plural forms of the message
|
||||
explicit basic_message(const string_type& single, const string_type& plural, count_type number) :
|
||||
n_(number), c_id_(0), c_context_(0), c_plural_(0), id_(single), plural_(plural)
|
||||
n_(number), c_id_(nullptr), c_context_(nullptr), c_plural_(nullptr), id_(single), plural_(plural)
|
||||
{}
|
||||
|
||||
/// Create a simple message from a string with context.
|
||||
explicit basic_message(const string_type& context, const string_type& id) :
|
||||
n_(0), c_id_(0), c_context_(0), c_plural_(0), id_(id), context_(context)
|
||||
n_(0), c_id_(nullptr), c_context_(nullptr), c_plural_(nullptr), id_(id), context_(context)
|
||||
{}
|
||||
|
||||
/// Create a simple plural form message from strings.
|
||||
@@ -206,7 +208,7 @@ namespace boost { namespace locale {
|
||||
const string_type& plural,
|
||||
count_type number) :
|
||||
n_(number),
|
||||
c_id_(0), c_context_(0), c_plural_(0), id_(single), context_(context), plural_(plural)
|
||||
c_id_(nullptr), c_context_(nullptr), c_plural_(nullptr), id_(single), context_(context), plural_(plural)
|
||||
{}
|
||||
|
||||
/// Copy an object
|
||||
@@ -279,7 +281,7 @@ namespace boost { namespace locale {
|
||||
if(c_plural_)
|
||||
return c_plural_;
|
||||
if(plural_.empty())
|
||||
return 0;
|
||||
return nullptr;
|
||||
return plural_.c_str();
|
||||
}
|
||||
const char_type* context() const
|
||||
@@ -287,7 +289,7 @@ namespace boost { namespace locale {
|
||||
if(c_context_)
|
||||
return c_context_;
|
||||
if(context_.empty())
|
||||
return 0;
|
||||
return nullptr;
|
||||
return context_.c_str();
|
||||
}
|
||||
|
||||
@@ -304,11 +306,11 @@ namespace boost { namespace locale {
|
||||
if(*id == 0)
|
||||
return empty_string;
|
||||
|
||||
const facet_type* facet = 0;
|
||||
const facet_type* facet = nullptr;
|
||||
if(std::has_facet<facet_type>(loc))
|
||||
facet = &std::use_facet<facet_type>(loc);
|
||||
|
||||
const char_type* translated = 0;
|
||||
const char_type* translated = nullptr;
|
||||
if(facet) {
|
||||
if(!plural) {
|
||||
translated = facet->get(domain_id, context, id);
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace boost { namespace locale { namespace conv { namespace impl {
|
||||
if(state == normal)
|
||||
res = conv(&begin, &in_left, &out_ptr, &out_left);
|
||||
else
|
||||
res = conv(0, 0, &out_ptr, &out_left);
|
||||
res = conv(nullptr, nullptr, &out_ptr, &out_left);
|
||||
|
||||
int err = errno;
|
||||
|
||||
|
||||
@@ -203,8 +203,8 @@ namespace boost { namespace locale { namespace conv { namespace impl {
|
||||
|
||||
std::vector<wchar_t> tmp; // buffer for mb2w
|
||||
std::wstring tmps; // buffer for utf_to_utf
|
||||
const wchar_t* wbegin = 0;
|
||||
const wchar_t* wend = 0;
|
||||
const wchar_t* wbegin = nullptr;
|
||||
const wchar_t* wend = nullptr;
|
||||
|
||||
if(from_code_page_ == 65001) {
|
||||
tmps = utf_to_utf<wchar_t>(begin, end, how_);
|
||||
@@ -315,11 +315,9 @@ namespace boost { namespace locale { namespace conv { namespace impl {
|
||||
if(code_page_ == 65001) {
|
||||
return utf_to_utf<char>(begin, end, how_);
|
||||
}
|
||||
const wchar_t* wbegin = 0;
|
||||
const wchar_t* wend = 0;
|
||||
const wchar_t* wbegin;
|
||||
const wchar_t* wend;
|
||||
std::vector<wchar_t> buffer; // if needed
|
||||
if(begin == end)
|
||||
return std::string();
|
||||
if(validate_utf16(begin, end - begin)) {
|
||||
wbegin = reinterpret_cast<const wchar_t*>(begin);
|
||||
wend = reinterpret_cast<const wchar_t*>(end);
|
||||
@@ -328,7 +326,9 @@ namespace boost { namespace locale { namespace conv { namespace impl {
|
||||
throw conversion_error();
|
||||
} else {
|
||||
clean_invalid_utf16(begin, end - begin, buffer);
|
||||
if(!buffer.empty()) {
|
||||
if(buffer.empty())
|
||||
wbegin = wend = nullptr;
|
||||
else {
|
||||
wbegin = &buffer[0];
|
||||
wend = wbegin + buffer.size();
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ namespace boost { namespace locale {
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
BOOST_LOCALE_START_CONST_CONDITION
|
||||
if(sizeof(CharType) == 2 || (sizeof(CharType) == 1 && util::normalize_encoding(encoding) == "utf8")) {
|
||||
UText* ut = 0;
|
||||
UText* ut = nullptr;
|
||||
try {
|
||||
if(sizeof(CharType) == 1)
|
||||
ut = utext_openUTF8(0, reinterpret_cast<const char*>(begin), end - begin, &err);
|
||||
ut = utext_openUTF8(nullptr, reinterpret_cast<const char*>(begin), end - begin, &err);
|
||||
else // sizeof(CharType)==2
|
||||
ut = utext_openUChars(0, reinterpret_cast<const UChar*>(begin), end - begin, &err);
|
||||
ut = utext_openUChars(nullptr, reinterpret_cast<const UChar*>(begin), end - begin, &err);
|
||||
BOOST_LOCALE_END_CONST_CONDITION
|
||||
|
||||
check_and_throw_icu_error(err);
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
// No need to check err each time, this
|
||||
// is how ICU works.
|
||||
cvt_ = ucnv_open(encoding.c_str(), &err);
|
||||
ucnv_setFromUCallBack(cvt_, UCNV_FROM_U_CALLBACK_STOP, 0, 0, 0, &err);
|
||||
ucnv_setToUCallBack(cvt_, UCNV_TO_U_CALLBACK_STOP, 0, 0, 0, &err);
|
||||
ucnv_setFromUCallBack(cvt_, UCNV_FROM_U_CALLBACK_STOP, nullptr, nullptr, nullptr, &err);
|
||||
ucnv_setToUCallBack(cvt_, UCNV_TO_U_CALLBACK_STOP, nullptr, nullptr, nullptr, &err);
|
||||
|
||||
if(!cvt_ || U_FAILURE(err)) {
|
||||
if(cvt_)
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
case converter_base::normalization: normalize_string(str, flags); break;
|
||||
case converter_base::upper_case: str.toUpper(locale_); break;
|
||||
case converter_base::lower_case: str.toLower(locale_); break;
|
||||
case converter_base::title_case: str.toTitle(0, locale_); break;
|
||||
case converter_base::title_case: str.toTitle(nullptr, locale_); break;
|
||||
case converter_base::case_folding: str.foldCase(); break;
|
||||
}
|
||||
return cvt.std(str);
|
||||
@@ -84,7 +84,7 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
raii_casemap(const raii_casemap&) = delete;
|
||||
void operator=(const raii_casemap&) = delete;
|
||||
|
||||
raii_casemap(const std::string& locale_id) : map_(0)
|
||||
raii_casemap(const std::string& locale_id) : map_(nullptr)
|
||||
{
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
map_ = ucasemap_open(locale_id.c_str(), 0, &err);
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
int get_option(calendar_option_type opt) const override
|
||||
{
|
||||
switch(opt) {
|
||||
case is_gregorian: return icu_cast<const icu::GregorianCalendar>(calendar_.get()) != 0;
|
||||
case is_gregorian: return icu_cast<const icu::GregorianCalendar>(calendar_.get()) != nullptr;
|
||||
case is_dst: {
|
||||
guard l(lock_);
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
|
||||
@@ -372,7 +372,7 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
case strftime: {
|
||||
using namespace flags;
|
||||
std::unique_ptr<icu::DateFormat> new_df;
|
||||
icu::DateFormat* df = 0;
|
||||
icu::DateFormat* df = nullptr;
|
||||
// try to use cached first
|
||||
{
|
||||
icu::SimpleDateFormat* sdf = cache.date_formatter();
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
{
|
||||
if(d && readdir_r(d, &de, &read_result) == 0 && read_result != 0)
|
||||
return de.d_name;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -121,7 +121,7 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
if(!d.is_open())
|
||||
return std::string();
|
||||
|
||||
const char* name = 0;
|
||||
const char* name = nullptr;
|
||||
while((name = d.next()) != 0) {
|
||||
std::string file_name = name;
|
||||
if(file_name == "." || file_name == ".." || file_name == "posixrules" || file_name == "localtime") {
|
||||
|
||||
@@ -105,18 +105,18 @@ namespace boost { namespace locale { namespace impl_icu {
|
||||
|
||||
try {
|
||||
if(cvt_type == cpcvt_type::skip) {
|
||||
ucnv_setFromUCallBack(cvt_, UCNV_FROM_U_CALLBACK_SKIP, 0, 0, 0, &err);
|
||||
ucnv_setFromUCallBack(cvt_, UCNV_FROM_U_CALLBACK_SKIP, nullptr, nullptr, nullptr, &err);
|
||||
check_and_throw_icu_error(err);
|
||||
|
||||
err = U_ZERO_ERROR;
|
||||
ucnv_setToUCallBack(cvt_, UCNV_TO_U_CALLBACK_SKIP, 0, 0, 0, &err);
|
||||
ucnv_setToUCallBack(cvt_, UCNV_TO_U_CALLBACK_SKIP, nullptr, nullptr, nullptr, &err);
|
||||
check_and_throw_icu_error(err);
|
||||
} else {
|
||||
ucnv_setFromUCallBack(cvt_, UCNV_FROM_U_CALLBACK_STOP, 0, 0, 0, &err);
|
||||
ucnv_setFromUCallBack(cvt_, UCNV_FROM_U_CALLBACK_STOP, nullptr, nullptr, nullptr, &err);
|
||||
check_and_throw_icu_error(err);
|
||||
|
||||
err = U_ZERO_ERROR;
|
||||
ucnv_setToUCallBack(cvt_, UCNV_TO_U_CALLBACK_STOP, 0, 0, 0, &err);
|
||||
ucnv_setToUCallBack(cvt_, UCNV_TO_U_CALLBACK_STOP, nullptr, nullptr, nullptr, &err);
|
||||
check_and_throw_icu_error(err);
|
||||
}
|
||||
} catch(...) {
|
||||
|
||||
@@ -66,25 +66,19 @@ namespace boost { namespace locale { namespace impl_posix {
|
||||
if(real_id_.empty())
|
||||
real_id_ = util::get_system_locale();
|
||||
|
||||
locale_t tmp = newlocale(LC_ALL_MASK, real_id_.c_str(), 0);
|
||||
|
||||
if(!tmp) {
|
||||
tmp = newlocale(LC_ALL_MASK, "C", 0);
|
||||
}
|
||||
if(!tmp) {
|
||||
locale_t tmp = newlocale(LC_ALL_MASK, real_id_.c_str(), nullptr);
|
||||
if(!tmp)
|
||||
tmp = newlocale(LC_ALL_MASK, "C", nullptr);
|
||||
if(!tmp)
|
||||
throw std::runtime_error("newlocale failed");
|
||||
}
|
||||
|
||||
locale_t* tmp_p = 0;
|
||||
|
||||
locale_t* tmp_p;
|
||||
try {
|
||||
tmp_p = new locale_t();
|
||||
tmp_p = new locale_t(tmp);
|
||||
} catch(...) {
|
||||
freelocale(tmp);
|
||||
throw;
|
||||
}
|
||||
|
||||
*tmp_p = tmp;
|
||||
lc_ = std::shared_ptr<locale_t>(tmp_p, free_locale_by_ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,22 +12,22 @@
|
||||
|
||||
namespace boost { namespace locale {
|
||||
|
||||
ios_info::string_set::string_set() : type(0), size(0), ptr(0) {}
|
||||
ios_info::string_set::string_set() : type(nullptr), size(0), ptr(nullptr) {}
|
||||
ios_info::string_set::~string_set()
|
||||
{
|
||||
delete[] ptr;
|
||||
}
|
||||
ios_info::string_set::string_set(const string_set& other)
|
||||
{
|
||||
if(other.ptr != 0) {
|
||||
if(other.ptr != nullptr) {
|
||||
ptr = new char[other.size];
|
||||
size = other.size;
|
||||
type = other.type;
|
||||
memcpy(ptr, other.ptr, size);
|
||||
} else {
|
||||
ptr = 0;
|
||||
ptr = nullptr;
|
||||
size = 0;
|
||||
type = 0;
|
||||
type = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
struct message_key {
|
||||
typedef std::basic_string<CharType> string_type;
|
||||
|
||||
message_key(const string_type& c = string_type()) : c_context_(0), c_key_(0)
|
||||
message_key(const string_type& c = string_type()) : c_context_(nullptr), c_key_(nullptr)
|
||||
{
|
||||
const size_t pos = c.find(CharType(4));
|
||||
if(pos == string_type::npos) {
|
||||
@@ -297,7 +297,7 @@ namespace boost { namespace locale { namespace gnu_gettext {
|
||||
message_key(const CharType* c, const CharType* k) : c_key_(k)
|
||||
{
|
||||
static const CharType empty = 0;
|
||||
if(c != 0)
|
||||
if(c != nullptr)
|
||||
c_context_ = c;
|
||||
else
|
||||
c_context_ = ∅
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace boost { namespace locale { namespace util {
|
||||
{
|
||||
if(check_is_simple_encoding(encoding))
|
||||
return new simple_converter(encoding);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<base_converter> create_utf8_converter()
|
||||
|
||||
@@ -28,7 +28,7 @@ static bool get_user_default_locale_info(LCTYPE lcType, char (&buf)[N])
|
||||
namespace boost { namespace locale { namespace util {
|
||||
std::string get_system_locale(bool use_utf8_on_windows)
|
||||
{
|
||||
const char* lang = 0;
|
||||
const char* lang = nullptr;
|
||||
if(!lang || !*lang)
|
||||
lang = getenv("LC_ALL");
|
||||
if(!lang || !*lang)
|
||||
|
||||
@@ -22,15 +22,15 @@
|
||||
namespace boost { namespace locale { namespace util {
|
||||
namespace {
|
||||
|
||||
int is_leap(int year)
|
||||
bool is_leap(int year)
|
||||
{
|
||||
if(year % 400 == 0)
|
||||
return 1;
|
||||
return true;
|
||||
if(year % 100 == 0)
|
||||
return 0;
|
||||
return false;
|
||||
if(year % 4 == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int days_in_month(int year, int month)
|
||||
@@ -127,7 +127,7 @@ namespace boost { namespace locale { namespace util {
|
||||
gregorian_calendar(const std::string& terr)
|
||||
{
|
||||
first_day_of_week_ = first_day_of_week(terr.c_str());
|
||||
time_ = std::time(0);
|
||||
time_ = std::time(nullptr);
|
||||
is_local_ = true;
|
||||
tzoff_ = 0;
|
||||
from_time(time_);
|
||||
@@ -217,8 +217,8 @@ namespace boost { namespace locale { namespace util {
|
||||
point = internal_timegm(&val);
|
||||
#ifdef BOOST_WINDOWS
|
||||
// Windows uses TLS, thread safe
|
||||
std::tm* revert_point = 0;
|
||||
if(point < 0 || (revert_point = gmtime(&point)) == 0)
|
||||
std::tm* revert_point = nullptr;
|
||||
if(point < 0 || (revert_point = gmtime(&point)) == nullptr)
|
||||
throw date_time_error("boost::locale::gregorian_calendar time is out of range");
|
||||
val = *revert_point;
|
||||
#else
|
||||
@@ -663,7 +663,7 @@ namespace boost { namespace locale { namespace util {
|
||||
void from_time(std::time_t point)
|
||||
{
|
||||
std::time_t real_point = point + tzoff_;
|
||||
std::tm* t = 0;
|
||||
std::tm* t;
|
||||
#ifdef BOOST_WINDOWS
|
||||
// Windows uses TLS, thread safe
|
||||
t = is_local_ ? localtime(&real_point) : gmtime(&real_point);
|
||||
|
||||
@@ -27,11 +27,10 @@ namespace boost { namespace locale { namespace util {
|
||||
return 0;
|
||||
int gmtoff = 0;
|
||||
const char* begin = ltz.c_str() + 3;
|
||||
char* end = 0;
|
||||
char* end = const_cast<char*>(begin);
|
||||
int hours = strtol(begin, &end, 10);
|
||||
if(end != begin) {
|
||||
if(end != begin)
|
||||
gmtoff += hours * 3600;
|
||||
}
|
||||
if(*end == ':') {
|
||||
begin = end + 1;
|
||||
int minutes = strtol(begin, &end, 10);
|
||||
|
||||
@@ -12,8 +12,10 @@ project : requirements
|
||||
<library>/boost/locale//boost_locale
|
||||
<warnings>extra
|
||||
<toolset>msvc:<warnings-as-errors>on
|
||||
<toolset>gcc:<cxxflags>-Wzero-as-null-pointer-constant
|
||||
[ predef-check "BOOST_COMP_GNUC >= 8.0.0" : : <cxxflags>-Wsuggest-override ]
|
||||
[ predef-check "BOOST_COMP_GNUC >= 8.0.0" and "BOOST_COMP_GNUC < 12" : : <warnings-as-errors>on ]
|
||||
<toolset>clang:<cxxflags>-Wzero-as-null-pointer-constant
|
||||
<toolset>clang-5:<warnings-as-errors>on
|
||||
[ predef-check "BOOST_COMP_CLANG >= 9" and "BOOST_COMP_CLANG < 14" : : <warnings-as-errors>on ]
|
||||
<include>.
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
#endif
|
||||
|
||||
#ifndef LC_ALL_MASK
|
||||
using locale_t = int;
|
||||
using locale_t = void*;
|
||||
locale_t newlocale(int, const char*, locale_t)
|
||||
{
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
void freelocale(locale_t) {}
|
||||
# define LC_ALL_MASK 0xFFFFFFFF
|
||||
@@ -25,7 +25,7 @@ void freelocale(locale_t) {}
|
||||
|
||||
class locale_holder {
|
||||
locale_t l_;
|
||||
void reset(const locale_t l = 0)
|
||||
void reset(const locale_t l = nullptr)
|
||||
{
|
||||
if(l_)
|
||||
freelocale(l_);
|
||||
@@ -33,7 +33,7 @@ class locale_holder {
|
||||
}
|
||||
|
||||
public:
|
||||
explicit locale_holder(locale_t l = 0) : l_(l) {}
|
||||
explicit locale_holder(locale_t l = nullptr) : l_(l) {}
|
||||
~locale_holder() { reset(); }
|
||||
locale_holder(const locale_holder&) = delete;
|
||||
locale_holder& operator=(const locale_holder&) = delete;
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
inline bool has_posix_locale(const std::string& name)
|
||||
{
|
||||
locale_holder l(newlocale(LC_ALL_MASK, name.c_str(), 0));
|
||||
locale_holder l(newlocale(LC_ALL_MASK, name.c_str(), nullptr));
|
||||
return !!l;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ inline bool test_std_supports_SJIS_codecvt(const std::string& locale_name)
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string get_std_name(const std::string& name, std::string* real_name = 0)
|
||||
std::string get_std_name(const std::string& name, std::string* real_name = nullptr)
|
||||
{
|
||||
if(has_std_locale(name.c_str())) {
|
||||
if(real_name)
|
||||
|
||||
@@ -138,7 +138,7 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
std::cout << "- Testing timezone and time " << std::endl;
|
||||
{
|
||||
setlocale(LC_ALL, "C");
|
||||
time_t now = time(0);
|
||||
time_t now = std::time(nullptr);
|
||||
char buf[1024];
|
||||
strftime(buf, sizeof(buf), "%%c=%c; %%Z=%Z; %%z=%z", localtime_wrap(&now));
|
||||
std::cout << " Local Time :" << buf << std::endl;
|
||||
|
||||
@@ -337,11 +337,11 @@ void test_boundaries(std::string* all, int* first, int* second, lb::boundary_typ
|
||||
{
|
||||
boost::locale::generator g;
|
||||
std::cout << " char UTF-8" << std::endl;
|
||||
run_word<char>(all, first, second, 0, 0, 0, g("he_IL.UTF-8"), t);
|
||||
run_word<char>(all, first, second, nullptr, nullptr, nullptr, g("he_IL.UTF-8"), t);
|
||||
std::cout << " char CP1255" << std::endl;
|
||||
run_word<char>(all, first, second, 0, 0, 0, g("he_IL.cp1255"), t);
|
||||
run_word<char>(all, first, second, nullptr, nullptr, nullptr, g("he_IL.cp1255"), t);
|
||||
std::cout << " wchar_t" << std::endl;
|
||||
run_word<wchar_t>(all, first, second, 0, 0, 0, g("he_IL.UTF-8"), t);
|
||||
run_word<wchar_t>(all, first, second, nullptr, nullptr, nullptr, g("he_IL.UTF-8"), t);
|
||||
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
|
||||
std::cout << " char16_t" << std::endl;
|
||||
run_word<char16_t>(all, first, second, 0, 0, 0, g("he_IL.UTF-8"), t);
|
||||
@@ -506,7 +506,7 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
std::cout << "Testing word boundary" << std::endl;
|
||||
word_boundary();
|
||||
std::cout << "Testing character boundary" << std::endl;
|
||||
test_boundaries(character, nones, 0, lb::character);
|
||||
test_boundaries(character, nones, nullptr, lb::character);
|
||||
std::cout << "Testing sentence boundary" << std::endl;
|
||||
test_boundaries(sentence1, sentence1a, sentence1b, lb::sentence);
|
||||
std::cout << "Testing line boundary" << std::endl;
|
||||
|
||||
@@ -31,9 +31,9 @@ bool test_from(boost::locale::util::base_converter& cvt, unsigned codepoint, con
|
||||
char buf[32] = {0};
|
||||
unsigned res = cvt.from_unicode(codepoint, buf, buf + sizeof(buf));
|
||||
if(res == boost::locale::util::base_converter::illegal) {
|
||||
return str == 0;
|
||||
return str == nullptr;
|
||||
} else {
|
||||
return str != 0 && strlen(str) == res && memcmp(str, buf, res) == 0;
|
||||
return str != nullptr && strlen(str) == res && memcmp(str, buf, res) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void test_shiftjis(std::unique_ptr<boost::locale::util::base_converter>& cvt)
|
||||
TEST_INC(0x30d2, 1); // Full width katakana Hi ヒ
|
||||
TEST_INC(0x3072, 1); // Full width hiragana Hi ひ
|
||||
|
||||
TEST_FROM(0, 0x5e9); // Hebrew ש not in ShiftJIS
|
||||
TEST_FROM(nullptr, 0x5e9); // Hebrew ש not in ShiftJIS
|
||||
}
|
||||
|
||||
void test_main(int /*argc*/, char** /*argv*/)
|
||||
@@ -201,15 +201,15 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
std::cout << "-- Test no surrogate " << std::endl;
|
||||
|
||||
TEST_FROM(0, 0xD800);
|
||||
TEST_FROM(0, 0xDBFF);
|
||||
TEST_FROM(0, 0xDC00);
|
||||
TEST_FROM(0, 0xDFFF);
|
||||
TEST_FROM(nullptr, 0xD800);
|
||||
TEST_FROM(nullptr, 0xDBFF);
|
||||
TEST_FROM(nullptr, 0xDC00);
|
||||
TEST_FROM(nullptr, 0xDFFF);
|
||||
|
||||
std::cout << "-- Test invalid " << std::endl;
|
||||
|
||||
TEST_FROM(0, 0x110000);
|
||||
TEST_FROM(0, 0x1FFFFF);
|
||||
TEST_FROM(nullptr, 0x110000);
|
||||
TEST_FROM(nullptr, 0x1FFFFF);
|
||||
|
||||
std::cout << "Test windows-1255" << std::endl;
|
||||
|
||||
@@ -236,8 +236,8 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
TEST_FROM("\xc4", 0x5b4);
|
||||
TEST_FROM("\xfe", 0x200f);
|
||||
|
||||
TEST_FROM(0, 0xe4);
|
||||
TEST_FROM(0, 0xd0);
|
||||
TEST_FROM(nullptr, 0xe4);
|
||||
TEST_FROM(nullptr, 0xd0);
|
||||
|
||||
#ifdef BOOST_LOCALE_WITH_ICU
|
||||
std::cout << "Testing Shift-JIS using ICU/uconv" << std::endl;
|
||||
|
||||
@@ -481,7 +481,7 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
// Default constructed time_point
|
||||
{
|
||||
const time_t current_time = std::time(0);
|
||||
const time_t current_time = std::time(nullptr);
|
||||
date_time time_point_default;
|
||||
// Defaults to current time, i.e. different than a date in 1970
|
||||
date_time time_point_1970 = year(1970) + february() + day(5);
|
||||
|
||||
@@ -440,7 +440,7 @@ void test_manip(std::string e_charset = "UTF-8")
|
||||
}
|
||||
|
||||
{
|
||||
const time_t now = time(0);
|
||||
const time_t now = time(nullptr);
|
||||
boost::locale::time_zone::global("GMT+4:00");
|
||||
const time_t local_now = now + 3600 * 4;
|
||||
char time_str[256];
|
||||
@@ -646,7 +646,7 @@ void test_format_class(std::string charset = "UTF-8")
|
||||
// formatted time
|
||||
{
|
||||
boost::locale::time_zone::global("GMT+4:00");
|
||||
time_t now = time(0);
|
||||
const time_t now = time(nullptr);
|
||||
char local_time_str[256], local_time_str_gmt2[256];
|
||||
time_t local_now = now + 3600 * 4;
|
||||
strftime(local_time_str, sizeof(local_time_str), "'%H:%M:%S'", gmtime_wrap(&local_now));
|
||||
|
||||
@@ -22,7 +22,7 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
std::cout << "ICU is not build... Skipping\n";
|
||||
return;
|
||||
#endif
|
||||
time_t now = time(0);
|
||||
const time_t now = std::time(nullptr);
|
||||
boost::locale::generator gen;
|
||||
std::locale::global(gen("en_US.UTF-8"));
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ void test_char()
|
||||
std::cout << "- " << name << " is not supported, skipping" << std::endl;
|
||||
else {
|
||||
std::cout << "Testing " << name << std::endl;
|
||||
locale_holder cl(newlocale(LC_ALL_MASK, name.c_str(), 0));
|
||||
locale_holder cl(newlocale(LC_ALL_MASK, name.c_str(), nullptr));
|
||||
TEST(cl);
|
||||
#ifndef BOOST_LOCALE_NO_POSIX_BACKEND
|
||||
if(towupper_l(L'i', cl) == 0x130)
|
||||
|
||||
@@ -150,7 +150,7 @@ void test_main(int /*argc*/, char** /*argv*/)
|
||||
std::cout << locale_name << " not supported" << std::endl;
|
||||
} else {
|
||||
std::locale generated_locale = gen(locale_name);
|
||||
locale_holder real_locale(newlocale(LC_ALL_MASK, locale_name.c_str(), 0));
|
||||
locale_holder real_locale(newlocale(LC_ALL_MASK, locale_name.c_str(), nullptr));
|
||||
TEST_REQUIRE(real_locale);
|
||||
|
||||
std::cout << "UTF-8" << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user