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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,64a2795a04707a01 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed.freenet.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Converting Integer / Float to String Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <62haf1069b85$.tb768rmm6vib.dlg@40tude.net> Date: Thu, 17 Jul 2008 11:24:51 +0200 Message-ID: <1iawxy1h6dfdt$.1n0nm38ucgzpg.dlg@40tude.net> NNTP-Posting-Date: 17 Jul 2008 11:24:51 CEST NNTP-Posting-Host: 379f3a4b.newsspool1.arcor-online.net X-Trace: DXC=EJ8gHWPQNNnfF8a^:6>b7eic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbbjgW5j\LYKg[6LHn;2LCVn7enW;^6ZC`dIXm65S@:3>oU]MddLMNMQo X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:1190 Date: 2008-07-17T11:24:51+02:00 List-Id: On Thu, 17 Jul 2008 10:32:59 +0200, Alexander Camek wrote: > First of all, this was only a base to start discussion on it and at that > point I need some value to initial my float or integer value to get a proper > value if the string is malformed. I don't think it is a good idea. Malformed document should be reported, instead of being silently parsed. > As far as I can tell, the background of the code snipplet is that the string > is given from an xml file which is parsed by glib xml and there I get all as > a string. I see. Doesn't Glib's XML parser have a support for numeric parsing? I mean, if you already use a parser then it is better to use it at full, instead of adding other code. > To your second question. The whitespaces are trimmed and I can only rely on > the point that there is a correct value in it, But it can be like this: 1.0 2 4 Then what about encoded Unicode characters? Like "ሴ". Does the parser translate them? If it does, how does it this for non-Latin-1 characters? I don't know it, but the parser could produce UTF-8 octets stored in Ada String, which then would be OK to parse as if it were Latin-1... (:-)) > if not then the default value > will be set or at the beginning for initilisation 0.0 is used. Well, the cases "there is no any number" and "the file contains rubbish" are different to me. I would not use the default in the second case. I have a library for parsing: http://www.dmitry-kazakov.de/ada/strings_edit.htm Your sample code could look like: begin Value := Strings_Edit.Floats.Value (Float_String); exception when End_Error => -- No number Value := Default; when Data_Error => -- Wrong number, XML file is corrupt ... when Constraint_Error => -- Out of range ... end; If saturation of the input is OK, then Value (Float_String, ToFirst => True, ToLast => True); that would saturate the input to the nearest bound instead of Constraint_Error propagation. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de