#include <opennurbs_locale.h>

Public Types

enum  { BUFFER_MAXIMUM_CAPACITY = 128 }
 
enum  WindowsLCID : unsigned int {
  OrdinalLCID = 0, InvariantCultureLCID = 0x0027, cs_CZ_LCID = 0x0405, de_DE_LCID = 0x0407,
  en_US_LCID = 0x0409, en_CA_LCID = 0x1009, es_ES_tradnl_LCID = 0x040A, es_ES_LCID = 0x0c0a,
  fr_FR_LCID = 0x040c, it_IT_LCID = 0x0410, ja_JP_LCID = 0x0411, ko_KR_LCID = 0x0412,
  pl_PL_LCID = 0x0415, pt_PT_LCID = 0x0816, zh_CN_LCID = 0x0804, zh_TW_LCID = 0x0404
}
 

Public Member Functions

 ON_Locale () ON_NOEXCEPT
 Default construction creates a copy of ON_Local::Ordinal. More...
 
 ON_Locale (const ON_Locale &)=default
 
 ~ON_Locale ()=default
 
const char * BCP47LanguageTag () const
 
const char * GetAppleLanguageName (char *buffer, size_t buffer_capacity) const
 
const wchar_t * GetAppleLanguageName (wchar_t *buffer, size_t buffer_capacity) const
 
const char * GetAppleLocaleName (char *buffer, size_t buffer_capacity) const
 
const wchar_t * GetAppleLocaleName (wchar_t *buffer, size_t buffer_capacity) const
 
const char * GetBCP47LanguageTag (char *buffer, size_t buffer_capacity) const
 Get the language id. More...
 
const wchar_t * GetBCP47LanguageTag (wchar_t *buffer, size_t buffer_capacity) const
 
const char * GetWindowsLocaleName (char *buffer, size_t buffer_capacity) const
 Get the Microsoft Windows locale id. More...
 
const wchar_t * GetWindowsLocaleName (wchar_t *buffer, size_t buffer_capacity) const
 
bool IsInvariantCulture () const
 
bool IsOrdinal () const
 
bool IsOrdinalOrInvariantCulture () const
 
const char * LanguageCode () const
 
ON_CRT_locale_t NumericLocalePtr () const
 NumericLocalePtr() is an expert user function needed to call C-runtime functions that format or parse numbers. This locale must never be used to collate or map strings. More...
 
ON_Localeoperator= (const ON_Locale &)=default
 
const char * RegionCode () const
 
const char * ScriptCode () const
 
ON_CRT_locale_t StringCollateAndMapLocalePtr () const
 StringCollateAndMapLocalePtr() is an expert user function needed to call C-runtime functions that collate (compare) and map (toupper/tolower) strings. This locale must never be used for formatting or parsing numbers. More...
 
ON__UINT32 WindowsLCID () const
 
const char * WindowsSortOrder () const
 

Static Public Member Functions

static unsigned int EnforcePeriodAsCRuntimeDecimalPoint ()
 Use a call like setlocale(LC_NUMERIC,"C") to configure the C runtime formatted printing and scanning functions to use the period character as the decimal point for doubles and floats. More...
 
static ON_Locale FromAppleName (const char *apple_name)
 Create a locale from an Apple locale or language name More...
 
static ON_Locale FromAppleName (const wchar_t *apple_name)
 
static ON_Locale FromBCP47LanguageName (const char *language_name)
 Create a locale from a BCP 47 language name. More...
 
static ON_Locale FromBCP47LanguageName (const wchar_t *language_name)
 
static ON_Locale FromSubtags (const char *language_code, const char *script_code, const char *region_code)
 Create a locale from BCP 47 lanugage code, script code and region code. More...
 
static ON_Locale FromSubtags (const wchar_t *language_code, const wchar_t *script_code, const wchar_t *region_code)
 
static ON_Locale FromWindowsLCID (ON__UINT32 windows_lcid)
 Create a locale from a Windows locale id. More...
 
static ON_Locale FromWindowsName (const char *windows_name)
 Create a locale from a Windows locale name. More...
 
static ON_Locale FromWindowsName (const wchar_t *windows_name)
 
static bool ParseName (const wchar_t *locale_name, int locale_name_element_count, wchar_t *language_code, size_t language_code_capacity, wchar_t *extlang_code, size_t extlang_code_capacity, wchar_t *script_code, size_t script_code_capacity, wchar_t *region_code, size_t region_code_capacity, wchar_t *windows_sortorder, size_t windows_sortorder_capacity)
 Attempt to parse a string that is a language name or locale name and extract language code, extlang code script code, region code and Windows sort order. More...
 
static bool ParseName (const char *locale_name, int locale_name_element_count, char *language_code, size_t language_code_capacity, char *extlang_code, size_t extlang_code_capacity, char *script_code, size_t script_code_capacity, char *region_code, size_t region_code_capacity, char *windows_sortorder, size_t windows_sortorder_capacity)
 
static bool PeriodIsCRuntimeDecimalPoint ()
 
static bool SetCurrentCulture (const ON_Locale &current_culture_locale)
 Set the current culture locale More...
 
static bool SetPeriodAsCRuntimeDecimalPoint ()
 Use a call like setlocale(LC_NUMERIC,"C") to configure the C runtime formatted printing and scanning functions to use the period character as the decimal point for doubles and floats. More...
 

Static Public Attributes

static const ON_LocaleCurrentCulture
 
static const ON_Locale InvariantCulture
 
static const ON_Locale Ordinal
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
BUFFER_MAXIMUM_CAPACITY 

◆ WindowsLCID

enum ON_Locale::WindowsLCID : unsigned int
Enumerator
OrdinalLCID 
InvariantCultureLCID 
cs_CZ_LCID 

Windows LCID for languages Rhino supports.

"cs-CZ" Czech, ???? script implied

de_DE_LCID 

"de-DE" German, Germany, Latn script implied

en_US_LCID 

"en-US" English, US, Latn script implied

en_CA_LCID 

"en-CA" English, Canada, Latn script implied

es_ES_tradnl_LCID 

"es-ES_tradnl" Spanish, Spain, Latn script implied, traditional sort

es_ES_LCID 

"es-ES" Spanish, Spain, Latn script implied, modern sort

fr_FR_LCID 

"fr-FR" French, France, Latn script implied

it_IT_LCID 

"it-IT" Italian, Italy, Latn script implied

ja_JP_LCID 

"ja-JP" Japanese, Japan, ???? script implied

ko_KR_LCID 

Korean, Republic of Korea, ???? script implied.

pl_PL_LCID 

Polish, Poland, ???? script implied.

pt_PT_LCID 

Portuguese, Portugal, Latn script implied.

zh_CN_LCID 

Standard Chinese (Mandarin), Peoples Republic of China, Hans script implied (simplified characters)

zh_TW_LCID 

Standard Chinese (Mandarin), Taiwan, Hant script implied (traditional characters)

Constructor & Destructor Documentation

◆ ON_Locale() [1/2]

ON_Locale::ON_Locale ( )

Default construction creates a copy of ON_Local::Ordinal.

◆ ~ON_Locale()

ON_Locale::~ON_Locale ( )
default

◆ ON_Locale() [2/2]

ON_Locale::ON_Locale ( const ON_Locale )
default

Member Function Documentation

◆ BCP47LanguageTag()

const char* ON_Locale::BCP47LanguageTag ( ) const

TODODOC: A string of the form TODODOC: TODODOC: <language>[-<Script>][-<REGION>] TODODOC: TODODOC: <language> TODODOC: ISO 639 language code. TODODOC: http://www.iso.org/iso/language_codes TODODOC: TODODOC: <Script> is optional. TODODOC: If present, it is a 4 alpha letter ISO 15924 script code TODODOC: http://www.unicode.org/iso15924/iso15924-codes.html TODODOC: TODODOC: <REGION> TODODOC: ISO 3166-1 country/region identifier. (2 alpha letters) TODODOC: or UN M.49 code (3 digits) TODODOC: http://www.iso.org/iso/home/standards/country_codes.htm TODODOC:

ON_Locale::InvariantCulture.BCP47LanguageName() = ""; ON_Locale::Oridnal.BCP47LanguageName() = "";

◆ EnforcePeriodAsCRuntimeDecimalPoint()

static unsigned int ON_Locale::EnforcePeriodAsCRuntimeDecimalPoint ( )
static

Use a call like setlocale(LC_NUMERIC,"C") to configure the C runtime formatted printing and scanning functions to use the period character as the decimal point for doubles and floats.

Returns
0: failed 1: success Currently The decimal piont is a period in the C-runtime formatted printing and scanning functions. 2: success When called, the decimal piont was not a period, but a call to ON_Locale::SetPeriodAsCRuntimeDecimalPoint() restored the defaut behavior.

◆ FromAppleName() [1/2]

static ON_Locale ON_Locale::FromAppleName ( const char *  apple_name)
static

Create a locale from an Apple locale or language name

Parameters
apple_name[in] The Apple name has the form <language>[-<Script>][-<REGION>]. An underbar (_) may be used in place of a hyphen (-). Case is not important.
Returns

ON_Locale identified by locale_name. If locale_name is not valid or not supported, a copy of ON_Locale::Ordinal is returned.

◆ FromAppleName() [2/2]

static ON_Locale ON_Locale::FromAppleName ( const wchar_t *  apple_name)
static

◆ FromBCP47LanguageName() [1/2]

static ON_Locale ON_Locale::FromBCP47LanguageName ( const char *  language_name)
static

Create a locale from a BCP 47 language name.

Parameters
language_name[in] The language name has the form <language>[-<Script>][-<REGION>] Case is not important.
Returns
ON_Locale identified by language_name. If locale_name is not valid or not supported, a copy of ON_Locale::Ordinal is returned.

◆ FromBCP47LanguageName() [2/2]

static ON_Locale ON_Locale::FromBCP47LanguageName ( const wchar_t *  language_name)
static

◆ FromSubtags() [1/2]

static ON_Locale ON_Locale::FromSubtags ( const char *  language_code,
const char *  script_code,
const char *  region_code 
)
static

Create a locale from BCP 47 lanugage code, script code and region code.

Parameters
language_code[in] ISO 639 language code. When avilable, two letter codes from ISO 639-1 are prefered. http://www.iso.org/iso/language_codes
script[in] nullptr, empty string, or a 4 letter ISO 15924 script code http://www.unicode.org/iso15924/iso15924-codes.html

<REGION> nullptr, empty string, or an ISO 3166 country/region identifier. http://www.iso.org/iso/home/standards/country_codes.htm

Returns
ON_Locale identified by the locale name. If the locale name is not valid or not supported, a copy of ON_Locale::Ordinal is returned.

◆ FromSubtags() [2/2]

static ON_Locale ON_Locale::FromSubtags ( const wchar_t *  language_code,
const wchar_t *  script_code,
const wchar_t *  region_code 
)
static

◆ FromWindowsLCID()

static ON_Locale ON_Locale::FromWindowsLCID ( ON__UINT32  windows_lcid)
static

Create a locale from a Windows locale id.

Parameters
lcid[in] Windows LCID value or zero for the "ordinal" locale.
Returns
ON_Locale identified by lcid. If lcid is not valid or not supported, a copy of ON_Locale::Ordinal is returned.

◆ FromWindowsName() [1/2]

static ON_Locale ON_Locale::FromWindowsName ( const char *  windows_name)
static

Create a locale from a Windows locale name.

Parameters
windows_name[in] The Windows name has the form <language>[-<Script>][-<REGION>][_<sort_order>] Case is not important.
Returns
ON_Locale identified by locale_name. If locale_name is not valid or not supported, a copy of ON_Locale::Ordinal is returned.

◆ FromWindowsName() [2/2]

static ON_Locale ON_Locale::FromWindowsName ( const wchar_t *  windows_name)
static

◆ GetAppleLanguageName() [1/2]

const char* ON_Locale::GetAppleLanguageName ( char *  buffer,
size_t  buffer_capacity 
) const
Returns

Apple OS X / iOS locale name in the form <language>[-<Script>][-<REGION>]

<language> ISO 639 language code. When avilable, two letter codes from ISO 639-1 are prefered. http://www.iso.org/iso/language_codes

<Script> is optional. If present, it is a 4 alpha letter ISO 15924 script code http://www.unicode.org/iso15924/iso15924-codes.html

<REGION> ISO 3166-1 country/region identifier. (2 alpha letters) or UN M.49 code (3 digits) http://www.iso.org/iso/home/standards/country_codes.htm

The Invariant locale name is the empty string "". Apple language names have a hyphen (-) before the region. Apple locale names have an underbar (_) before the region.

◆ GetAppleLanguageName() [2/2]

const wchar_t* ON_Locale::GetAppleLanguageName ( wchar_t *  buffer,
size_t  buffer_capacity 
) const

◆ GetAppleLocaleName() [1/2]

const char* ON_Locale::GetAppleLocaleName ( char *  buffer,
size_t  buffer_capacity 
) const
Returns

Apple OS X / iOS locale name in the form <language>[-<Script>][_<REGION>]

<language> ISO 639 language code. When avilable, two letter codes from ISO 639-1 are prefered. http://www.iso.org/iso/language_codes

<Script> is optional. If present, it is a 4 alpha letter ISO 15924 script code http://www.unicode.org/iso15924/iso15924-codes.html

<REGION> ISO 3166-1 country/region identifier. (2 alpha letters) or UN M.49 code (3 digits) http://www.iso.org/iso/home/standards/country_codes.htm

The Invariant locale name is the empty string "". Apple language names have a hyphen (-) before the region. Apple locale names have an underbar (_) before the region.

◆ GetAppleLocaleName() [2/2]

const wchar_t* ON_Locale::GetAppleLocaleName ( wchar_t *  buffer,
size_t  buffer_capacity 
) const

◆ GetBCP47LanguageTag() [1/2]

const char* ON_Locale::GetBCP47LanguageTag ( char *  buffer,
size_t  buffer_capacity 
) const

Get the language id.

Parameters
buffer[out] A null terminated string containing the language id is returned in this buffer. The string has the form:

<language>[-<Script>][-<REGION>]

<language> ISO 639 language code. http://www.iso.org/iso/language_codes

<Script> is optional. If present, it is a 4 alpha letter ISO 15924 script code http://www.unicode.org/iso15924/iso15924-codes.html

<REGION> ISO 3166-1 country/region identifier. (2 alpha letters) or UN M.49 code (3 digits) http://www.iso.org/iso/home/standards/country_codes.htm

Parameters
buffer_capacity[in] number of elements in the buffer. A capacity >= ON_Locale::BUFFER_MAXIMUM_CAPACITY will be large enough to hold all possible output.
Returns

If buffer_capacity is to small or buffer is nullptr, then nullptr is returned. Otherwise the pointer to buffer is returned.

The Invariant language name is the empty string "".

◆ GetBCP47LanguageTag() [2/2]

const wchar_t* ON_Locale::GetBCP47LanguageTag ( wchar_t *  buffer,
size_t  buffer_capacity 
) const

◆ GetWindowsLocaleName() [1/2]

const char* ON_Locale::GetWindowsLocaleName ( char *  buffer,
size_t  buffer_capacity 
) const

Get the Microsoft Windows locale id.

Parameters
buffer[out] A null terminated string containing the Microsoft Windows locale id is returned in this buffer. The string has the form:

<language>[-<Script>][-<REGION>][_<sort_order>] (UTF-8 string encoding)

<language> ISO 639 language code. http://www.iso.org/iso/language_codes

<Script> is optional. If present, it is a 4 alpha letter ISO 15924 script code http://www.unicode.org/iso15924/iso15924-codes.html

<REGION> ISO 3166-1 country/region identifier. (2 alpha letters) or UN M.49 code (3 digits) http://www.iso.org/iso/home/standards/country_codes.htm

<sort_order> Up to six letters specifying a sort order. Microsoft Windows codes are used.

Parameters
buffer_capacity[in] number of elements in the buffer. A capacity >= ON_Locale::BUFFER_MAXIMUM_CAPACITY will be large enough to hold all possible output.
Returns

If buffer_capacity is to small or buffer is nullptr, then nullptr is returned. Otherwise the pointer to buffer is returned.

The Invariant locale name is the empty string "".

◆ GetWindowsLocaleName() [2/2]

const wchar_t* ON_Locale::GetWindowsLocaleName ( wchar_t *  buffer,
size_t  buffer_capacity 
) const

◆ IsInvariantCulture()

bool ON_Locale::IsInvariantCulture ( ) const
Returns
True if this is ON_Locale:InvariantCulture or a copy.

◆ IsOrdinal()

bool ON_Locale::IsOrdinal ( ) const
Returns
True if this is ON_Locale:Ordinal or a copy.

◆ IsOrdinalOrInvariantCulture()

bool ON_Locale::IsOrdinalOrInvariantCulture ( ) const
Returns
True if this is ON_Locale:Ordinal, ON_Locale:InvariantCulture or a copy of one of them.

◆ LanguageCode()

const char* ON_Locale::LanguageCode ( ) const
Returns
ISO 639 language code. When avilable, two letter codes from ISO 639-1 are prefered.

The InvariantCulture.LanguageCode() is "".

See also
http://www.iso.org/iso/language_codes

◆ NumericLocalePtr()

ON_CRT_locale_t ON_Locale::NumericLocalePtr ( ) const

NumericLocalePtr() is an expert user function needed to call C-runtime functions that format or parse numbers. This locale must never be used to collate or map strings.

The primary use for this function is in opennurbs implementations of ON_String and ON_wString number formatting and parsing functions.

Returns
A value that can be passed into C-runtime functions that take a locale parameter.
@verbatim
// Call _sprintf_p_l
ON_CRT_locale_t numeric_locale = ON_Locale::CurrentCulture::NumericLocalePtr();
_sprintf_p_l(....,locale,...);
@endverbatim

◆ operator=()

ON_Locale& ON_Locale::operator= ( const ON_Locale )
default

◆ ParseName() [1/2]

static bool ON_Locale::ParseName ( const wchar_t *  locale_name,
int  locale_name_element_count,
wchar_t *  language_code,
size_t  language_code_capacity,
wchar_t *  extlang_code,
size_t  extlang_code_capacity,
wchar_t *  script_code,
size_t  script_code_capacity,
wchar_t *  region_code,
size_t  region_code_capacity,
wchar_t *  windows_sortorder,
size_t  windows_sortorder_capacity 
)
static

Attempt to parse a string that is a language name or locale name and extract language code, extlang code script code, region code and Windows sort order.

The language name has the form <language>[<-extlang>][-<Script>][-<REGION>]

If the Microsoft [_<windows_sort_order>] appears after the language name, it is parsed.

Apple "locale ids" of the form <language>_<REGION>" are parsed as well (an underbar separator instead of a hyphen before <REGION>).

Parameters
locale_name[in] name to parse. Case is ignored.
locale_name_element_count[in] number of elements to parse in locale_name[] If locale_name_element_count < 0, then a null terminator ends parsing.
language_code[out]
language_code_capacity[in] number of elements available in language_code[].
extlang_code[out]
extlang_code_capacity[in] number of elements available in extlang_code[].
script_code[out]
script_code_capacity[in] number of elements available in script_code[].
region_code[out]
region_code_capacity[in] number of elements available in region_code[].
windows_sortorder[out]
windows_sortorder_capacity[in] number of elements available in windows_sortorder[].

The standards for language identifiers (RFC 5646 and BCP 47) states that a hyphen ( Unicode U+002D ) is supposed to be the separator between subtags.

ftp://ftp.isi.edu/in-notes/bcp/bcp47.txt

◆ ParseName() [2/2]

static bool ON_Locale::ParseName ( const char *  locale_name,
int  locale_name_element_count,
char *  language_code,
size_t  language_code_capacity,
char *  extlang_code,
size_t  extlang_code_capacity,
char *  script_code,
size_t  script_code_capacity,
char *  region_code,
size_t  region_code_capacity,
char *  windows_sortorder,
size_t  windows_sortorder_capacity 
)
static

◆ PeriodIsCRuntimeDecimalPoint()

static bool ON_Locale::PeriodIsCRuntimeDecimalPoint ( )
static
Returns
True if the C runtime formatted printing and scanning functions are using the period character as the decimal point for doubles and floats.

◆ RegionCode()

const char* ON_Locale::RegionCode ( ) const
Returns
ISO 3166-1 country/region identifier (2 alpha) or UN M.49 code (3 digits)

The returned string can be "" if the no region is specified. The InvariantCulture.RegionCode() is "".

See also
http://www.iso.org/iso/home/standards/country_codes.htm

◆ ScriptCode()

const char* ON_Locale::ScriptCode ( ) const
Returns
A 4 letter ISO 15924 script code

The returned string can be "" if the no script is specified for the locale. The InvariantCulture.ScriptCode() is "".

See also
http://www.unicode.org/iso15924/iso15924-codes.html

◆ SetCurrentCulture()

static bool ON_Locale::SetCurrentCulture ( const ON_Locale current_culture_locale)
static

Set the current culture locale

Parameters
current_culture_locale[in]

◆ SetPeriodAsCRuntimeDecimalPoint()

static bool ON_Locale::SetPeriodAsCRuntimeDecimalPoint ( )
static

Use a call like setlocale(LC_NUMERIC,"C") to configure the C runtime formatted printing and scanning functions to use the period character as the decimal point for doubles and floats.

Returns
True if successful.

◆ StringCollateAndMapLocalePtr()

ON_CRT_locale_t ON_Locale::StringCollateAndMapLocalePtr ( ) const

StringCollateAndMapLocalePtr() is an expert user function needed to call C-runtime functions that collate (compare) and map (toupper/tolower) strings. This locale must never be used for formatting or parsing numbers.

The primary use for this function is in opennurbs implementations of ON_String and ON_wString collate and map functions.

Returns
A value that can be passed into C-runtime functions that take a locale parameter.
@verbatim
// Call _wcsicoll_l
ON_CRT_locale_t coll_locale = ON_Locale::CurrentCulture::StringCollateAndMapLocalePtr();
_wcsicoll_l(....,coll_locale);
@endverbatim

◆ WindowsLCID()

ON__UINT32 ON_Locale::WindowsLCID ( ) const
Returns
Microsoft Windows LCID value ON_LocaleLCID::OrdinalLCID (=0) The locale is a copy of ON_Locale::Ordinal. ON_Locale::InvariantCultureLCID (=0x00000027U) The locale is a copy of ON_Locale::InvariantCulture.

◆ WindowsSortOrder()

const char* ON_Locale::WindowsSortOrder ( ) const
Returns
A 6 letter locale sort order.

The returned string can be "" if the no sort order is specified for the locale. The InvariantCulture.WindowsSortOrder() is "".

See also
https://msdn.microsoft.com/en-us/library/windows/desktop/dd374060(v=vs.85).aspx

Member Data Documentation

◆ CurrentCulture

const ON_Locale& ON_Locale::CurrentCulture
static

◆ InvariantCulture

const ON_Locale ON_Locale::InvariantCulture
static

◆ Ordinal

const ON_Locale ON_Locale::Ordinal
static