[haiku-commits] haiku: hrev51173 - src/kits/locale headers/os/locale

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 17 May 2017 19:53:54 +0200 (CEST)

hrev51173 adds 1 changeset to branch 'master'
old head: f286626cd0adf423bb215d525db5053d3c6a93ea
new head: f5c544b59a75f9d2912f158fad8a4cbc9ddc55da
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=f5c544b59a75+%5Ef286626cd0ad

----------------------------------------------------------------------------

f5c544b59a75: Fix style formatting issue in BTimeUnitFormat, update 
BDurationFormat accordingly.
  
  * Issue: BTimeUnitFormat doesn't incorporate style formatting while
  formatting a time unit. Format() does take style as an argument but the
  style is not used anywhere. So currently the abbreviated style doesn't
  work and by default the time unit is formatted to the full style.
  
  * Fix: Move the style flag from BTimeUnitFormat::Format() to the
  BTimeUnitFormat constructors and call the relevant icu::TimeUnitFormat
  constructor. Map the Haiku defined style unit to the corresponding ICU
  unit. Move the style flag from BDurationFormat::Format() to the
  BDurationFormat constructors to map the changes in BTimeUnitFormat.
  
  Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
  
  Fixes #13508

                       [ Akshay Agarwal <agarwal.akshay.akshay8@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51173
Commit:      f5c544b59a75f9d2912f158fad8a4cbc9ddc55da
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f5c544b59a75
Author:      Akshay Agarwal <agarwal.akshay.akshay8@xxxxxxxxx>
Date:        Tue May 16 22:16:31 2017 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Commit-Date: Wed May 17 17:53:46 2017 UTC

Ticket:      https://dev.haiku-os.org/ticket/13508

----------------------------------------------------------------------------

4 files changed, 45 insertions(+), 22 deletions(-)
headers/os/locale/DurationFormat.h | 10 +++++-----
headers/os/locale/TimeUnitFormat.h |  9 +++++----
src/kits/locale/DurationFormat.cpp | 14 ++++++++------
src/kits/locale/TimeUnitFormat.cpp | 34 +++++++++++++++++++++++++++-------

----------------------------------------------------------------------------

diff --git a/headers/os/locale/DurationFormat.h 
b/headers/os/locale/DurationFormat.h
index 9a529ec..fa0e92c 100644
--- a/headers/os/locale/DurationFormat.h
+++ b/headers/os/locale/DurationFormat.h
@@ -28,9 +28,10 @@ class BDurationFormat : public BFormat {
 public:
                                                                
BDurationFormat(const BLanguage& language,
                                                                        const 
BFormattingConventions& conventions,
-                                                                       const 
BString& separator = ", ");
-                                                               BDurationFormat(
-                                                                       const 
BString& separator = ", ");
+                                                                       const 
BString& separator = ", ",
+                                                                       const 
time_unit_style style = B_TIME_UNIT_FULL);
+                                                               
BDurationFormat(const BString& separator = ", ",
+                                                                       const 
time_unit_style style = B_TIME_UNIT_FULL);
                                                                
BDurationFormat(const BDurationFormat& other);
        virtual                                         ~BDurationFormat();
 
@@ -39,8 +40,7 @@ public:
 
                        status_t                        Format(BString& buffer,
                                                                        const 
bigtime_t startValue,
-                                                                       const 
bigtime_t stopValue,
-                                                                       
time_unit_style style = B_TIME_UNIT_FULL
+                                                                       const 
bigtime_t stopValue
                                                                        ) const;
 
 private:
diff --git a/headers/os/locale/TimeUnitFormat.h 
b/headers/os/locale/TimeUnitFormat.h
index 447284b..632cdcb 100644
--- a/headers/os/locale/TimeUnitFormat.h
+++ b/headers/os/locale/TimeUnitFormat.h
@@ -43,16 +43,17 @@ class BTimeUnitFormat : public BFormat {
        typedef BFormat                         Inherited;
 
 public:
-                                                               
BTimeUnitFormat();
+                                                               
BTimeUnitFormat(const time_unit_style style =
+                                                                       
B_TIME_UNIT_FULL);
                                                                
BTimeUnitFormat(const BLanguage& language,
-                                                                       const 
BFormattingConventions& conventions);
+                                                                       const 
BFormattingConventions& conventions,
+                                                                       const 
time_unit_style style = B_TIME_UNIT_FULL);
                                                                
BTimeUnitFormat(const BTimeUnitFormat& other);
        virtual                                         ~BTimeUnitFormat();
 
                        status_t                        Format(BString& buffer,
                                                                        const 
int32 value,
-                                                                       const 
time_unit_element unit,
-                                                                       
time_unit_style style = B_TIME_UNIT_FULL
+                                                                       const 
time_unit_element unit
                                                                        ) const;
 
 private:
diff --git a/src/kits/locale/DurationFormat.cpp 
b/src/kits/locale/DurationFormat.cpp
index 9536480..f00608a 100644
--- a/src/kits/locale/DurationFormat.cpp
+++ b/src/kits/locale/DurationFormat.cpp
@@ -35,11 +35,12 @@ static const UCalendarDateFields skUnitMap[] = {
 
 
 BDurationFormat::BDurationFormat(const BLanguage& language,
-       const BFormattingConventions& conventions, const BString& separator)
+       const BFormattingConventions& conventions,
+       const BString& separator, const time_unit_style style)
        :
        Inherited(language, conventions),
        fSeparator(separator),
-       fTimeUnitFormat(language, conventions)
+       fTimeUnitFormat(language, conventions, style)
 {
        UErrorCode icuStatus = U_ZERO_ERROR;
        fCalendar = new GregorianCalendar(icuStatus);
@@ -50,11 +51,12 @@ BDurationFormat::BDurationFormat(const BLanguage& language,
 }
 
 
-BDurationFormat::BDurationFormat(const BString& separator)
+BDurationFormat::BDurationFormat(const BString& separator,
+       const time_unit_style style)
        :
        Inherited(),
        fSeparator(separator),
-       fTimeUnitFormat()
+       fTimeUnitFormat(style)
 {
        UErrorCode icuStatus = U_ZERO_ERROR;
        fCalendar = new GregorianCalendar(icuStatus);
@@ -118,7 +120,7 @@ BDurationFormat::SetTimeZone(const BTimeZone* timeZone)
 
 status_t
 BDurationFormat::Format(BString& buffer, const bigtime_t startValue,
-       const bigtime_t stopValue, time_unit_style style) const
+       const bigtime_t stopValue) const
 {
        UErrorCode icuStatus = U_ZERO_ERROR;
        fCalendar->setTime((UDate)startValue / 1000, icuStatus);
@@ -139,7 +141,7 @@ BDurationFormat::Format(BString& buffer, const bigtime_t 
startValue,
                        else
                                needSeparator = true;
                        status_t status = fTimeUnitFormat.Format(buffer, delta,
-                               (time_unit_element)unit, style);
+                               (time_unit_element)unit);
                        if (status != B_OK)
                                return status;
                }
diff --git a/src/kits/locale/TimeUnitFormat.cpp 
b/src/kits/locale/TimeUnitFormat.cpp
index 61a8ba5..c91b530 100644
--- a/src/kits/locale/TimeUnitFormat.cpp
+++ b/src/kits/locale/TimeUnitFormat.cpp
@@ -34,13 +34,26 @@ static const TimeUnit::UTimeUnitFields skUnitMap[] = {
        TimeUnit::UTIMEUNIT_SECOND,
 };
 
+//maps our unit style to the corresponding ICU unit
+static const UTimeUnitFormatStyle kTimeUnitStyleToICU[] = {
+       UTMUTFMT_ABBREVIATED_STYLE,
+       UTMUTFMT_FULL_STYLE,
+};
+
 
-BTimeUnitFormat::BTimeUnitFormat()
+BTimeUnitFormat::BTimeUnitFormat(const time_unit_style style)
        : Inherited()
 {
        Locale icuLocale(fLanguage.Code());
        UErrorCode icuStatus = U_ZERO_ERROR;
-       fFormatter = new TimeUnitFormat(icuLocale, icuStatus);
+       if (style != B_TIME_UNIT_ABBREVIATED && style != B_TIME_UNIT_FULL) {
+               fFormatter = NULL;
+               fInitStatus = B_BAD_VALUE;
+               return;
+       }
+
+       fFormatter = new TimeUnitFormat(icuLocale, kTimeUnitStyleToICU[style],
+               icuStatus);
        if (fFormatter == NULL) {
                fInitStatus = B_NO_MEMORY;
                return;
@@ -52,12 +65,20 @@ BTimeUnitFormat::BTimeUnitFormat()
 
 
 BTimeUnitFormat::BTimeUnitFormat(const BLanguage& language,
-       const BFormattingConventions& conventions)
+       const BFormattingConventions& conventions,
+       const time_unit_style style)
        : Inherited(language, conventions)
 {
        Locale icuLocale(fLanguage.Code());
        UErrorCode icuStatus = U_ZERO_ERROR;
-       fFormatter = new TimeUnitFormat(icuLocale, icuStatus);
+       if (style != B_TIME_UNIT_ABBREVIATED && style != B_TIME_UNIT_FULL) {
+               fFormatter = NULL;
+               fInitStatus = B_BAD_VALUE;
+               return;
+       }
+
+       fFormatter = new TimeUnitFormat(icuLocale, kTimeUnitStyleToICU[style],
+               icuStatus);
        if (fFormatter == NULL) {
                fInitStatus = B_NO_MEMORY;
                return;
@@ -87,10 +108,9 @@ BTimeUnitFormat::~BTimeUnitFormat()
 
 status_t
 BTimeUnitFormat::Format(BString& buffer, const int32 value,
-       const time_unit_element unit, time_unit_style style) const
+       const time_unit_element unit) const
 {
-       if (unit < 0 || unit > B_TIME_UNIT_LAST
-               || (style != B_TIME_UNIT_ABBREVIATED && style != 
B_TIME_UNIT_FULL))
+       if (unit < 0 || unit > B_TIME_UNIT_LAST)
                return B_BAD_VALUE;
 
        if (fFormatter == NULL)


Other related posts:

  • » [haiku-commits] haiku: hrev51173 - src/kits/locale headers/os/locale - pulkomandy