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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38c827f7e800d317 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-27 05:22:55 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!skynet.be!skynet.be!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: conversion Date: Fri, 27 Jun 2003 14:22:51 +0200 Message-ID: References: NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1056716573 30236065 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:39805 Date: 2003-06-27T14:22:51+02:00 List-Id: On Fri, 27 Jun 2003 04:51:04 -0600, "Andrew" wrote: >I am experimenting with Ada as the primary language in our process. It >seems that >the use of String and Unbounded_String require converting from one to the >other in >order to read a line from a file and then trim it or slice it or tokenize >it. Usually you do not need Unbounded_String when you are working with files. You read into a string buffer and parse the buffer contents taking into account the number of read characters. Ada.Text_IO.Get_Line uses this technique: procedure Get_Line ( File : in File_Type; Item : out String; Last : out Natural ); When you parse the buffer, the recognized tokens need not to be copied. You can well use string slices for that. >For now, >regardless of the performance of these conversions it is rather inconvenient >to design >for a language that does not have a "universal" string type. Yes, Unbounded_String and String should to be siblings, which is presently impossible in Ada. >For instance: a variable of type char * can be used as char * or as char [] >and char [] >can be used as char *. A fixed string in Ada (to me) is like declaring a >char [], you >must specify a size at compile time. An unbounded_string in Ada is like >char *, it can >take on a different size when it appears on the LHS of an assignment >operator. The >catch is that unbounded_string can not be used in context of string. This >posses some >design inconveniences and requires converting back and forth from string to >unbounded_string multiple times. In most cases you can avoid Unbounded_String by using discriminated types: type Employee (Name_Length : Positive) is record Name : String (1..Name_Length); ... end record; Truly dynamic string objects are surprisingly rare. Even if you have such, they will be likely encapsulated in more complex objects, for which it should be no problem to define an appropriate interface in terms of Strings not Unbounded_Strings. >I defined a string pointer type so that I could dynamically create strings >that are the fixed >string type but I find that 'that' only defers the need to convert from >fixed string to >unbounded_string to different points in the design or that the conversion is >not eliminated. I presume that Unbounded_String-->String conversion is very inexpensive. >I am now thinking that for my company we could develop a "library" that has >a "universal" >string type. If we don't base it on the defined string in package standard >and can use >streams to read from files then we can define our own string type. I >think... > >I'm not real sure whether to extend on the functionality of ada.text_io or >to create new >functionality from the stream package. Any recommendations? Has anyone >done >something like this? I never felt any need in something like that. Perhaps others ... --- Regards, Dmitry Kazakov www.dmitry-kazakov.de