From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx01.iad.POSTED!not-for-mail From: agent@drrob1.com Newsgroups: comp.lang.ada Subject: Re: trimming strings Message-ID: <2satt9tc4b1c6ldmqnmec3181jnfsuj7hp@4ax.com> References: <55c718c7-b4cd-43c7-ae66-fef3e514a47c@googlegroups.com> User-Agent: ForteAgent/7.20.32.1218 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@easynews.com Organization: Forte - www.forteinc.com X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Sun, 03 Aug 2014 17:42:24 -0400 X-Received-Bytes: 3546 X-Received-Body-CRC: 1804108903 Xref: news.eternal-september.org comp.lang.ada:21428 Date: 2014-08-03T17:42:24-04:00 List-Id: On Sat, 2 Aug 2014 10:22:26 -0700 (PDT), mockturtle 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