comp.lang.ada
 help / color / mirror / Atom feed
From: agent@drrob1.com
Subject: Re: trimming strings
Date: Sun, 03 Aug 2014 17:42:24 -0400
Date: 2014-08-03T17:42:24-04:00	[thread overview]
Message-ID: <2satt9tc4b1c6ldmqnmec3181jnfsuj7hp@4ax.com> (raw)
In-Reply-To: 55c718c7-b4cd-43c7-ae66-fef3e514a47c@googlegroups.com

On Sat, 2 Aug 2014 10:22:26 -0700 (PDT), mockturtle
<framefritti@gmail.com> wrote:

>On Saturday, August 2, 2014 3:10:16 PM UTC+2, ag...@drrob1.com wrote:
>> I am having a very difficult time understanding something.  I am
>> 
>> trying to do this using gnat on Ubuntu 14.04 system:
>> 
>> with Ada.Strings; use Ada.Strings;
>> with Ada.Strings.Fixed; use Ada.Strings.Fixed;
>> 
>> subtype string255fixedtype is string (1.255);
>> inbuf : string255fixedtype;
>> 
>> BEGIN
>> 
>>   inbuf := Get_Line;
>>   inbuf := trim(inbuf,both);  
>> 
>> --    this does not work, error is both is not visible
>> 
>> No combination of ada.strings.fixed.both, or ada.strings.both got it
>> to be visible.
>
>
>As others said, a complete example would help us to help you.  Anyway,  I am going to do  a wild guessing: did you maybe declared another "both" in your code?  I do not have a compiler at hand and I cannot check, but if I remember correctly in this case you get a "non visible" error because the two symbols hide each other.
>
>Riccardo


I am, after all, a newbie in Ada.  I was wondering what the
non-visible error meant, as I was getting that also.  Now I know it
means that identifiers are clashing in different packages.

I'm guessing that it is the use statements that make the symbols
clash?

I also don't have string processing down.  


> one of these being likely that an array of 255 characters
> is to receive a string object that may not have that many
> due to trimming.

> That's definitely an error (and assigning a string with a known length to Get_Line won't work either).  
> But those won't cause errors at compile time.  They will result in exceptions at run time.
>                                 -- Adam


with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters; use Ada.Characters;
with Ada.Characters.Conversions;  use Ada.Characters.Conversions;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
---------------------------

Procedure trimtest is
  Subtype String255FixedType is String(1..255); 

  str    : String255Fixedtype;
  STRLEN : Natural;
 
BEGIN
  Put(" Enter line: ");
  Get_Line(Str,StrLen);
  Str := TRIM(Str,Side => Both);
--  Str := Ada.Strings.Fixed.TRIM(str,side => Ada.Strings.both);
  Put_Line(" Line is: " & Str(1..StrLen) & " with length of " &
Natural'image(StrLen) );
End trimtest;

This simple procedure compiles, but does give me an exception at
run-time after I call trim.  I don't understand how to avoid this.  I
am used to more flexible strings that are null terminated.

How do I avoid a constraint_error exception at run-time?

Thanks

  reply	other threads:[~2014-08-03 21:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-02 13:10 trimming strings agent
2014-08-02 14:21 ` Pascal Obry
2014-08-02 15:27   ` G.B.
2014-08-02 17:00     ` Adam Beneschan
2014-08-02 17:22 ` mockturtle
2014-08-03 21:42   ` agent [this message]
2014-08-03 23:14     ` Georg Bauhaus
2014-08-04  0:17     ` Shark8
2014-08-04 10:06       ` mockturtle
2014-08-04 10:49         ` Pascal Obry
2014-08-04 11:51           ` Simon Clubley
2014-08-04 12:11             ` Pascal Obry
2014-08-04 16:50         ` Shark8
2014-08-04 23:28           ` Dennis Lee Bieber
2014-08-05 21:05             ` agent
replies disabled

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