eradatestr.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 ERADATE_STR < $TEXT, $ANCHORED_FMT
partial class ERADATE_STR < $TEXT, $ANCHORED_FMT is
-- This partial class implements numeric date conversion routines,
-- to and from character strings.
-- NOTE This version is a dummy until overseas cultural help is available.
-- Version 1.0 Feb 99. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 1 Feb 99 kh Original from DATE_STR
is_date(
str : STR
) : CONVERSION_RESULTS
pre ~void(str)
post (result = CONVERSION_RESULTS::All_Right)
or (result = CONVERSION_RESULTS::Out_of_Range)
or (result = CONVERSION_RESULTS::Bad_Format)
or (result = CONVERSION_RESULTS::Empty)
is
-- This routine checks that the format of of the leading characters of
-- the given string in the given repertoire and encoding corresponds to that
-- required for a real number, returning the relevant result state.
return CONVERSION_RESULTS::Bad_Format
end ;
build(
loc_cursor : STR_CURSOR
) : SAME
pre ~void(loc_cursor)
and ~loc_cursor.is_done
post ((result.count = 0)
and (initial(loc_cursor.index) = loc_cursor.index))
or (initial(loc_cursor.index) < loc_cursor.index)
is
-- This routine creates the date contained in the string indicated. If
-- the string does not contain a valid date then zero is returned and the
-- cursor has not been moved!
return from_days(0)
end ;
create(
str : STR
) : SAME
pre (is_date(str) = CONVERSION_RESULTS::All_Right)
post true
is
-- This routine creates the whole number corresponding to the textual
-- representation contained in str in the given repertoire and encoding.
return build(str.cursor)
end ;
str(
lib : LIBCHARS
) : STR is
-- This routine returns the date as a string representation using the
-- culture-defined formatting information.
return void
-- return lib.culture.date_time.date.fmt(self,lib)
end ;
str : STR is
-- This routine returns the date as a string representation using the
-- culture-dependent default formatting information.
return str(LIBCHARS::default)
end ;
fmt(
format : ANCHORED_DESCR,
lib : LIBCHARS
) : STR
pre ~void(format)
and ~void(lib)
post result.size > 0
is
-- This routine returns a formatted representation of self in the given
-- repertoire and encoding as dictated by the given format description.
res : STR := str(lib) ;
loc_fill : STR := STR::create(lib) + format.filler.char ;
if res.size < format.leading then -- needs a filler
res := loc_fill.repeat(format.width - res.size) + res
end ;
if format.trailing > 0 then
return res + loc_fill.repeat(format.trailing)
else
return res
end
end ;
fmt(
format : ANCHORED_DESCR
) : STR
pre ~void(format)
post result.size > 0
is
-- This routine returns a formatted representation of self in the default
-- repertoire and encoding as dictated by the given format description.
return fmt(format,LIBCHARS::default)
end ;
end ; -- ERADATE_STR