formatter.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>  <--------------


partial class ISO_FORMAT{T,COMP < $ENUMS{COMP}}

partial class ISO_FORMAT{T,COMP < $ENUMS{COMP}} is -- This class provides the common creation, etc facilities needed when -- making the group of format classes which may be described by a list of -- modifiers, components and separators. -- The special facilities needed by any particular formatting descriptor -- are contained in a routine for which the stub is given below. -- Version 1.0 Nov 99. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 5 Nov 99 kh Original from previous part implementation include BINARY ; private attr prefix : CODE_STR ; readonly attr modifiers : FLIST{COMP} ; -- Romanize or void readonly attr components : FLIST{COMP} ; readonly attr separators : FLIST{CODE_STR} ; private attr lib : LIBCHARS ; private stub do_special( code : COMP, inout sep_str : CODE_STR, out modifier : COMP, inout pushed : BOOL ) : BOOL ; -- 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. private create : SAME pre true post ~void(result) is -- This form of creation returns a new empty format object. me : SAME := new ; me.prefix := void ; return me end ; create( val : CODE_STR ) : SAME pre ~void(val) post ~void(result) is -- This routine is the creation routine used by the program which -- creates objects of this kind from their culture dependent source file -- descriptions. Note that the pre-condition on val does not imply that -- it necessarily has to have any elements! me : SAME := create ; me.lib := val.lib ; me.modifiers := FLIST{COMP}::create ; me.components := FLIST{COMP}::create ; me.separators := FLIST{CODE_STR}::create ; separator_next : BOOL := false ; -- ignore prefix here percent : CHAR_CODE := me.lib.Percent ; str : CODE_STR := CODE_STR::create(me.lib) ; finding_prefix : BOOL := true ; doing_escape : BOOL := false ; code_pushed : BOOL := false ; modifier : COMP := void ; -- usually! loop -- For prefix (if any)! item : CHAR_CODE := val.elt! ; if item = percent then if finding_prefix then -- So try to set one up finding_prefix := false ; if str.size > 0 then -- But only if something there! me.prefix := str ; str := CODE_STR::create(me.lib) end end ; if doing_escape then doing_escape := false ; str := str.push(item) else doing_escape := true end else if doing_escape then doing_escape := false ; loc_tmp : CODE_STR := CODE_STR::create(item) ; comp : COMP := COMP::create(loc_tmp.tgt_str) ; if me.do_special(comp,inout str,out modifier, inout code_pushed) then doing_escape := ~void(modifier) else -- just an ordinary code if code_pushed then me.separators := me.separators.push(str) ; str := CODE_STR::create(me.lib) end ; me.modifiers := me.modifiers.push(modifier) ; modifier := void ; me.components := me.components.push(comp) ; code_pushed := true end else str := str.push(item) end end end ; if finding_prefix then -- should never be this! me.prefix := str elsif code_pushed then -- needs pushing even if empty! me.separators := me.separators.push(str) end ; return me end ; build( index : BIN_CURSOR, lib : LIBCHARS ) : SAME pre ~void(index) and ~index.is_done and ~void(lib) post true is -- This routine reads its component values from the binary string -- indicated using the indicated repertoire and encoding and then returns -- the new address format object. me : T := create ; me.lib := lib ; if CODE_KINDS::build(index) /= lib.culture.kind then -- Can't continue - not understood return void end ; loc_binstr : BINSTR := index.get_sized ; if loc_binstr.size > 0 then me.prefix := CODE_STR::build(loc_binstr.cursor,lib) end ; loc_cnt : CARD := index.get_item.card ; -- loop control! if loc_cnt > 0 then me.modifiers := FLIST{COMP}::create ; me.components := FLIST{COMP}::create(loc_cnt) ; me.separators := FLIST{CODE_STR}::create(loc_cnt) ; loop loc_cnt.times! ; if index.is_done then -- too short! return void end ; me.modifiers := me.modifiers.push(COMP::build(index)) ; me.components := me.components.push(COMP::build(index)) ; loc_binstr := index.get_sized ; if loc_binstr.size > 0 then loc_sep : CODE_STR := CODE_STR::build(loc_binstr.cursor,me.lib) ; me.separators := me.separators.push(loc_sep) else me.separators := me.separators.push(void) end end end ; return me 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 using the default repertoire and encoding and then returns the -- new address format 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 ; binstr : BINSTR pre ~void(self) post true -- and it is a valid representation of self! is -- This routine produces a binary string representation of self in -- a form suitable for exporting/storage. res : BINSTR := BINSTR::create + lib.culture.kind.binstr ; if void(prefix) then res := res + OCTET::null else res := res + prefix.binstr.sized end ; res := res + OCTET::create(separators.size) ; -- loop counter! loop loc_comp : COMP := modifiers.elt! ; if void(loc_comp) then res := res + OCTET::null else res := res + loc_comp.binstr end ; res := res + components.elt!.binstr ; loc_sep : CODE_STR := separators.elt! ; if loc_sep.size = 0 then res := res + OCTET::null else res := res + loc_sep.binstr.sized end end ; return res end ; end ; -- ISO_FORMAT