Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

All Sorts of Sorts


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

Table 1: Locale entry for Australia.

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.