[haiku-commits] haiku: hrev53609 - src/kits/locale docs/user/locale headers/os/locale

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 2 Dec 2019 07:32:18 -0500 (EST)

hrev53609 adds 1 changeset to branch 'master'
old head: b4c187b004a360a3de34f5f4ef973581a327db30
new head: 70cdd7d4f5fc62e8b3e220646f84235ec3d444d5
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=70cdd7d4f5fc+%5Eb4c187b004a3

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

70cdd7d4f5fc: BCountry: add SetTo and InitCheck.
  
  Change-Id: I5fbc2a1c0e735d6edeb23672017bb64d1b3f4390
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/1872
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

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

Revision:    hrev53609
Commit:      70cdd7d4f5fc62e8b3e220646f84235ec3d444d5
URL:         https://git.haiku-os.org/haiku/commit/?id=70cdd7d4f5fc
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Fri Sep 20 10:34:29 2019 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Mon Dec  2 12:32:15 2019 UTC

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

3 files changed, 83 insertions(+), 8 deletions(-)
docs/user/locale/Country.dox | 32 +++++++++++++++++++++---
headers/os/locale/Country.h  |  5 +++-
src/kits/locale/Country.cpp  | 54 +++++++++++++++++++++++++++++++++++++---

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

diff --git a/docs/user/locale/Country.dox b/docs/user/locale/Country.dox
index 8c1a74a49f..2eebdcce5c 100644
--- a/docs/user/locale/Country.dox
+++ b/docs/user/locale/Country.dox
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 Haiku, Inc. All rights reserved.
+ * Copyright 2011-2019 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -8,8 +8,8 @@
  *             John Scipione, jscipione@xxxxxxxxx
  * 
  * Corresponds to:
- *             headers/os/locale/Country.h      rev 42274
- *             src/kits/locale/Country.cpp      rev 42274
+ *             headers/os/locale/Country.h      rev 53489
+ *             src/kits/locale/Country.cpp      rev 53489
  */
 
 
@@ -77,6 +77,32 @@
 */
 
 
+/*!
+       \fn status_t BCountry::SetTo(const char* countryCode)
+       \brief Initialize a BCountry from a country code.
+
+       \param countryCode The country code to initialize from.
+
+       \returns Same value as InitCheck.
+
+       \since Haiku R1
+*/
+
+
+/*!
+       \fn status_t BCountry::InitCheck()
+       \brief Check validity of the BCountry object.
+
+       \param countryCode The country code to initialize from.
+
+       \returns B_OK if everything went fine, B_BAD_DATA if the specified 
country
+                code is not valid, B_NO_MEMORY if the object could not be
+                        allocated properly.
+
+       \since Haiku R1
+*/
+
+
 /*!
        \fn status_t BCountry::GetName(BString& name,
                const BLanguage* displayLanguage = NULL) const
diff --git a/headers/os/locale/Country.h b/headers/os/locale/Country.h
index 681910e895..ae41f5351f 100644
--- a/headers/os/locale/Country.h
+++ b/headers/os/locale/Country.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2011, Haiku, Inc.
+ * Copyright 2003-2019, Haiku, Inc.
  * Distributed under the terms of the MIT Licence.
  */
 #ifndef _COUNTRY_H_
@@ -32,6 +32,9 @@ public:
                                                                BCountry& 
operator=(const BCountry& other);
                                                                ~BCountry();
 
+                       status_t                        SetTo(const char* 
countryCode);
+                       status_t                        InitCheck() const;
+
                        status_t                        GetNativeName(BString& 
name) const;
                        status_t                        GetName(BString& name,
                                                                        const 
BLanguage* displayLanguage = NULL
diff --git a/src/kits/locale/Country.cpp b/src/kits/locale/Country.cpp
index e95711d5f0..7912908d2d 100644
--- a/src/kits/locale/Country.cpp
+++ b/src/kits/locale/Country.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2003-2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
- * Copyright 2009-2010, Adrien Destugues, pulkomandy@xxxxxxxxx.
+ * Copyright 2009-2019, Adrien Destugues, pulkomandy@xxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 
@@ -30,8 +30,9 @@
 
 BCountry::BCountry(const char* countryCode)
        :
-       fICULocale(new icu::Locale("", countryCode))
+       fICULocale(NULL)
 {
+       SetTo(countryCode);
 }
 
 
@@ -48,7 +49,10 @@ BCountry::operator=(const BCountry& other)
        if (this == &other)
                return *this;
 
-       *fICULocale = *other.fICULocale;
+       if (!fICULocale)
+               fICULocale = new icu::Locale(*other.fICULocale);
+       else
+               *fICULocale = *other.fICULocale;
 
        return *this;
 }
@@ -60,9 +64,36 @@ BCountry::~BCountry()
 }
 
 
+status_t
+BCountry::SetTo(const char* countryCode)
+{
+       delete fICULocale;
+       fICULocale = new icu::Locale("", countryCode);
+
+       return InitCheck();
+}
+
+
+status_t
+BCountry::InitCheck() const
+{
+       if (fICULocale == NULL)
+               return B_NO_MEMORY;
+
+       if (fICULocale->isBogus())
+               return B_BAD_DATA;
+
+       return B_OK;
+}
+
+
 status_t
 BCountry::GetNativeName(BString& name) const
 {
+       status_t valid = InitCheck();
+       if (valid != B_OK)
+               return valid;
+
        UnicodeString string;
        fICULocale->getDisplayName(*fICULocale, string);
        string.toTitle(NULL, *fICULocale);
@@ -78,7 +109,10 @@ BCountry::GetNativeName(BString& name) const
 status_t
 BCountry::GetName(BString& name, const BLanguage* displayLanguage) const
 {
-       status_t status = B_OK;
+       status_t status = InitCheck();
+       if (status != B_OK)
+               return status;
+
        BString appLanguage;
        if (displayLanguage == NULL) {
                BMessage preferredLanguages;
@@ -105,6 +139,10 @@ BCountry::GetName(BString& name, const BLanguage* 
displayLanguage) const
 const char*
 BCountry::Code() const
 {
+       status_t status = InitCheck();
+       if (status != B_OK)
+               return NULL;
+
        return fICULocale->getCountry();
 }
 
@@ -112,6 +150,10 @@ BCountry::Code() const
 status_t
 BCountry::GetIcon(BBitmap* result) const
 {
+       status_t status = InitCheck();
+       if (status != B_OK)
+               return status;
+
        return BLocaleRoster::Default()->GetFlagIconForCountry(result, Code());
 }
 
@@ -119,6 +161,10 @@ BCountry::GetIcon(BBitmap* result) const
 status_t
 BCountry::GetAvailableTimeZones(BMessage* timeZones) const
 {
+       status_t status = InitCheck();
+       if (status != B_OK)
+               return status;
+
        return 
BLocaleRoster::Default()->GetAvailableTimeZonesForCountry(timeZones,
                Code());
 }


Other related posts:

  • » [haiku-commits] haiku: hrev53609 - src/kits/locale docs/user/locale headers/os/locale - Adrien Destugues