comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Some problems with string type(Exact String?)
Date: Wed, 06 Jun 2001 21:30:04 GMT
Date: 2001-06-06T21:30:04+00:00	[thread overview]
Message-ID: <whxT6.68591$%i7.51923767@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: lowT6.40598$DG1.6446489@news1.rdc1.mi.home.com

>not greater than the bounds of the array.  My first hunch on the way to
>work with this strictness(or so it seems) would be keep count of the
>number of elements (characters of a string, numbers, whatever) going into
>the array, and then pad the rest of the array with with NULLs or something
  In Barnes, look at the chapter "Predefined Library", section "Characters
and strings" and you'll see Ada.Strings.Bounded (and Ada.Strings.Unbounded).
Bounded strings essentially keep a "current length", along with the fixed
length array.  There's no need then to pad with nulls or anything else.

  Alternatively, you could change
>       i.nameindex:=s; -- Ligne cinq
to
  if s'length > i.nameindex'lenth then    -- just take the first part
    i.nameindex := s(s'first .. s'first-1+i.nameindex'length)
  else  -- pad with blanks
    i.nameindex := s & (s'length+1 .. i.nameindex'length => ' ');
  end if;

or
  i.nameindex := s(s'first .. integer'min(s'length, i.nameindex'length)
                              + s'first -1)
                 & (1 .. i.namelength'length - s'length => ' ');
which would truncate if s is too long, and pad with ' ' if s is too short.

or, more simply,
  i.nameindex := Ada.Strings.Fixed.Head(s, i.namelength'length, pad => ' ');



  reply	other threads:[~2001-06-06 21:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-07  2:18 Some problems with string type Valdes
2001-06-06 16:34 ` Philip Anderson
2001-06-06 20:29   ` Some problems with string type(Exact String?) McDoobie
2001-06-06 21:30     ` tmoran [this message]
2001-06-07  8:07       ` Jean-Pierre Rosen
2001-06-06 22:08     ` Marin David Condic
2001-06-07  6:48     ` Ada.Strings.Fixed procedure Move Petter Fryklund
2001-06-07  4:06   ` Some problems with string type Valdes
2001-06-07 13:20     ` Valdes Laurent
2001-06-06 17:49 ` tmoran
2001-06-07  4:07   ` Valdes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox