Lines 389-405
Handle<String> CurrencySignString(Isolate* isolate,
Link Here
|
389 |
Handle<String> UnitDisplayString(Isolate* isolate, |
389 |
Handle<String> UnitDisplayString(Isolate* isolate, |
390 |
const icu::UnicodeString& skeleton) { |
390 |
const icu::UnicodeString& skeleton) { |
391 |
// Ex: skeleton as |
391 |
// Ex: skeleton as |
392 |
// "measure-unit/length-meter .### rounding-mode-half-up unit-width-full-name" |
392 |
// <ICU-68.1: "measure-unit/length-meter .### rounding-mode-half-up unit-width-full-name". |
|
|
393 |
// >=ICU-68.1: "unit/length-meter .### rounding-mode-half-up unit-width-full-name" |
393 |
if (skeleton.indexOf("unit-width-full-name") >= 0) { |
394 |
if (skeleton.indexOf("unit-width-full-name") >= 0) { |
394 |
return ReadOnlyRoots(isolate).long_string_handle(); |
395 |
return ReadOnlyRoots(isolate).long_string_handle(); |
395 |
} |
396 |
} |
396 |
// Ex: skeleton as |
397 |
// Ex: skeleton as |
397 |
// "measure-unit/length-meter .### rounding-mode-half-up unit-width-narrow". |
398 |
// <ICU-68.1: "measure-unit/length-meter .### rounding-mode-half-up unit-width-narrow". |
|
|
399 |
// >=ICU-68.1: "unit/length-meter .### rounding-mode-half-up unit-width-narrow". |
398 |
if (skeleton.indexOf("unit-width-narrow") >= 0) { |
400 |
if (skeleton.indexOf("unit-width-narrow") >= 0) { |
399 |
return ReadOnlyRoots(isolate).narrow_string_handle(); |
401 |
return ReadOnlyRoots(isolate).narrow_string_handle(); |
400 |
} |
402 |
} |
401 |
// Ex: skeleton as |
403 |
// Ex: skeleton as |
402 |
// "measure-unit/length-foot .### rounding-mode-half-up" |
404 |
// <ICU-68.1: "measure-unit/length-foot .### rounding-mode-half-up" |
|
|
405 |
// >=ICU-68.1: "unit/length-foot .### rounding-mode-half-up" |
403 |
return ReadOnlyRoots(isolate).short_string_handle(); |
406 |
return ReadOnlyRoots(isolate).short_string_handle(); |
404 |
} |
407 |
} |
405 |
|
408 |
|
Lines 422-428
Notation NotationFromSkeleton(const icu::UnicodeString& skeleton) {
Link Here
|
422 |
return Notation::COMPACT; |
425 |
return Notation::COMPACT; |
423 |
} |
426 |
} |
424 |
// Ex: skeleton as |
427 |
// Ex: skeleton as |
425 |
// "measure-unit/length-foot .### rounding-mode-half-up" |
428 |
// <ICU-68.1: "measure-unit/length-foot .### rounding-mode-half-up" |
|
|
429 |
// >=ICU-68.1: "unit/length-foot .### rounding-mode-half-up" |
426 |
return Notation::STANDARD; |
430 |
return Notation::STANDARD; |
427 |
} |
431 |
} |
428 |
|
432 |
|
Lines 562-575
namespace {
Link Here
|
562 |
|
566 |
|
563 |
// Ex: percent .### rounding-mode-half-up |
567 |
// Ex: percent .### rounding-mode-half-up |
564 |
// Special case for "percent" |
568 |
// Special case for "percent" |
565 |
// Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .### |
569 |
// <ICU-68.1: |
566 |
// rounding-mode-half-up" should return "kilometer-per-unit". |
570 |
// Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .### |
567 |
// Ex: "measure-unit/duration-year .### rounding-mode-half-up" should return |
571 |
// rounding-mode-half-up" should return "kilometer-per-unit". |
568 |
// "year". |
572 |
// Ex: "measure-unit/duration-year .### rounding-mode-half-up" should return |
|
|
573 |
// >=ICU-68.1: |
574 |
// Ex: "unit/milliliter-per-acre .### rounding-mode-half-up" |
575 |
// should return "milliliter-per-acre". |
576 |
// Ex: "unit/year .### rounding-mode-half-up" should return |
577 |
// "year". |
569 |
std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) { |
578 |
std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) { |
570 |
std::string str; |
579 |
std::string str; |
571 |
str = skeleton.toUTF8String<std::string>(str); |
580 |
str = skeleton.toUTF8String<std::string>(str); |
|
|
581 |
#if U_ICU_VERSION_MAJOR_NUM < 68 |
572 |
std::string search("measure-unit/"); |
582 |
std::string search("measure-unit/"); |
|
|
583 |
#else |
584 |
std::string search("unit/"); |
585 |
#endif |
573 |
size_t begin = str.find(search); |
586 |
size_t begin = str.find(search); |
574 |
if (begin == str.npos) { |
587 |
if (begin == str.npos) { |
575 |
// Special case for "percent". |
588 |
// Special case for "percent". |
Lines 578-597
std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
Link Here
|
578 |
} |
591 |
} |
579 |
return ""; |
592 |
return ""; |
580 |
} |
593 |
} |
|
|
594 |
#if U_ICU_VERSION_MAJOR_NUM < 68 |
581 |
// Skip the type (ex: "length"). |
595 |
// Skip the type (ex: "length"). |
582 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
596 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
583 |
// b |
597 |
// b |
584 |
begin = str.find("-", begin + search.size()); |
598 |
begin = str.find("-", begin + search.size()); |
|
|
599 |
#else |
600 |
// Ex: |
601 |
// "unit/acre .### rounding-mode-half-up" |
602 |
// b |
603 |
// Ex: |
604 |
// "unit/milliliter-per-acre .### rounding-mode-half-up" |
605 |
// b |
606 |
begin += search.size(); |
607 |
#endif |
585 |
if (begin == str.npos) { |
608 |
if (begin == str.npos) { |
586 |
return ""; |
609 |
return ""; |
587 |
} |
610 |
} |
|
|
611 |
#if U_ICU_VERSION_MAJOR_NUM < 68 |
588 |
begin++; // Skip the '-'. |
612 |
begin++; // Skip the '-'. |
|
|
613 |
#endif |
589 |
// Find the end of the subtype. |
614 |
// Find the end of the subtype. |
590 |
size_t end = str.find(" ", begin); |
615 |
size_t end = str.find(" ", begin); |
591 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
616 |
// <ICU-68.1: |
592 |
// b e |
617 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
|
|
618 |
// b e |
619 |
// >=ICU-68.1: |
620 |
// Ex: |
621 |
// "unit/acre .### rounding-mode-half-up" |
622 |
// b e |
623 |
// Ex: |
624 |
// "unit/milliliter-per-acre .### rounding-mode-half-up" |
625 |
// b e |
593 |
if (end == str.npos) { |
626 |
if (end == str.npos) { |
594 |
end = str.size(); |
627 |
end = str.size(); |
|
|
628 |
#if U_ICU_VERSION_MAJOR_NUM < 68 |
595 |
return str.substr(begin, end - begin); |
629 |
return str.substr(begin, end - begin); |
596 |
} |
630 |
} |
597 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
631 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
Lines 625-641
std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
Link Here
|
625 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
659 |
// "measure-unit/length-kilometer per-measure-unit/duration-hour" |
626 |
// [result ] b e |
660 |
// [result ] b e |
627 |
return result + "-per-" + str.substr(begin, end - begin); |
661 |
return result + "-per-" + str.substr(begin, end - begin); |
|
|
662 |
#else |
663 |
} |
664 |
return str.substr(begin, end - begin); |
665 |
#endif |
628 |
} |
666 |
} |
629 |
|
667 |
|
630 |
Style StyleFromSkeleton(const icu::UnicodeString& skeleton) { |
668 |
Style StyleFromSkeleton(const icu::UnicodeString& skeleton) { |
631 |
if (skeleton.indexOf("currency/") >= 0) { |
669 |
if (skeleton.indexOf("currency/") >= 0) { |
632 |
return Style::CURRENCY; |
670 |
return Style::CURRENCY; |
633 |
} |
671 |
} |
|
|
672 |
#if U_ICU_VERSION_MAJOR_NUM < 68 |
634 |
if (skeleton.indexOf("measure-unit/") >= 0) { |
673 |
if (skeleton.indexOf("measure-unit/") >= 0) { |
635 |
if (skeleton.indexOf("scale/100") >= 0 && |
674 |
if (skeleton.indexOf("scale/100") >= 0 && |
636 |
skeleton.indexOf("measure-unit/concentr-percent") >= 0) { |
675 |
skeleton.indexOf("measure-unit/concentr-percent") >= 0) { |
|
|
676 |
#else |
677 |
if (skeleton.indexOf("percent") >= 0) { |
678 |
// percent precision-integer rounding-mode-half-up scale/100 |
679 |
if (skeleton.indexOf("scale/100") >= 0) { |
680 |
#endif |
637 |
return Style::PERCENT; |
681 |
return Style::PERCENT; |
|
|
682 |
#if U_ICU_VERSION_MAJOR_NUM >= 68 |
683 |
} else { |
684 |
return Style::UNIT; |
685 |
#endif |
638 |
} |
686 |
} |
|
|
687 |
#if U_ICU_VERSION_MAJOR_NUM >= 68 |
688 |
} |
689 |
// Before ICU68: "measure-unit/", since ICU68 "unit/" |
690 |
if (skeleton.indexOf("unit/") >= 0) { |
691 |
#endif |
639 |
return Style::UNIT; |
692 |
return Style::UNIT; |
640 |
} |
693 |
} |
641 |
return Style::DECIMAL; |
694 |
return Style::DECIMAL; |