@@ -389,17 +389,17 @@ Handle<String> CurrencySignString(Isolate* isolate,
389
389
Handle <String> UnitDisplayString (Isolate* isolate,
390
390
const icu::UnicodeString& skeleton) {
391
391
// Ex: skeleton as
392
- // "measure- unit/length-meter .### rounding-mode-half-up unit-width-full-name"
392
+ // "unit/length-meter .### rounding-mode-half-up unit-width-full-name"
393
393
if (skeleton.indexOf (" unit-width-full-name" ) >= 0 ) {
394
394
return ReadOnlyRoots (isolate).long_string_handle ();
395
395
}
396
396
// Ex: skeleton as
397
- // "measure- unit/length-meter .### rounding-mode-half-up unit-width-narrow".
397
+ // "unit/length-meter .### rounding-mode-half-up unit-width-narrow".
398
398
if (skeleton.indexOf (" unit-width-narrow" ) >= 0 ) {
399
399
return ReadOnlyRoots (isolate).narrow_string_handle ();
400
400
}
401
401
// Ex: skeleton as
402
- // "measure- unit/length-foot .### rounding-mode-half-up"
402
+ // "unit/length-foot .### rounding-mode-half-up"
403
403
return ReadOnlyRoots (isolate).short_string_handle ();
404
404
}
405
405
@@ -422,7 +422,7 @@ Notation NotationFromSkeleton(const icu::UnicodeString& skeleton) {
422
422
return Notation::COMPACT;
423
423
}
424
424
// Ex: skeleton as
425
- // "measure- unit/length-foot .### rounding-mode-half-up"
425
+ // "unit/length-foot .### rounding-mode-half-up"
426
426
return Notation::STANDARD;
427
427
}
428
428
@@ -562,14 +562,14 @@ namespace {
562
562
563
563
// Ex: percent .### rounding-mode-half-up
564
564
// Special case for "percent"
565
- // Ex: "measure- unit/length-kilometer per-measure-unit/duration-hour .###
566
- // rounding-mode-half-up" should return "kilometer -per-unit ".
567
- // Ex: "measure- unit/duration- year .### rounding-mode-half-up" should return
565
+ // Ex: "unit/milliliter- per-acre .### rounding-mode-half-up"
566
+ // should return "milliliter -per-acre ".
567
+ // Ex: "unit/year .### rounding-mode-half-up" should return
568
568
// "year".
569
569
std::string UnitFromSkeleton (const icu::UnicodeString& skeleton) {
570
570
std::string str;
571
571
str = skeleton.toUTF8String <std::string>(str);
572
- std::string search (" measure- unit/" );
572
+ std::string search (" unit/" );
573
573
size_t begin = str.find (search);
574
574
if (begin == str.npos ) {
575
575
// Special case for "percent".
@@ -578,64 +578,44 @@ std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
578
578
}
579
579
return " " ;
580
580
}
581
- // Skip the type (ex: "length").
582
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
583
- // b
584
- begin = str.find (" -" , begin + search.size ());
581
+ // Ex:
582
+ // "unit/acre .### rounding-mode-half-up"
583
+ // b
584
+ // Ex:
585
+ // "unit/milliliter-per-acre .### rounding-mode-half-up"
586
+ // b
587
+ begin += search.size ();
585
588
if (begin == str.npos ) {
586
589
return " " ;
587
590
}
588
- begin++; // Skip the '-'.
589
591
// Find the end of the subtype.
590
592
size_t end = str.find (" " , begin);
591
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
592
- // b e
593
+ // Ex:
594
+ // "unit/acre .### rounding-mode-half-up"
595
+ // b e
596
+ // Ex:
597
+ // "unit/milliliter-per-acre .### rounding-mode-half-up"
598
+ // b e
593
599
if (end == str.npos ) {
594
600
end = str.size ();
595
- return str.substr (begin, end - begin);
596
- }
597
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
598
- // b e
599
- // [result ]
600
- std::string result = str.substr (begin, end - begin);
601
- begin = end + 1 ;
602
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
603
- // [result ]eb
604
- std::string search_per (" per-measure-unit/" );
605
- begin = str.find (search_per, begin);
606
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
607
- // [result ]e b
608
- if (begin == str.npos ) {
609
- return result;
610
- }
611
- // Skip the type (ex: "duration").
612
- begin = str.find (" -" , begin + search_per.size ());
613
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
614
- // [result ]e b
615
- if (begin == str.npos ) {
616
- return result;
617
601
}
618
- begin++; // Skip the '-'.
619
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
620
- // [result ]e b
621
- end = str.find (" " , begin);
622
- if (end == str.npos ) {
623
- end = str.size ();
624
- }
625
- // "measure-unit/length-kilometer per-measure-unit/duration-hour"
626
- // [result ] b e
627
- return result + " -per-" + str.substr (begin, end - begin);
602
+ return str.substr (begin, end - begin);
628
603
}
629
604
630
605
Style StyleFromSkeleton (const icu::UnicodeString& skeleton) {
631
606
if (skeleton.indexOf (" currency/" ) >= 0 ) {
632
607
return Style ::CURRENCY;
633
608
}
634
- if (skeleton.indexOf (" measure-unit/ " ) >= 0 ) {
635
- if (skeleton. indexOf ( " scale/100 " ) >= 0 &&
636
- skeleton.indexOf (" measure-unit/concentr-percent " ) >= 0 ) {
609
+ if (skeleton.indexOf (" percent " ) >= 0 ) {
610
+ // percent precision-integer rounding-mode-half-up scale/100
611
+ if ( skeleton.indexOf (" scale/100 " ) >= 0 ) {
637
612
return Style ::PERCENT;
613
+ } else {
614
+ return Style ::UNIT;
638
615
}
616
+ }
617
+ // Before ICU68: "measure-unit/", since ICU68 "unit/"
618
+ if (skeleton.indexOf (" unit/" ) >= 0 ) {
639
619
return Style ::UNIT;
640
620
}
641
621
return Style ::DECIMAL;
0 commit comments