containerstr.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 CONTAINER_STR{ETP < $STR} < $TEXT
partial class CONTAINER_STR{ETP < $STR} < $TEXT is
-- This partial class implements routines for conversion to/from text
-- string representations (in the appropriate repertoire and encoding) of
-- a container class. Each element represented will be separated by some
-- indicated separator character.
-- Version 1.0 Nov 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 4 Nov 98 kh Original from Sather 1.2 dist.
private build(cursor : STR_CURSOR, sep : CHAR_CODE, start : CHAR, finish : CHAR ) : SAME
pre ~void(cursor)
and (cursor.remaining >= 2) -- the two end marks at least
and ~(start.code = CHAR_CODE::null)
and ~(finish.code = CHAR_CODE::null)
post ~void(result) or (cursor.index = initial(cursor.index))
is
-- This routine creates a new object from the string representation
-- indicated by the cursor, which is expected to be in a repertoire and
-- encoding specified by lib. The two given characters are expected to be
-- the starting and ending marks respectively.
loc_val : ETP ; -- for the typecase only!
typecase loc_val
when $TEXT then -- It has a text build routine!
cursor.skip_space ;
if cursor.item /= start then
return void
else
cursor.advance -- over the starter
end ;
res : FLIST{ETP} := FLIST{ETP}::create ;-- 'cos size not known yet!
loop
cursor.skip_space ;
if cursor.is_done or (cursor.item = finish) then break! end ;
if cursor.item = sep.char then
cursor.advance ;
cursor.skip_space
end ;
res := res.push(ETP::build(cursor))
end ;
return res.array
else
return void
end
end ;
build(cursor : STR_CURSOR, start, finish : CHAR ) : SAME
pre ~void(cursor)
and (cursor.remaining >= 2) -- the two end marks at least
and ~(start.code = CHAR_CODE::null)
and ~(finish.code = CHAR_CODE::null)
post true
is
-- This routine creates a new object from the string representation
-- indicated by the cursor, which is expected to be in the default repertoire
-- and encoding. The two given characters are expected to be the starting
-- and ending marks respectively.
loc_sep : CHAR_CODE ;
loc_lib : LIBCHARS := cursor.buffer.index_lib ;
if loc_lib.Decimal_Mark = loc_lib.Comma then
loc_sep := loc_lib.Fullstop
else
loc_sep := loc_lib.Comma
end ;
return build(cursor,loc_sep,start,finish)
end ;
build( cursor : STR_CURSOR) : SAME
pre ~void(cursor) and (cursor.remaining >= 2) -- the two end marks at least
post true
is
-- This routine creates a new object from the string representation
-- indicated by the cursor, which is expected to be in a repertoire and
-- encoding specified by lib. The default start/end marks are a left and
-- right brace respectively.
loc_sep : CHAR_CODE ;
loc_lib : LIBCHARS := cursor.buffer.index_lib ;
if loc_lib.Decimal_Mark = loc_lib.Comma then
loc_sep := loc_lib.Fullstop
else
loc_sep := loc_lib.Comma
end ;
return build(cursor,loc_sep,loc_lib.Left_Brace.char,loc_lib.Right_Brace.char)
end ;
create(str : STR, sep : CHAR ) : SAME
pre (str.size >= 2) -- the two end marks at least
post true
is
-- This routine creates a new object from the string representation
-- indicated by the cursor.
return build(str.cursor,sep.code,str[0],str[str.size - 1])
end ;
create( str : STR ) : SAME
pre (str.size >= 2) -- the two end marks at least
post true
is
-- This routine creates a new object from the string representation given
-- indicated by the cursor, which is expected to be in the default repertoire
-- and encoding. The separator defaults to either a comma or a fullstop -
-- whichever is NOT being used as a decimal mark.
loc_sep : CHAR_CODE ;
loc_lib : LIBCHARS := str.index_lib ;
if loc_lib.Decimal_Mark = loc_lib.Comma then
loc_sep := loc_lib.Fullstop
else
loc_sep := loc_lib.Comma
end ;
return build(str.cursor,loc_sep,str[0],str[str.size - 1])
end ;
str(lib : LIBCHARS, sep : CHAR ) : STR
pre ~void(lib)
post ~void(result) -- and it is a text representation of self.
is
-- This routine returns a string representation of the contents of self
-- in the given repertoire and encoding using either a comma or fullstop (and
-- space) to separate elements.
loc_str : STR := STR::create(lib) + sep + lib.Space.char ;
res : FSTR := FSTR::create(CODE_STR::create(lib.Left_Brace).tgt_str) ;
loop
elem_str : STR ;
loc_val : $OB := elt! ;
if void(loc_val) then
elem_str := lib.Asterisk.char.str
else
typecase loc_val
when $STR then
elem_str := loc_val.str(lib)
else
elem_str := STR::create(lib) + lib.Asterisk.char
end
end ;
res := res + loc_str.separate!(elem_str)
end ;
res := res + lib.Right_Brace.char ;
return res.str
end ;
str( lib : LIBCHARS ) : STR
pre ~void(lib)
post ~void(result) -- and it is a text representation of self.
is
-- This routine returns a string representation of the contents of self
-- in the given repertoire and encoding using either a comma or fullstop (and
-- space) to separate elements.
loc_sep : CHAR_CODE ;
if lib.Decimal_Mark = lib.Comma then
loc_sep := lib.Fullstop
else
loc_sep := lib.Comma
end ;
return str(lib,loc_sep.char)
end ;
str : STR is
-- This routine returns a string representation of the contents of self
-- in the default repertoire and encoding.
loc_sep : CHAR_CODE ;
loc_lib : LIBCHARS := LIBCHARS::default ;
if loc_lib.Decimal_Mark = loc_lib.Comma then loc_sep := loc_lib.Fullstop
else loc_sep := loc_lib.Comma
end ;
return str(loc_lib,loc_sep.char)
end ;
inspect:STR is
--This routine returns a string representation of the contents of self.
-- K.Kodama
res : STR := "[";
loop
elem_str : STR:="";
--index:$OB:=ind!;
--if void(index) then elem_str := "_";
--else
--typecase index
--when $STR then elem_str := index.str;
--else elem_str := "*"
--end
--end ;
--elem_str:=elem_str+"->";
loc_val : $OB := elt! ;
if void(loc_val) then elem_str := elem_str+"_";
else
typecase loc_val
when $STR then
elem_str := elem_str+loc_val.str;
else elem_str := elem_str+"*"
end;
end ;
res := res + ", "+ elem_str;
end ;
res := res + "]" ;
return res;
end ;
end ; -- CONTAINER_STR{ETP,CTP}