|
57 | 57 | #endif // __has_include |
58 | 58 | #endif // _WIN32 |
59 | 59 |
|
| 60 | +#include <array> |
| 61 | +#include <cstdint> |
60 | 62 | #include <cstdlib> |
61 | 63 | #include <cstring> |
62 | 64 | #include <string> |
@@ -121,25 +123,25 @@ std::string win32_local_time_zone() { |
121 | 123 | return ""; |
122 | 124 | } |
123 | 125 |
|
124 | | - UChar buffer[128]; |
| 126 | + std::array<UChar, 128> buffer; |
125 | 127 | UErrorCode status = U_ZERO_ERROR; |
126 | 128 | const auto num_chars_in_buffer = ucal_getTimeZoneIDForWindowsIDFunc( |
127 | | - reinterpret_cast<const UChar*>(info.TimeZoneKeyName), -1, nullptr, buffer, |
128 | | - ARRAYSIZE(buffer), &status); |
| 129 | + reinterpret_cast<const UChar*>(info.TimeZoneKeyName), -1, nullptr, |
| 130 | + buffer.data(), static_cast<int32_t>(buffer.size()), &status); |
129 | 131 | if (status != U_ZERO_ERROR || num_chars_in_buffer <= 0 || |
130 | | - num_chars_in_buffer > ARRAYSIZE(buffer)) { |
| 132 | + num_chars_in_buffer > static_cast<int32_t>(buffer.size())) { |
131 | 133 | return ""; |
132 | 134 | } |
133 | 135 |
|
134 | 136 | const int num_bytes_in_utf8 = ::WideCharToMultiByte( |
135 | | - CP_UTF8, 0, reinterpret_cast<const wchar_t*>(buffer), |
| 137 | + CP_UTF8, 0, reinterpret_cast<const wchar_t*>(buffer.data()), |
136 | 138 | static_cast<int>(num_chars_in_buffer), nullptr, 0, nullptr, nullptr); |
137 | 139 | std::string local_time_str; |
138 | 140 | local_time_str.resize(static_cast<size_t>(num_bytes_in_utf8)); |
139 | | - ::WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<const wchar_t*>(buffer), |
140 | | - static_cast<int>(num_chars_in_buffer), |
141 | | - &local_time_str[0], num_bytes_in_utf8, nullptr, |
142 | | - nullptr); |
| 141 | + ::WideCharToMultiByte( |
| 142 | + CP_UTF8, 0, reinterpret_cast<const wchar_t*>(buffer.data()), |
| 143 | + static_cast<int>(num_chars_in_buffer), &local_time_str[0], |
| 144 | + num_bytes_in_utf8, nullptr, nullptr); |
143 | 145 | return local_time_str; |
144 | 146 | } |
145 | 147 | #endif // USE_WIN32_LOCAL_TIME_ZONE |
|
0 commit comments