comp.lang.ada
 help / color / mirror / Atom feed
From: rracine@myremarq.com (Roger Racine)
Subject: Re: CONTRAINT ERROR (was Re: parsing a string)
Date: 2000/01/26
Date: 2000-01-26T13:36:54+00:00	[thread overview]
Message-ID: <388ef706.1991756564@news.draper.com> (raw)
In-Reply-To: 86mm2o$3cd$1@nnrp1.deja.com

On Wed, 26 Jan 2000 11:33:44 GMT, pumilia@est.it wrote:

>In article <uu2k3kszb.fsf@gsfc.nasa.gov>,
>  Stephen Leake <Stephen.Leake@gsfc.nasa.gov> wrote:
>
>> Index is a function, which must be assigned to a value, so this can't
>> be the real source. Please include your _complete_ test program, so we
>> can compile it ourselves, to help get a good answer.
>>
>> The default for Map should be fine. You can find out what else you
>> might pass for Map in the package Ada.Strings.Maps.
>>
>> -- Stephe
>>
>
>Ok, i simplified my program, adjusted something thanks to David Hoos's
>and
>your useful comments and found a new error: CONSTRAINT_ERROR.
>
>Here is my test procedure, aimed to converting an unbounded string
>to string and then to parse the string:
>
>-- str2_test --------------------------------------
>with   ada.strings.unbounded;
>use    ada.strings.unbounded;
>with    ustrings;
>use      ustrings;
>with   text_io;
>with   Ada.Integer_Text_IO;
>use    text_io;
>with ada.strings.fixed; use ada.strings.fixed;
>
>with Ada.Integer_Text_IO;
>use Ada.Integer_Text_IO;
>
>procedure str2_test is
>
> output_file_string : unbounded_string ;
> output_file : string (1..25) ;
> pos1 : natural;
>
>Begin
>
>    get_line(output_file_string);
>
>   put(" output:  "); put(output_file_string); put("<--"); new_line;
>   output_file :=  to_string(output_file_string);
>   put(" Output:  "); put(output_file); put("<--"); new_line;
>   put(" index:  "); pos1 := Index(output_file,"xxx");
>   put(pos1);
>   new_line;
>
>end str2_test;
>-- str2_test --------------------------------------
>
>
>While executing i get the error:
>
>>   raised constraint_error : str2_test.adb:24
>
>This is line 24:
>
>  output_file :=  to_string(output_file_string);
>
>
>Any help wil be appreciiated
>thank you
>Pol
>
>- ustrings.ads ---------------------------------
>-- Ideally this would be a child package of "Ada.Strings.Unbounded".
>
>-- package Ustrings is
>--   procedure Get_Line(Item : out Unbounded_String);
>--   procedure Put(Item : in Unbounded_String);
>--   procedure Put_Line(Item : in Unbounded_String);
>-- end Ustrings;
>--
>-- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
>-- Author: David A. Wheeler
>--
>

The unbounded string Output_File_String can be of any length.  The
string Output_File is exactly 25 characters.  The following will help:

  Ulength : Natural;
...
   ULength := Length (Output_File_String);
   if ULength > Output_file'Length then
-- Do something to make sure bad input is caught

      raise Constraint_Error;  

   else

   Output_File(1 .. ULength) :=  to_string(output_file_string);
...
end if;

Roger Racine





  reply	other threads:[~2000-01-26  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-15  0:00 parsing a string Paolo M. Pumilia
2000-01-15  0:00 ` James S. Rogers
2000-01-24  0:00   ` pumilia
2000-01-24  0:00     ` Ehud Lamm
2000-01-24  0:00     ` Stephen Leake
2000-01-26  0:00       ` CONTRAINT ERROR (was Re: parsing a string) pumilia
2000-01-26  0:00         ` Roger Racine [this message]
2000-01-26  0:00           ` Fraser
2000-01-26  0:00             ` Simon Wright
2000-01-26  0:00         ` John English
2000-01-26  0:00         ` Ian Clifton
2000-01-24  0:00   ` parsing a string pumilia
replies disabled

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