1 From b0a7f5691113534c2cf771f2dd3cece5e93bc7d4 Mon Sep 17 00:00:00 2001
2 From: Frank Tang <ftang@chromium.org>
3 Date: Tue, 03 Nov 2020 23:20:37 -0800
4 Subject: [PATCH] Update to ICU68-1
5
6 ICU68-1 change the output skeleton format. So we need to change
7 resolvedOptions code for 68 migration.
8
9 Chromium roll
10 https://chromium-review.googlesource.com/c/chromium/src/+/2474093
11
12 Bug: v8:10945
13 Change-Id: I3b2c7fbe8abb22df8fa51287c498ca3245b8c55b
14 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2477431
15 Commit-Queue: Frank Tang <ftang@chromium.org>
16 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
17 Reviewed-by: Shu-yu Guo <syg@chromium.org>
18 Cr-Commit-Position: refs/heads/master@{#70972}
19
20 (ported to work with <ICU-68.1 and rebased chromium)
21 ---
22
23 diff --git a/src/3rdparty/chromium/v8/src/objects/js-number-format.cc b/src/3rdparty/chromium/v8/src/objects/js-number-format.cc
24 index 45b0eab..d18b133 100644
25 --- a/src/3rdparty/chromium/v8/src/objects/js-number-format.cc
26 +++ b/src/3rdparty/chromium/v8/src/objects/js-number-format.cc
27 @@ -389,17 +389,20 @@ Handle<String> CurrencySignString(Isolate* isolate,
28 Handle<String> UnitDisplayString(Isolate* isolate,
29 const icu::UnicodeString& skeleton) {
30 // Ex: skeleton as
31 - // "measure-unit/length-meter .### rounding-mode-half-up unit-width-full-name"
32 + // <ICU-68.1: "measure-unit/length-meter .### rounding-mode-half-up unit-width-full-name".
33 + // >=ICU-68.1: "unit/length-meter .### rounding-mode-half-up unit-width-full-name"
34 if (skeleton.indexOf("unit-width-full-name") >= 0) {
35 return ReadOnlyRoots(isolate).long_string_handle();
36 }
37 // Ex: skeleton as
38 - // "measure-unit/length-meter .### rounding-mode-half-up unit-width-narrow".
39 + // <ICU-68.1: "measure-unit/length-meter .### rounding-mode-half-up unit-width-narrow".
40 + // >=ICU-68.1: "unit/length-meter .### rounding-mode-half-up unit-width-narrow".
41 if (skeleton.indexOf("unit-width-narrow") >= 0) {
42 return ReadOnlyRoots(isolate).narrow_string_handle();
43 }
44 // Ex: skeleton as
45 - // "measure-unit/length-foot .### rounding-mode-half-up"
46 + // <ICU-68.1: "measure-unit/length-foot .### rounding-mode-half-up"
47 + // >=ICU-68.1: "unit/length-foot .### rounding-mode-half-up"
48 return ReadOnlyRoots(isolate).short_string_handle();
49 }
50
51 @@ -422,7 +425,8 @@ Notation NotationFromSkeleton(const icu::UnicodeString& skeleton) {
52 return Notation::COMPACT;
53 }
54 // Ex: skeleton as
55 - // "measure-unit/length-foot .### rounding-mode-half-up"
56 + // <ICU-68.1: "measure-unit/length-foot .### rounding-mode-half-up"
57 + // >=ICU-68.1: "unit/length-foot .### rounding-mode-half-up"
58 return Notation::STANDARD;
59 }
60
61 @@ -562,14 +566,23 @@ namespace {
62
63 // Ex: percent .### rounding-mode-half-up
64 // Special case for "percent"
65 -// Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .###
66 -// rounding-mode-half-up" should return "kilometer-per-unit".
67 -// Ex: "measure-unit/duration-year .### rounding-mode-half-up" should return
68 -// "year".
69 +// <ICU-68.1:
70 +// Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .###
71 +// rounding-mode-half-up" should return "kilometer-per-unit".
72 +// Ex: "measure-unit/duration-year .### rounding-mode-half-up" should return
73 +// >=ICU-68.1:
74 +// Ex: "unit/milliliter-per-acre .### rounding-mode-half-up"
75 +// should return "milliliter-per-acre".
76 +// Ex: "unit/year .### rounding-mode-half-up" should return
77 +// "year".
78 std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
79 std::string str;
80 str = skeleton.toUTF8String<std::string>(str);
81 +#if U_ICU_VERSION_MAJOR_NUM < 68
82 std::string search("measure-unit/");
83 +#else
84 + std::string search("unit/");
85 +#endif
86 size_t begin = str.find(search);
87 if (begin == str.npos) {
88 // Special case for "percent".
89 @@ -578,20 +591,41 @@ std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
90 }
91 return "";
92 }
93 +#if U_ICU_VERSION_MAJOR_NUM < 68
94 // Skip the type (ex: "length").
95 // "measure-unit/length-kilometer per-measure-unit/duration-hour"
96 // b
97 begin = str.find("-", begin + search.size());
98 +#else
99 + // Ex:
100 + // "unit/acre .### rounding-mode-half-up"
101 + // b
102 + // Ex:
103 + // "unit/milliliter-per-acre .### rounding-mode-half-up"
104 + // b
105 + begin += search.size();
106 +#endif
107 if (begin == str.npos) {
108 return "";
109 }
110 +#if U_ICU_VERSION_MAJOR_NUM < 68
111 begin++; // Skip the '-'.
112 +#endif
113 // Find the end of the subtype.
114 size_t end = str.find(" ", begin);
115 - // "measure-unit/length-kilometer per-measure-unit/duration-hour"
116 - // b e
117 + // <ICU-68.1:
118 + // "measure-unit/length-kilometer per-measure-unit/duration-hour"
119 + // b e
120 + // >=ICU-68.1:
121 + // Ex:
122 + // "unit/acre .### rounding-mode-half-up"
123 + // b e
124 + // Ex:
125 + // "unit/milliliter-per-acre .### rounding-mode-half-up"
126 + // b e
127 if (end == str.npos) {
128 end = str.size();
129 +#if U_ICU_VERSION_MAJOR_NUM < 68
130 return str.substr(begin, end - begin);
131 }
132 // "measure-unit/length-kilometer per-measure-unit/duration-hour"
133 @@ -625,17 +659,36 @@ std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
134 // "measure-unit/length-kilometer per-measure-unit/duration-hour"
135 // [result ] b e
136 return result + "-per-" + str.substr(begin, end - begin);
137 +#else
138 + }
139 + return str.substr(begin, end - begin);
140 +#endif
141 }
142
143 Style StyleFromSkeleton(const icu::UnicodeString& skeleton) {
144 if (skeleton.indexOf("currency/") >= 0) {
145 return Style::CURRENCY;
146 }
147 +#if U_ICU_VERSION_MAJOR_NUM < 68
148 if (skeleton.indexOf("measure-unit/") >= 0) {
149 if (skeleton.indexOf("scale/100") >= 0 &&
150 skeleton.indexOf("measure-unit/concentr-percent") >= 0) {
151 +#else
152 + if (skeleton.indexOf("percent") >= 0) {
153 + // percent precision-integer rounding-mode-half-up scale/100
154 + if (skeleton.indexOf("scale/100") >= 0) {
155 +#endif
156 return Style::PERCENT;
157 +#if U_ICU_VERSION_MAJOR_NUM >= 68
158 + } else {
159 + return Style::UNIT;
160 +#endif
161 }
162 +#if U_ICU_VERSION_MAJOR_NUM >= 68
163 + }
164 + // Before ICU68: "measure-unit/", since ICU68 "unit/"
165 + if (skeleton.indexOf("unit/") >= 0) {
166 +#endif
167 return Style::UNIT;
168 }
169 return Style::DECIMAL;
170 diff --git a/src/3rdparty/chromium/v8/src/objects/js-relative-time-format.cc b/src/3rdparty/chromium/v8/src/objects/js-relative-time-format.cc
171 index 267343aaae..64d56a1c12 100644
172 --- a/src/3rdparty/chromium/v8/src/objects/js-relative-time-format.cc
173 +++ b/src/3rdparty/chromium/v8/src/objects/js-relative-time-format.cc
174 @@ -195,9 +195,18 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
175 }
176 }
177
178 +#if U_ICU_VERSION_MAJOR_NUM < 68
179 icu::DecimalFormat* decimal_format =
180 static_cast<icu::DecimalFormat*>(number_format);
181 decimal_format->setMinimumGroupingDigits(-2);
182 +#else
183 + if (number_format->getDynamicClassID() ==
184 + icu::DecimalFormat::getStaticClassID()) {
185 + icu::DecimalFormat* decimal_format =
186 + static_cast<icu::DecimalFormat*>(number_format);
187 + decimal_format->setMinimumGroupingDigits(-2);
188 + }
189 +#endif
190
191 // Change UDISPCTX_CAPITALIZATION_NONE to other values if
192 // ECMA402 later include option to change capitalization.
|