For example, Table 1 is a sensible locale entry for Australia. Some fields speak for themselves. Some are downright cryptic. I don't pretend that casual users can or should learn the mysteries of locale files. More likely, a system administrator or programmer would modify an existing locale file for each peculiar need. The point is that you can capture many peculiarities of a given culture with just a few hundred bytes of text.
Locale | "Australia' |
---|---|
currency_symbol | "$" |
decimal_point | "." |
grouping | "3" |
int_curr_symbol | "AUD" |
mon_decimal_point | "," |
mon_grouping | "3" |
negative_sign | "-" |
positive_sign | "+" |
frac_digits | 2 |
int_frac_digits | 2 |
n_cs_precedes | 1 |
n_sep_by_space | 0 |
A program can read this file at program startup and adapt in several critical ways to the preferences of the locals. Or it can adapt repeatedly to various locales as it runs, if it is more ambitious. Or it can tailor a specialized locale by choosing French dates, say, and accountants' conventions for formatting monetary values. A program shared in a multiprocessing system, such as UNIX, can even adapt simultaneously in different ways to different users. This example specifies how the locals prefer to format monetary and nonmonetary amounts and how they write their dates. That information is of widest interest to programmers writing adaptable applications. The locale file can also specify:
- Additions to various character classes, such as letters with accent marks or additional punctuation characters.
- The encoding of multibyte character strings and their corresponding wide-character codes for large character sets.
- The ordering rules for strcoll and strxfrm. I want to focus on this last item.
Despite what I said previously, strcoll is not the fundamental function. You can write strcoll in terms or strxfrm, but not the other way around. Each ordering rule is thus defined in terms of a string transformation. How the transformed strings sort determines the behavior of the ordering rule. So you want some flexible way to specify string transformations.
Perhaps you can see the quandary I faced. I want people to be able to specify a large assortment of ordering rules by adding text to a local file. That rules out writing a predetermined set of functions. Each may be very fast at enforcing a given ordering rule, but it is also limited. Choosing among a finite set of ordering rules is not a happy solution.