address_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 ADDRESS_CODES < $ENUMS{ADDRESS_CODES}
immutable class ADDRESS_CODES < $ENUMS{ADDRESS_CODES} is
-- This class is an enumeration of all the address component
-- format values which are defined in the LC_ADDRESS component of the ISO/IEC
-- standard 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. The prefix letter for some of these codes have the
-- following meanings
--
-- R - Use a Romanized version for the text (based on a transliteration.
-- Version 1.0 Feb 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 20 Feb 98 kh Original from ISO/IEC 14652
include EXACT_ENUM{ADDRESS_CODES} ;
private const val_count : CARD := 15 ;
-- The following constant 'routines' specify the enumeration values.
Care_of : SAME is return enum(1) end ; -- a
Building : SAME is return enum(2) end ; -- b
Country : SAME is return enum(3) end ; -- c
Country_Code : SAME is return enum(4) end ; -- C
Department : SAME is return enum(5) end ; -- d
Floor_Num : SAME is return enum(6) end ; -- e
Organisation : SAME is return enum(7) end ; -- f
House_Num : SAME is return enum(8) end ; -- h
Conditional_EOL : SAME is return enum(9) end ; -- N
Room_Num : SAME is return enum(10) end ; -- r
Street : SAME is return enum(11) end ; -- s
Conditional_Space : SAME is return enum(12) end ;-- t
Town : SAME is return enum(13) end ; -- T
Post_Code : SAME is return enum(14) end ; -- z
Romanize_Prefix : SAME is return enum(15) end ; -- R
end ; -- ADDRESS_CODES
class ADDRESS_FMT
class ADDRESS_FMT is
-- This class is the descriptor to be used when converting and
-- formatting an address 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.2 Nov 99. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 20 Feb 98 kh Original design from ISO/IEC 14652
-- 15 Jul 98 kh Revised with pre/post conditions
-- 5 Nov 99 kh Revised for generic ISO I/O.
include ISO_FORMAT{SAME,ADDRESS_CODES} ;
private do_special(
code : ADDRESS_CODES,
inout sep_str : CODE_STR,
out modifier : ADDRESS_CODES,
inout pushed : BOOL
) : BOOL is
-- This routine returns true if and only if the code argument has resulted
-- in any special action being taken, otherwise nothing has been done and
-- the creation routine below sets the appropriate list components.
modifier := void ;
case code
when ADDRESS_CODES::Romanize_Prefix then -- the only common component!
modifier := code ;
else -- an ordinary formatting code!
return false
end ;
return true
end ;
private do_format(
place : ADDRESS,
lib : LIBCHARS
) : STR
pre ~void(self)
and ~void(place)
and ~void(lib)
post ~void(result)
-- and result is a textual representation of place as specified
-- by this object.
is
-- This private routine does formatting for all of the variant routines
-- which follow. It relies on the routine render in the ADDRESS class to
-- determine any Romanization necessary when applicable
res : STR := STR::create ;
prev : STR := STR::create ;
line : STR := STR::create + prefix ;
loop
modified : BOOL := ~void(modifiers.elt!) ;
case components.elt!
when ADDRESS_CODES::Care_of then
line := line + prev ;
prev := place.render(place.care_of,modified)
when ADDRESS_CODES::Building then
line := line + prev ;
prev := place.render(place.building,modified)
when ADDRESS_CODES::Country then
line := line + prev ;
prev := place.render(place.country,modified)
when ADDRESS_CODES::Country_Code then
line := line + prev ;
prev := place.render(place.country_CEPT,modified)
when ADDRESS_CODES::Department then
line := line + prev ;
prev := place.render(place.dept,modified)
when ADDRESS_CODES::Floor_Num then
line := line + prev ;
prev := place.render(place.floor.runes(lib),modified)
when ADDRESS_CODES::Organisation then
line := line + prev ;
prev := place.render(place.organisation,modified)
when ADDRESS_CODES::House_Number then
line := line + prev ;
prev := place.render(place.house,modified)
when ADDRESS_CODES::Conditional_EOL then
line := line + prev ;
prev := STR::create ;
if line.size > 0 then
res := res + line + lib.Line_Mark.char ;
line := STR::create
end
when ADDRESS_CODES::Room_Num then
line := line + prev ;
prev := place.render(place.room,modified)
when ADDRESS_CODES::Street then
line := line + prev ;
prev := place.render(place.street,modified)
when ADDRESS_CODES::Conditional_Space then
line := line + prev ;
if prev.size > 0 then
line := line + lib.Space.char
end
when ADDRESS_CODES::Town then
line := line + prev ;
prev := place.render(place.town,modified)
when ADDRESS_CODES::Post_Code then
line := line + prev ;
prev := place.render(place.post_code,modified)
-- when ADDRESS_CODES::Romanize_Prefix then -- done on creation
else -- error in cultural spec!
SYS_ERROR::create.error(self,SYS_EXCEPT::Bad_Format,
res + line + prev)
end
end ;
return res + line + prev
end ;
fmt(
val : ADDRESS,
lib : LIBCHARS
) : STR
pre ~void(val)
and ~void(self)
and ~void(lib)
post result.size > 0
is
-- This routine produces a formatted version of the given date as a text
-- string representation.
return do_format(val,lib)
end ;
end ; -- ADDRESS_FMT
immutable class ADDRESS_KEYS < $ENUMS{ADDRESS_KEYS}
immutable class ADDRESS_KEYS < $ENUMS{ADDRESS_KEYS} is
-- This immutable class is the enumeration over the address section
-- keywords of a standard locale source file.
--
-- The corresponding names in the culture-independent resources file
-- are prescribed by the ISO/IEC standard 14652. There is, however,
-- nothing to state that culture-dependent versions could not be used
-- additionally! The names are --
--
-- postal_fmt, country_name, country_post, country_ab2, country_ab3,
-- country_num. country_car, country_isbn, lang_name, lang_ab,
-- lang_term, lang_lib
-- Version 1.0 Feb 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 19 Feb 98 kh Original from ISO/IEC 14652
include EXACT_ENUM{ADDRESS_KEYS}
val_count -> ;
private const val_count : CARD := 12 ;
-- The following constant 'routines' specify the enumeration values.
Postal_Format : SAME is return enum(1) end ;
Country_Name : SAME is return enum(2) end ;
CEPT_Abbreviation : SAME is return enum(3) end ;
Two_Letter_Abbreviation : SAME is return enum(4) end ;
Three_Letter_Abbreviation : SAME is return enum(5) end ;
ISO3166_Number : SAME is return enum(6) end ;
Geneva_Car_Code : SAME is return enum(7) end ;
Country_ISBN : SAME is return enum(8) end ;
Language_Name : SAME is return enum(9) end ;
ISO639_Abbreviation : SAME is return enum(10) end ;
ISO639_Term : SAME is return enum(11) end ;
ISO639_Library_Name : SAME is return enum(12) end ;
end ; -- ADDRESS_KEYS
class ADDRESSING < $BINARY
class ADDRESSING < $BINARY is
-- This class contains the components of the cultural specification in
-- ISO/IEC 14652 devoted to postal addressing and related data values.
-- Version 1.1 Aug 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 26 Jun 98 kh Original design from cultural compiler
-- 19 Aug 98 kh Modified to sub-type from $BINARY
include BINARY ;
readonly attr format : ADDRESS_FMT ;
readonly attr data : FMAP{ADDRESS_KEYS,CODE_STR} ;
build(
cursor : BIN_CURSOR,
lib : LIBCHARS
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine attempts to build an object from the binary string
-- indicated by the cursor parameter.
res : SAME := new;
res.format := ADDRESS_FMT::build(cursor,lib) ;
if cursor.is_done
or void(res.format) then
return void
end ;
loc_error_free : BOOL := true ;
loc_cnt : CARD := cursor.get_item.card ;
if loc_cnt > 0 then
res.data := FMAP{ADDRESS_KEYS,CODE_STR}::create ;
loop
loc_cnt.times! ;
if cursor.is_done then -- premature end of input!
loc_error_free := false ;
break!
end ;
key : ADDRESS_KEYS := ADDRESS_KEYS::build(cursor) ;
loc_chunks : BINSTR := cursor.get_sized ;
if loc_chunks.size > 0 then
loc_str : CODE_STR := CODE_STR::build(
loc_chunks.cursor,lib) ;
res.data := res.data.insert(key,loc_str)
else
res.data := res.data.insert(key,void)
end
end
end ;
if loc_error_free then
return res
else
return void
end
end ;
build(
cursor : BIN_CURSOR
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine attempts to build an object from the binary string
-- indicated by the cursor parameter.
return build(cursor,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 ;
binstr : BINSTR
pre ~void(self)
post ~void(result)
-- and a representation of self is contained in it
is
-- This routine produces a binary string form of self suitable for
-- appending to a file.
res : BINSTR := format.binstr ;
res := res + OCTET::create(data.size) ;
if data.size > 0 then
loop
key : ADDRESS_KEYS := data.keys! ;
str : CODE_STR := data.get(key) ;
res := res + key.binstr + str.binstr
end
end ;
return res
end ;
end ; -- ADDRESSING