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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,564a91823edb719c X-Google-Attributes: gid103376,public From: rracine@myremarq.com (Roger Racine) Subject: Re: CONTRAINT ERROR (was Re: parsing a string) Date: 2000/01/26 Message-ID: <388ef706.1991756564@news.draper.com>#1/1 X-Deja-AN: 577830670 References: <388095E5.6BF46237@cstc.org> <85q63n$ese$1@bgtnsc01.worldnet.att.net> <86h42s$1ht$1@nnrp1.deja.com> <86mm2o$3cd$1@nnrp1.deja.com> X-Complaints-To: abuse@draper.com X-Trace: news.draper.com 948893814 20797 140.102.40.31 (26 Jan 2000 13:36:54 GMT) NNTP-Posting-Date: 26 Jan 2000 13:36:54 GMT Newsgroups: comp.lang.ada Date: 2000-01-26T13:36:54+00:00 List-Id: On Wed, 26 Jan 2000 11:33:44 GMT, pumilia@est.it wrote: >In article , > Stephen Leake 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