BCountry: add SetTo and InitCheck.
Change-Id: I5fbc2a1c0e735d6edeb23672017bb64d1b3f4390 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1872 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
b4c187b004
commit
70cdd7d4f5
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
* John Scipione, [email protected]
|
* John Scipione, [email protected]
|
||||||
*
|
*
|
||||||
* Corresponds to:
|
* Corresponds to:
|
||||||
* headers/os/locale/Country.h rev 42274
|
* headers/os/locale/Country.h rev 53489
|
||||||
* src/kits/locale/Country.cpp rev 42274
|
* 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,
|
\fn status_t BCountry::GetName(BString& name,
|
||||||
const BLanguage* displayLanguage = NULL) const
|
const BLanguage* displayLanguage = NULL) const
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2011, Haiku, Inc.
|
* Copyright 2003-2019, Haiku, Inc.
|
||||||
* Distributed under the terms of the MIT Licence.
|
* Distributed under the terms of the MIT Licence.
|
||||||
*/
|
*/
|
||||||
#ifndef _COUNTRY_H_
|
#ifndef _COUNTRY_H_
|
||||||
@@ -32,6 +32,9 @@ public:
|
|||||||
BCountry& operator=(const BCountry& other);
|
BCountry& operator=(const BCountry& other);
|
||||||
~BCountry();
|
~BCountry();
|
||||||
|
|
||||||
|
status_t SetTo(const char* countryCode);
|
||||||
|
status_t InitCheck() const;
|
||||||
|
|
||||||
status_t GetNativeName(BString& name) const;
|
status_t GetNativeName(BString& name) const;
|
||||||
status_t GetName(BString& name,
|
status_t GetName(BString& name,
|
||||||
const BLanguage* displayLanguage = NULL
|
const BLanguage* displayLanguage = NULL
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2011, Axel Dörfler, [email protected].
|
* Copyright 2003-2011, Axel Dörfler, [email protected].
|
||||||
* Copyright 2009-2010, Adrien Destugues, [email protected].
|
* Copyright 2009-2019, Adrien Destugues, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -30,8 +30,9 @@
|
|||||||
|
|
||||||
BCountry::BCountry(const char* countryCode)
|
BCountry::BCountry(const char* countryCode)
|
||||||
:
|
:
|
||||||
fICULocale(new icu::Locale("", countryCode))
|
fICULocale(NULL)
|
||||||
{
|
{
|
||||||
|
SetTo(countryCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +49,9 @@ BCountry::operator=(const BCountry& other)
|
|||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
|
if (!fICULocale)
|
||||||
|
fICULocale = new icu::Locale(*other.fICULocale);
|
||||||
|
else
|
||||||
*fICULocale = *other.fICULocale;
|
*fICULocale = *other.fICULocale;
|
||||||
|
|
||||||
return *this;
|
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
|
status_t
|
||||||
BCountry::GetNativeName(BString& name) const
|
BCountry::GetNativeName(BString& name) const
|
||||||
{
|
{
|
||||||
|
status_t valid = InitCheck();
|
||||||
|
if (valid != B_OK)
|
||||||
|
return valid;
|
||||||
|
|
||||||
UnicodeString string;
|
UnicodeString string;
|
||||||
fICULocale->getDisplayName(*fICULocale, string);
|
fICULocale->getDisplayName(*fICULocale, string);
|
||||||
string.toTitle(NULL, *fICULocale);
|
string.toTitle(NULL, *fICULocale);
|
||||||
@@ -78,7 +109,10 @@ BCountry::GetNativeName(BString& name) const
|
|||||||
status_t
|
status_t
|
||||||
BCountry::GetName(BString& name, const BLanguage* displayLanguage) const
|
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;
|
BString appLanguage;
|
||||||
if (displayLanguage == NULL) {
|
if (displayLanguage == NULL) {
|
||||||
BMessage preferredLanguages;
|
BMessage preferredLanguages;
|
||||||
@@ -105,6 +139,10 @@ BCountry::GetName(BString& name, const BLanguage* displayLanguage) const
|
|||||||
const char*
|
const char*
|
||||||
BCountry::Code() const
|
BCountry::Code() const
|
||||||
{
|
{
|
||||||
|
status_t status = InitCheck();
|
||||||
|
if (status != B_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return fICULocale->getCountry();
|
return fICULocale->getCountry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +150,10 @@ BCountry::Code() const
|
|||||||
status_t
|
status_t
|
||||||
BCountry::GetIcon(BBitmap* result) const
|
BCountry::GetIcon(BBitmap* result) const
|
||||||
{
|
{
|
||||||
|
status_t status = InitCheck();
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
return BLocaleRoster::Default()->GetFlagIconForCountry(result, Code());
|
return BLocaleRoster::Default()->GetFlagIconForCountry(result, Code());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +161,10 @@ BCountry::GetIcon(BBitmap* result) const
|
|||||||
status_t
|
status_t
|
||||||
BCountry::GetAvailableTimeZones(BMessage* timeZones) const
|
BCountry::GetAvailableTimeZones(BMessage* timeZones) const
|
||||||
{
|
{
|
||||||
|
status_t status = InitCheck();
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
return BLocaleRoster::Default()->GetAvailableTimeZonesForCountry(timeZones,
|
return BLocaleRoster::Default()->GetAvailableTimeZonesForCountry(timeZones,
|
||||||
Code());
|
Code());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user