strstr.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 STR_STR < $TEXT, $ANCHORED_FMT
partial class STR_STR < $TEXT, $ANCHORED_FMT is
-- This partial class provides formatting services for the class STR.
-- Version 1.0 Sep 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 22 Sep 98 kh Original from revised CHAR class
is_str(
str : STR
) : CONVERSION_RESULTS
pre ~void(str.index_lib)
post (result = CONVERSION_RESULTS::All_Right)
or (result = CONVERSION_RESULTS::Empty)
is
-- This routine checks that the given string is a string! It returns
-- the relevant result state.
if str.size = 0 then
return CONVERSION_RESULTS::Empty
else
return CONVERSION_RESULTS::All_Right
end ;
end ;
build(
loc_cursor : STR_CURSOR
) : SAME
pre ~void(loc_cursor)
and ~loc_cursor.is_done
and ~void(index_lib)
post true
is
-- This routine creates returns a copy of the string indicated by
-- the cursor.
return loc_cursor.get_remainder
end ;
create(
str : STR
) : SAME
pre ~void(str)
post true
is
-- This is the creation routine from a string which is any of the
-- abbreviations listed in the Name table. If the name table has not been
-- read in this is done first.
return str.copy
end ;
str(
lib : LIBCHARS
) : STR
pre ~void(lib)
post result.size = size -- and the same in a different encoding!
is
-- This routine just returns the string formed by converting from self
-- in the encoding given.
res : SAME := convert(lib) ;
res.priv_lib := REP_LIB_LIST::index(lib) ;
return res
end ;
str : STR
pre ~void(self)
post true -- (result = self)
is
-- This routine just returns a copy of self. It is provided for
-- consistency with other classes.
return copy
end ;
fmt(
format : ANCHORED_DESCR,
lib : LIBCHARS
) : STR
pre ~void(self)
and ~void(format)
and (format.width > 0)
and ~void(lib)
post ~void(result)
is
-- This routine returns self in accordance with the formatting
-- instructions given in format. Note that the library of characters is
-- not used. It is retained for commonality of syntax.
res : STR ;
if format.leading > size then
res := STR::create(format.filler.char,lib).repeat(
format.leading - size)
else
res := STR::create(lib)
end ;
return res + self + STR::create(format.filler.char,lib).repeat(
format.trailing)
end ;
fmt(
format : ANCHORED_DESCR
) : STR
pre ~void(self)
and ~void(format)
and (format.width > 0)
post ~void(result)
is
-- This routine returns self in accordance with the formatting
-- instructions given in format.
return fmt(format,LIBCHARS::default)
end ;
end ; -- STR_STR