|
Archicad 30 C++ API
|
A locale provides support for formatting and parsing dates, times, numbers and currencies, for measurement units, for sort-order (collation), and more. Unicode defines a root (also called invariant by others) locale. Every locale is a tailoring of the root locale or its parent locale. For example:
The first component is an ISO-639 language code, the second component is an ISO-3166 region/country code. A locale identifier can contain more parts (e.g. script code), but we won’t cover them.
In order for Archicad to work correctly in every environment, we can’t rely on the user’s current locale settings. Using the root (invariant) locale for the operations also guarantees that we’ll get the same behavior across all platforms.
Consider a case where we want to compare two strings. Depending on the locale, we can get different results:
| Strings to compare | Locale | Result |
|---|---|---|
cukor < csap | root | false |
cukor < csap | hu_HU | true |
With the Hungarian locale the rules for the comparison are changed, knowing that cs is a letter by itself, and not two independent letters.
Using the root (invariant) locale is necessary to keep invariants in the program, for example to ensure that a list contains unique strings, or that it contains them sorted.
On GS::UniString the invariant operations don’t have any suffix: Compare, IsEqual, ToUpper, etc.
Example use case:
Let’s say that we’re on the Building Materials dialog. The Building Materials are listed ordered by their names. When the user would like to create a new material with a name which already exists, we have to refuse it.
For displaying the materials ordered by their names we should use locale-dependent functions as a comparator for the sorting algorithm. For checking whether a name already exists we must use the invariant functions.
On GS::UniString the locale-dependent operations are suffixed in two ways:
CompareWithLocale, etc.: does the operations according to the user’s current locale settings.CompareNatural, etc.: same as the WithLocale functions, just treats digits as numbers, so "11" < "100" will be true.On GS::UniString the binary operators will compare the strings as their bit representation compares. It’s beneficial to use them around containers for fast lookup if the Unicode rules don’t matter. They can also be used when we know that a text only contains ASCII characters, so Unicode handling wouldn’t make any difference.