OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // limitations under the License. | 4 // limitations under the License. |
5 | 5 |
6 #include "src/i18n.h" | 6 #include "src/i18n.h" |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/api.h" | 10 #include "src/api.h" |
11 #include "src/factory.h" | 11 #include "src/factory.h" |
12 #include "src/isolate.h" | 12 #include "src/isolate.h" |
13 #include "src/objects-inl.h" | 13 #include "src/objects-inl.h" |
14 #include "src/string-case.h" | 14 #include "src/string-case.h" |
15 #include "unicode/brkiter.h" | 15 #include "unicode/brkiter.h" |
16 #include "unicode/bytestream.h" | |
17 #include "unicode/calendar.h" | 16 #include "unicode/calendar.h" |
18 #include "unicode/coll.h" | 17 #include "unicode/coll.h" |
19 #include "unicode/curramt.h" | 18 #include "unicode/curramt.h" |
20 #include "unicode/dcfmtsym.h" | 19 #include "unicode/dcfmtsym.h" |
21 #include "unicode/decimfmt.h" | 20 #include "unicode/decimfmt.h" |
22 #include "unicode/dtfmtsym.h" | 21 #include "unicode/dtfmtsym.h" |
23 #include "unicode/dtptngen.h" | 22 #include "unicode/dtptngen.h" |
24 #include "unicode/gregocal.h" | 23 #include "unicode/gregocal.h" |
25 #include "unicode/locid.h" | 24 #include "unicode/locid.h" |
26 #include "unicode/numfmt.h" | 25 #include "unicode/numfmt.h" |
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 } | 1205 } |
1207 | 1206 |
1208 return LocaleConvertCase(s, isolate, true, ""); | 1207 return LocaleConvertCase(s, isolate, true, ""); |
1209 } | 1208 } |
1210 | 1209 |
1211 MUST_USE_RESULT Object* ConvertCase(Handle<String> s, bool is_upper, | 1210 MUST_USE_RESULT Object* ConvertCase(Handle<String> s, bool is_upper, |
1212 Isolate* isolate) { | 1211 Isolate* isolate) { |
1213 return is_upper ? ConvertToUpper(s, isolate) : ConvertToLower(s, isolate); | 1212 return is_upper ? ConvertToUpper(s, isolate) : ConvertToLower(s, isolate); |
1214 } | 1213 } |
1215 | 1214 |
1216 ICUTimezoneCache::ICUTimezoneCache() : timezone_(nullptr) { Clear(); } | |
1217 | |
1218 ICUTimezoneCache::~ICUTimezoneCache() { Clear(); } | |
1219 | |
1220 const char* ICUTimezoneCache::LocalTimezone(double time_ms) { | |
1221 bool is_dst = DaylightSavingsOffset(time_ms) != 0; | |
1222 char* name = is_dst ? dst_timezone_name_ : timezone_name_; | |
1223 if (name[0] == '\0') { | |
1224 icu::UnicodeString result; | |
1225 GetTimeZone()->getDisplayName(is_dst, icu::TimeZone::LONG, result); | |
1226 result += '\0'; | |
1227 | |
1228 icu::CheckedArrayByteSink byte_sink(name, kMaxTimezoneChars); | |
1229 result.toUTF8(byte_sink); | |
1230 CHECK(!byte_sink.Overflowed()); | |
1231 } | |
1232 return const_cast<const char*>(name); | |
1233 } | |
1234 | |
1235 icu::TimeZone* ICUTimezoneCache::GetTimeZone() { | |
1236 if (timezone_ == nullptr) { | |
1237 timezone_ = icu::TimeZone::createDefault(); | |
1238 } | |
1239 return timezone_; | |
1240 } | |
1241 | |
1242 bool ICUTimezoneCache::GetOffsets(double time_ms, int32_t* raw_offset, | |
1243 int32_t* dst_offset) { | |
1244 UErrorCode status = U_ZERO_ERROR; | |
1245 GetTimeZone()->getOffset(time_ms, false, *raw_offset, *dst_offset, status); | |
1246 return U_SUCCESS(status); | |
1247 } | |
1248 | |
1249 double ICUTimezoneCache::DaylightSavingsOffset(double time_ms) { | |
1250 int32_t raw_offset, dst_offset; | |
1251 if (!GetOffsets(time_ms, &raw_offset, &dst_offset)) return 0; | |
1252 return dst_offset; | |
1253 } | |
1254 | |
1255 double ICUTimezoneCache::LocalTimeOffset() { | |
1256 int32_t raw_offset, dst_offset; | |
1257 if (!GetOffsets(icu::Calendar::getNow(), &raw_offset, &dst_offset)) return 0; | |
1258 return raw_offset; | |
1259 } | |
1260 | |
1261 void ICUTimezoneCache::Clear() { | |
1262 delete timezone_; | |
1263 timezone_ = nullptr; | |
1264 timezone_name_[0] = '\0'; | |
1265 dst_timezone_name_[0] = '\0'; | |
1266 } | |
1267 | |
1268 } // namespace internal | 1215 } // namespace internal |
1269 } // namespace v8 | 1216 } // namespace v8 |
OLD | NEW |