name_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 SALUTATIONS < $ENUMS{SALUTATIONS}
immutable class SALUTATIONS < $ENUMS{SALUTATIONS} is
-- This class is an enumeration of all the salutation kinds given in
-- the LC_NAME component of a cultural description in ISO/IEC 14652.
--
-- The corresponding names in the common resources file
-- should be the ISO/IEC 14652 names specified for the indicated components.
--
-- 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 a name
-- 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{SALUTATIONS} ;
private const val_count : CARD := 5 ;
-- The following constant 'routines' specify the enumeration values.
Generic : SAME is return enum(1) end ;
Male : SAME is return enum(2) end ;
Married_Female : SAME is return enum(3) end ;
Unmarried_Female : SAME is return enum(4) end ;
Female : SAME is return enum(5) end ;
end ; -- SALUTATIONS
immutable class NAME_CODES < $ENUMS{NAME_CODES}
immutable class NAME_CODES < $ENUMS{NAME_CODES} 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{NAME_CODES} ;
private const val_count : CARD := 13 ;
-- The following constant 'routines' specify the enumeration values.
Family_Name : SAME is return enum(1) end ; -- f
UC_Family_Name : SAME is return enum(2) end ; -- F
First_Given_Name : SAME is return enum(3) end ; -- g
First_Given_Initial : SAME is return enum(4) end ; -- G
First_Given_Romanized : SAME is return enum(5) end ; -- l
Other_Short_Name : SAME is return enum(6) end ; -- o
Middle_Name : SAME is return enum(7) end ; -- m
Middle_Initial : SAME is return enum(8) end ; -- M
Profession : SAME is return enum(9) end ; -- p
Salutation_String : SAME is return enum(10) end ; -- s
Salutation_Code : SAME is return enum(11) end ; -- S
Conditional_Space : SAME is return enum(12) end ; -- t
Romanize_Prefix : SAME is return enum(13) end ; -- R
end ; -- NAME_CODES
class NAME_FMT < $BINARY
class NAME_FMT < $BINARY is
-- This class is the descriptor to be used when converting and
-- formatting a name 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
-- ---- ------ ------
-- 4 Mar 98 kh Original design from ISO/IEC 14652
-- 30 Oct 98 kh Refined, added pre/post conditions.
-- 5 Nov 99 kh Unified for ISO format I/O
include ISO_FORMAT{SAME,NAME_CODES} ;
private do_special(
code : NAME_CODES,
inout sep_str : CODE_STR,
out modifier : NAME_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 NAME_CODES::Romanize_Prefix then -- the only common component!
modifier := code ;
else -- an ordinary formatting code!
return false
end ;
return true
end ;
private do_format(
person : NAME,
lib : LIBCHARS
) : STR
pre ~void(self)
and ~void(person)
and ~void(lib)
post (result.size > 0) -- and is a properly formatted string.
is
-- This private routine does formatting for all of the variant routines
-- which follow.
res : STR := STR::create ;
prev : STR := STR::create ;
line : STR := STR::create + prefix ;
loop
case components.elt!
when NAME_CODES::Family_Name then
line := line + prev ;
prev := person.render(person.family_name,lib)
when NAME_CODES::UC_Family_Name then
line := line + prev ;
prev := person.render(person.family_name,lib).capitalize
when NAME_CODES::First_Given_Name then
line := line + prev ;
prev := person.render(person.first_name,lib)
when NAME_CODES::First_Given_Initial then
line := line + prev ;
prev := person.first(person.first_name,lib)
when NAME_CODES::First_Given_Romanized then
line := line + prev ;
prev := person.romanize(person.first_name,lib)
when NAME_CODES::Other_Short_Name then
line := line + prev ;
prev := person.render(person.other_names[0],lib)
when NAME_CODES::Middle_Name then
line := line + prev ;
prev := person.render(person.second_name,lib)
when NAME_CODES::Middle_Initial then
line := line + prev ;
prev := person.first(person.second_name,lib)
when NAME_CODES::Profession then
line := line + prev ;
prev := person.first(person.profession,lib)
when NAME_CODES::Salutation_String then
line := line + prev ;
prev := person.render(person.sal_string,lib,modified)
when NAME_CODES::Salutation_Code then
line := line + prev ;
prev := person.salutation.str(lib)
when NAME_CODES::Conditional_Space then
line := line + prev ;
if prev.size > 0 then
line := line + lib.Space
end
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 : NAME,
lib : LIBCHARS
) : STR
pre ~void(self)
and ~void(val)
and ~void(lib)
post ~void(result)
is
-- This routine produces a formatted version of the given name as a text
-- string representation.
return do_format(val,lib)
end ;
end ; -- NAME_FMT
class NAME_TITLE < $BINARY
class NAME_TITLE < $BINARY is
-- This class models a set of codes specified in the class SALUTATIONS
-- needed to construct a textual representation of a personal name.
-- Version 1.1 Oct 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 4 Mar 98 kh Original from ISO/IEC 14652
-- 30 Oct 98 kh Refined, added pre/post conditions
include BINARY ;
private attr map : ARRAY{CODE_STR} ; -- used because of the fixed size!
create : SAME is
-- This creation routine creates a new object with an 'empty' array.
me : SAME := new ;
me.map := ARRAY{CODE_STR}::create(SALUTATIONS::cardinality) ;
return me
end ;
build(
cursor : BIN_CURSOR,
lib : LIBCHARS
) : SAME
pre ~void(cursor)
and ~cursor.is_done
and ~void(lib)
post true
is
-- This routine creates a new object from the given binary string using
-- the given repertoire and encoding.
me : SAME := create ;
if cursor.item.card /= SALUTATIONS::cardinality then -- Error!
return void
else
cursor.advance
end ;
loop
loc_index : CARD := 0.upto!(SALUTATIONS::cardinality - 1) ;
loc_chunks : BINSTR := cursor.get_sized ;
if loc_chunks.size > 0 then
me.map[loc_index] := CODE_STR::build(loc_chunks.cursor,lib)
else
me.map[loc_index] := void
end ;
if cursor.is_done then -- not enough in the string
return void
end
end ;
return me
end ;
build(
cursor : BIN_CURSOR
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine creates a new object from the given binary string using
-- the default repertoire and encoding.
return build(cursor,LIBCHARS::default)
end ;
set(
elem : SALUTATIONS,
val : CODE_STR
) : SAME
pre ~void(self)
and ~void(elem)
post true
is
-- This routine sets the element of the map 'indexed' by elem.
map[elem.card - 1] := val ;
return self
end ;
get(
elem : SALUTATIONS
) : CODE_STR
pre ~void(self)
and ~elem.is_nil
post (result = map[elem.card - 1])
is
-- This routine returns the value of the string indexed by 'elem'.
return map[elem.card - 1]
end ;
binstr : BINSTR
pre ~void(self)
post (result.size > 0)
is
-- This routine returns the binary string representation of self.
loc_str : BINSTR := BINSTR::create(
OCTET::create(SALUTATIONS::cardinality)) ;
loop
elem : CODE_STR := map.elt! ;
if void(elem)
or (elem.size = 0) then
loc_str := loc_str + OCTET::null
else
loc_str := loc_str + elem.lib.culture.kind.binstr + elem.binstr
end
end ;
return loc_str
end ;
end ; -- NAME_TITLE
class NAMING < $BINARY
class NAMING < $BINARY is
-- This class contains the numeric components of the cultural
-- description as specified in ISO/IEC 14652 (as amended).
--
-- The two components actually come from two different segments of
-- the specification :-
--
-- format from the LC_NUMBER section
-- alternative digits - from the date/time section.
-- Version 1.1 Oct 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 26 Jun 98 kh Original design from cultural compiler
-- 30 Oct 98 kh Refined, added BINARY and pre/post conds.
include BINARY ;
readonly attr format : NAME_FMT ;
readonly attr titles : NAME_TITLE ;
build(
cursor : BIN_CURSOR,
lib : LIBCHARS
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine builds a new object from the current position in
-- the binary string, returning false only if out of data or some error
-- has occurred.
me : SAME := create ;
if BOOL::build(cursor) then
me.format := NAME_FMT::build(cursor,lib) ;
if void(me.format) then
return void
end
end ;
me.titles := NAME_TITLE::build(cursor,lib) ;
if void(me.titles) then
return void
else
return me
end
end ;
build(
cursor : BIN_CURSOR
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine builds a new object from the current position in
-- the binary string, returning false only if out of data or some error
-- has occurred.
return build(cursor,LIBCHARS::default)
end ;
create : SAME is
-- This routine creates an empty object
return new
end ;
create(
fmt : NAME_FMT,
tit : NAME_TITLE
) : SAME
pre ~void(fmt)
and ~void(tit)
post true
is
-- This routine creates a new object with the given compoenents,
me : SAME := new ;
me.format := fmt ;
me.titles := tit ;
return me
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 (result.size > 0)
is
-- This routine appends the contents of self as a binary string to
-- the given file.
return format.binstr + titles.binstr
end ;
end ; -- NAMING