v8-icu68.patch 7.0 KB

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