version_culture.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
immutable class CATEGORIES < $ENUMS{CATEGORIES}
immutable class CATEGORIES < $ENUMS{CATEGORIES} is
-- This immutable class is the enumeration over the sections of
-- a standard locale source file.
--
-- The corresponding names in the culture-independent resources file
-- are prescribed by the ISO/IEC standard 9945-2. There is, however,
-- nothing to state that culture-dependent versions could not be used
-- additionally! The names are --
--
-- LC_CTYPE, LC_COLLATE, LC_NUMERIC, LC_MONETARY, LC_TIME,
-- LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE,
-- LC_MEASUREMENT, LC_VERSIONS, END
-- Version 1.0 May 97. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 8 May 97 kh Original from ISO/IEC 9945-2
include ENUM{CATEGORIES} ;
private const val_count : CARD := 12 ;
-- The following constant 'routines' specify the enumeration values.
Char_Type : SAME is return enum(1) end ;
Collation : SAME is return enum(2) end ;
Numeric : SAME is return enum(3) end ;
Monetary : SAME is return enum(4) end ;
Time : SAME is return enum(5) end ;
Messages : SAME is return enum(6) end ;
Paper : SAME is return enum(7) end ;
Name : SAME is return enum(8) end ;
Address : SAME is return enum(9) end ;
Telephone : SAME is return enum(10) end ;
Measurement : SAME is return enum(11) end ;
Versions : SAME is return enum(12) end ;
end ; -- CATEGORIES
immutable class VERSION_KEYS < $ENUMS{VERSION_KEYS}
immutable class VERSION_KEYS < $ENUMS{VERSION_KEYS} is
-- This class is an enumeration of all the version component values
-- which are defined in the LC_VERSIONS component of ISO/IEC 14652.
--
-- The corresponding names in the common resources file
-- should be the ISO/IEC 14652 names specified for the indicated formats.
--
-- The table in ISO/IEC 14652 gives the text string format codes and
-- a description of the semantics to be ascribed to that code in an address
-- formatting class.
-- NOTE Date and Category values are at the end of this enumeration for
-- convenience in use since they are not merely string values.
-- Version 1.0 Mar 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 4 Mar 98 kh Original from ISO/IEC 14652
include EXACT_ENUM{VERSION_KEYS} ;
private const val_count : CARD := 15 ;
-- The following constant 'routines' specify the enumeration values.
Title : SAME is return enum(1) end ;
Source : SAME is return enum(2) end ;
Postal_Address : SAME is return enum(3) end ;
Contact : SAME is return enum(4) end ;
E_mail : SAME is return enum(5) end ;
Phone_Number : SAME is return enum(6) end ;
Fax_Number : SAME is return enum(7) end ;
Language : SAME is return enum(8) end ;
Territory : SAME is return enum(9) end ;
Audience : SAME is return enum(10) end ;
Application : SAME is return enum(11) end ;
Abbreviation : SAME is return enum(12) end ;
Revision : SAME is return enum(13) end ;
Date : SAME is return enum(14) end ;
Category : SAME is return enum(15) end ;
end ; -- VERSION_KEYS
immutable class CAT_STANDARDS < $ENUMS{CAT_STANDARDS}
immutable class CAT_STANDARDS < $ENUMS{CAT_STANDARDS} is
-- This class is an enumeration of all the name component format values
-- which are defined in the LC_ADDRESS component of ISO/IEC 14652.
--
-- The corresponding names in the common resources file
-- should be the ISO/IEC 14652 names specified for the indicated formats.
--
-- The table in ISO/IEC 14652 gives the text string format codes and
-- a description of the semantics to be ascribed to that code in an address
-- formatting class.
-- Version 1.0 Mar 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 4 Mar 98 kh Original from ISO/IEC 14652
include EXACT_ENUM{CAT_STANDARDS} ;
private const val_count : CARD := 2 ;
-- The following constant 'routines' specify the enumeration values.
ISO_14652 : SAME is return enum(1) end ;
Posix : SAME is return enum(2) end ;
end ; -- CAT_STANDARDS
class VERSION < $BINARY
class VERSION < $BINARY is
-- This class is the descriptor to be used when converting and
-- formatting a telephone number value into a textual representation.
-- The format descriptor provides for an optional prefix string and then
-- pairs of component/string pairs for as many components as needed. Any of
-- the 'component' strings may be empty where two or more value components
-- are to be formatted adjacent to each other (without any space!).
-- Version 1.0 Mar 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 4 Mar 98 kh Original design from ISO/IEC 14652
include BINARY ;
private const Non_Strings : CARD := 2 ; -- see VERSION_KEYS class!
private attr strings : ARRAY{STR} ;
private attr cat_specs : ARRAY{CAT_STANDARDS} ;
readonly attr date : DATES ;
private attr lib : LIBCHARS ; -- for export!
create(lib : LIBCHARS) : SAME
pre ~void(lib)
post (result.lib = lib)
and void(result.date)
and ~void(result.strings)
and ~void(result.cat_specs)
is
-- This routine is the creation routine used by the program which
-- creates objects of this kind from their culture dependent source file
-- descriptions. It returns an empty object.
me : SAME := new ;
me.lib := lib ;
me.strings := ARRAY{STR}::create(VERSION_KEYS::cardinality - Non_Strings) ;
me.cat_specs := ARRAY{CAT_STANDARDS}::create(CATEGORIES::cardinality) ;
me.date := void ;
return me
end ;
build(index : BIN_CURSOR,lib : LIBCHARS) : SAME
pre ~void(index)
and ~void(lib)
and ~index.is_done
post true
is
-- This routine reads its component values from the binary string
-- indicated and then returns the new version object.
me : SAME := new ;
loc_kind : CODE_KINDS := CODE_KINDS::build(index) ;
if loc_kind /= lib.culture.kind then
return void
end ;
me.lib := lib ;
cnt : CARD := index.get_item.card ;
if cnt /= (VERSION_KEYS::cardinality - Non_Strings) then
return void
else
me.strings := ARRAY{STR}::create(VERSION_KEYS::cardinality - Non_Strings) ;
loop
loc_cnt : CARD := 0.upto!(cnt - 1) ;
if index.is_done then -- Oops! run off the end!
return void
end ;
loc_binstr : BINSTR := index.get_sized ;
if loc_binstr.size > 0 then
me.strings[loc_cnt] := STR::build(loc_binstr.cursor,lib)
else
me.strings[loc_cnt] := void
end
end
end ;
cnt := index.get_item.card ;
if cnt = CATEGORIES::cardinality then
me.cat_specs := ARRAY{CAT_STANDARDS}::create(CATEGORIES::cardinality) ;
loop
loc_index : CARD := 0.upto!(CATEGORIES::cardinality - 1) ;
if index.is_done then -- Oops! run off the end!
return void
end ;
me.cat_specs[loc_index] := CAT_STANDARDS::build(index)
end
else
return void
end ;
me.date := DATES::build(index) ;
if void(me.date) then
return void
else
return me
end
end ;
build(index : BIN_CURSOR) : SAME
pre ~void(index) and ~index.is_done
post true
is
-- This routine reads its component values from the binary string
-- indicated and then returns the new version object.
return build(index,LIBCHARS::default)
end ;
read(index : BIN_CURSOR,lib : LIBCHARS) : SAME
pre ~void(index) and ~index.is_done
post true
is
-- This routine assumes that the next octet in the binary string
-- represents a boolean value. If this value is true then the appropriate
-- number of octets is used to build and return a new object. The use of
-- lib is provided in case the object being built needs conversion of
-- binary data to some textual form.
if BOOL::build(index) then
return build(index,lib)
else
return void
end
end ;
set(elem : VERSION_KEYS,str : STR) : SAME
pre ~void(self) and ~void(elem)
post result.strings[elem.card - 1] = str
is
-- This routine sets an individual value indexed by elem.
case elem
when VERSION_KEYS::Date,
VERSION_KEYS::Category then -- invalid string entries!!
return void
else
strings[elem.card - 1] := str ;
return self
end
end ;
set_date(day : DATES) : SAME
pre ~void(self) and ~void(day)
post result.date = day
is
-- This routine sets the date component of this version object.
date := day ;
return self
end ;
set_cat_spec(cat : CATEGORIES,val : CAT_STANDARDS) : SAME
pre ~void(self)
and ~void(cat)
and ~void(val)
post result.cat_specs[cat.card - 1] = val
is
-- This routine sets the standard to which the given category is specified.
cat_specs[cat.card - 1] := val ;
return self
end ;
get(elem : VERSION_KEYS) : STR
pre ~void(self) and ~void(elem)
post strings[elem.card - 1] = result
is
-- This routine returns the individual value indexed by elem.
case elem
when VERSION_KEYS::Date,
VERSION_KEYS::Category then -- invalid string entries!!
return void
else
return strings[elem.card - 1]
end
end ;
get_cat_spec(cat : CATEGORIES) : CAT_STANDARDS
pre ~void(self) and ~void(cat)
post cat_specs[cat.card - 1] = result
is
-- This routine returns the standard to which the given category is specified.
return cat_specs[cat.card - 1]
end ;
binstr : BINSTR
pre ~void(self)
post result.size > 0
is
-- This routine produces a binary string representation of self in
-- the target repertoire and encoding.
loc_str : BINSTR :=
BINSTR::create(OCTET::create(VERSION_KEYS::cardinality - Non_Strings)) ;
-- only one octet needed.
loop -- over the components
loc_str := loc_str + strings.elt!.binstr.sized
end ;
loop
loc_str := loc_str + cat_specs.elt!.binstr
end ;
loc_str := loc_str + date.binstr ;
return loc_str
end ;
end ; -- VERSION