The Standard ML Basis Library


The Locale structure

The Locale structure provides basic support for locale-dependent applications. In particular, it describes character sets and orderings on them, formats for monetary and numeric values, and special text formats for a given natural language. Note that locales are handled in an imperative fashion.

The semantics of the types and functions provided in Locale parallel those provided in the standard C libraries (cf. ANSI document X3.159-1989 or ISO/IEC [CITE]9899:1990/).


Synopsis

signature LOCALE
structure Locale : LOCALE

Interface

eqtype category
val collate : category
val ctype : category
val monetary : category
val numeric : category
val time : category
val messages : category
exception NoSuchLocale
val getCategory : category -> string
val setCategory : (category * string) -> unit
val setLocale : string -> unit
type locale_state
val saveLocale : unit -> locale_state
val restoreLocale : locale_state -> unit
datatype sign_posn  = PAREN  | PREC_ALL  | PREC_CUR  | FOLLOW_ALL  | FOLLOW_CURR
type lconv
val conventions : unit -> lconv
val decimalPoint : lconv -> char
val thousandsSep : lconv -> char option
val grouping : lconv -> int list
val currencySymbol : lconv -> string
val intCurrSymbol : lconv -> string
val monDecimalPoint : lconv -> char option
val monThousandsSep : lconv -> char option
val monGrouping : lconv -> int list
val positiveSign : lconv -> string
val negativeSign : lconv -> string
val intFracDigits : lconv -> int option
val fracDigits : lconv -> int option
val posCSPrecedes : lconv -> bool option
val posSepBySpace : lconv -> bool option
val negCSPrecedes : lconv -> bool option
val negSepBySpace : lconv -> bool option
val posSignPosn : lconv -> sign_posn option
val negSignPosn : lconv -> sign_posn option
exception NoSuchClass
eqtype char_class
val charClass : string -> char_class
val isClass : (WideChar.char * char_class) -> bool

Description

eqtype category

collate
the locale's collation mechanism. Affects the behavior of regular expressions and of some of the collate functions that perform string comparisons.

ctype
the locale's character classification and case conversion mechanism. Affects the behavior of regular expressions and of some of the character handling functions.

monetary
the locale's format for monetary quantities.

numeric
the locale's format for numeric values; used, e.g., by formatted IO.

time
the locale's format for time values.

messages
the locale's format for presenting text messages.

exception NoSuchLocale

getCategory c
returns the current locale for the category c of conventions.

setCategory (c, s)
setLocale s
sets the locale for the behavior category c to s. The second form sets the locale for all behavior categories to s. Raises NoSuchLocale if locale s is not supported.

The locale "SML" is the default SML locale, in which characters are 8 bits, character classification functions use ASCII ordering, etc. This locale is always supported. If s is the empty string, then the category is set in an implementation-specific manner. This usually involves reading the name of the locale from the environment. Other locales are optional.

The most common way to set the locale is to call setLocale "" at the beginning of a program. This may fail, in which case application programs typically print a warning message and continue execution in the default "SML" locale.

type locale_state

saveLocale ()
saves the current locale.

restoreLocale l
restores the current locale to the locale described by l.

datatype sign_posn
Values of type sign_posn are used to specify where the sign is placed in a monetary quantity.
PAREN
indicates that parentheses surround the quantity and currency symbol

PREC_ALL
indicates that the sign precedes the quantity and currency symbol

PREC_CUR
indicates that the sign immediately precedes the currency symbol

FOLLOW_ALL
indicates that the sign follows the quantity and currency symbol

FOLLOW_CURR
indicates that the sign immediately follows the currency symbol.

type lconv
used to describe a set of locale conventions. In the functions below, we slightly abuse our nomenclature by referring to values of type lconv as a locale.

conventions ()
returns the locale conventions corresponding to the current locale.

decimalPoint l
returns the character used for a decimal point in locale l.

Value in "SML" locale: #".".

thousandsSep l
returns SOME c where c is the character used in locale l to separate groups of digits in non-monetary quantities. Returns NONE if the locale does not have such a separator.

Value in "SML" locale: NONE.

grouping l
for the locale l, returns a list of integers describing the size of each group of digits (from right to left) in a non-monetary numeric format. Each group should be separated by the character thousandsSep l, if defined. A list element of 0 indicates that the previous value is to be used repeatedly for the remainder of the digits. The end of the list indicates that no further grouping is to be performed. In particular, an empty list indicates that no grouping is to be performed.

Value in "SML" locale: [].

currencySymbol l
returns a string containing the currency symbol of locale l.

Value in "SML" locale: "".

intCurrSymbol l
returns a string containing the international currency symbol of locale l. The format of the string is the same as that used in the int_curr_symbol field of the struct lconv value returned by the ISO C function localeconv.

Value in "SML" locale: "".

monDecimalPoint l
returns SOME c where c is the character used for a monetary decimal point in locale l; returns NONE if the locale does not have a monetary decimal point.

Value in "SML" locale: NONE.

monThousandsSep l
returns SOME c where c is the character used in locale l to separate groups of digits in monetary quantities. Returns NONE if the locale does not have such a separator.

Value in "SML" locale: NONE.

monGrouping l
for the locale l, returns a list of integers describing the size of each group of digits (from right to left) in a monetary numeric format. Each group should be separated by the character monThousandsSep l, if defined. A list element of 0 indicates that the previous value is to be used repeatedly for the remainder of the digits. The end of the list indicates that no further grouping is to be performed. In particular, an empty list indicates that no grouping is to be performed.

Value in "SML" locale: [].

positiveSign l
returns a string describing the formatting for a positive monetary value in locale l.

Value in "SML" locale: "".

negativeSign lc
returns a string describing the formatting for a negative monetary value in locale l.

Value in "SML" locale: "".

intFracDigits l
returns SOME i if locale l specifies the number of fractional digits i (those to the right of the decimal point) to be displayed in an internationally formatted monetary quantity.

Value in "SML" locale: NONE.

fracDigits l
returns SOME i if locale l specifies the number of fractional digits i (those to the right of the decimal point) to be displayed in an formatted monetary quantity.

Value in "SML" locale: NONE.

posCSPrecedes l
returns SOME b where b is true if and only if the currency symbol precedes, versus follows, the value for a nonnegative formatted monetary quantity in locale l; returns NONE if this is unspecified for locale l.

Value in "SML" locale: NONE.

posSepBySpace l
returns SOME b where b is true if and only if the currency symbol is separated by a space from the value for a nonnegative formatted monetary quantity in locale l; returns NONE if this is unspecified for locale l.

Value in "SML" locale: NONE.

negCSPrecedes l
returns SOME b where b is true if and only if the currency symbol precedes, versus follows, the value for a negative formatted monetary quantity in locale l; returns NONE if this is unspecified for locale l.

Value in "SML" locale: NONE.

negSepBySpace l
returns SOME b where b is true if and only if the currency symbol is separated by a space from the value for a negative formatted monetary quantity in locale l; returns NONE if this is unspecified for locale l.

Value in "SML" locale: NONE.

posSignPosn l
returns SOME p where p is the position of the positive sign for a nonnegative formatted monetary quantity for locale l; returns NONE if this is unspecified for locale l.

Value in "SML" locale: NONE.

negSignPosn l
returns SOME p where p is the position of the negative sign for a negative formatted monetary quantity for locale l; returns NONE if this is unspecified for locale l.

Value in "SML" locale: NONE.

exception NoSuchClass

eqtype char_class

charClass s
returns a char_class value corresponding to the given name s in the current locale. Raises NoSuchClass if the class is not supported in the current locale.

A char_class value must encapsulate information concerning the current locale, so that its use in isClass is independent of any change to the global current locale.

The standard classes "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower", "print", "punct", "space", "upper" and "xdigit" are always provided.

isClass (c, cc)
returns true if c is in the locale-dependent character class denoted by cc.

For the standard character classes (except "blank"), isClass is equivalent to the specific form described in CHAR, e.g., isClass(c, charClass "alpha") is the same as WideChar.isAlpha c.

Question:

This function should be moved somewhere else.




See Also

MultiByte, WideChar, WideSubstring

[ INDEX | TOP | Parent | Root ]

Last Modified January 21, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies