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-Thread: 103376,640b65cbfbab7216 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Sat, 05 Apr 2008 06:39:44 +0200 From: Gautier User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada.Strings.Bounded References: <47F26C46.3010607@obry.net> <44d88b93-6a90-4c18-8785-2164934ba700@a9g2000prl.googlegroups.com> <47F652F7.9050502@obry.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 85.0.157.23 X-Original-NNTP-Posting-Host: 85.0.157.23 Message-ID: <47f7028d$1_6@news.bluewin.ch> X-Trace: news.bluewin.ch 1207370381 85.0.157.23 (5 Apr 2008 06:39:41 +0200) Organization: Bluewin AG Complaints-To: abuse@bluewin.ch X-Original-NNTP-Posting-Host: 127.0.0.1 Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns11feed!worldnet.att.net!164.128.36.58!news.ip-plus.net!newsfeed.ip-plus.net!news.bluewin.ch!not-for-mail Xref: g2news1.google.com comp.lang.ada:20829 Date: 2008-04-05T06:39:44+02:00 List-Id: Adam Beneschan: > When I read this and was thinking randomly about Ada's string > handling, I got to wondering why Bounded_Strings was defined as a > generic, rather than declaring a discriminated type with the maximum > length as the discriminant. Do you mean something like that ? ------------------------------------------------------------------------------ -- File: BorString.ads -- Description: Variable-size, bounded strings as in early Borland Pascals -- Essentially for quick portability purposes. -- Date / Version: 14-May-2001 ; 4-May-2000 -- Author: Gautier de Montmollin -- Portability: Full: pure Ada 83. Nearest Ada 95+ package: the -- generic Ada.Strings.Bounded . ------------------------------------------------------------------------------ package BorStrings is type BorString( maxlength: positive ) is private; -- Idea: you can convert to string for _functional_ manipulations function To_String( b:BorString ) return String; -- ... then, put the result in a BorString if needed procedure Put( b : in out BorString; c: Character ); procedure Put( b : in out BorString; s: String ); procedure Put( bd: in out BorString; bs: BorString ); -- Note: with the "&" concatenators defined below, you can do it -- straigthforward ! -- * Procedures and functions that are in Turbo Pascal and later: -- Concat Copy Delete Insert Length Pos -- * We add RPos for searching a string from the _right_ -- Concat: use the "&" operator instead! NB: TP has "+" function Copy(b: BorString; index: Integer; count: Integer) return String; procedure Delete( b: in out BorString; index: Positive; count: Positive); procedure Insert( source: String; b: in out BorString; index: Integer); procedure Insert( source: BorString; b: in out BorString; index: Integer); function Length( b: BorString ) return Natural; function Pos( substr: String; b: BorString) return Natural; function RPos( substr: String; b: BorString) return Natural; -- "&" operators returning a BorString of _same_ maxlength as the input -- so you can write b:= b & " " or b:= "[" & b & "]" ! function "&" ( c: Character; b: BorString) return BorString; function "&" ( s: String; b: BorString) return BorString; function "&" ( b: BorString; c: Character) return BorString; function "&" ( b: BorString; s: String) return BorString; -- same, returning strings (experimental: can cause ambiguities) function "&" ( c: Character; b: BorString) return String; function "&" ( s: String; b: BorString) return String; function "&" ( b: BorString; c: Character) return String; function "&" ( b: BorString; s: String) return String; function Eq ( b1,b2: BorString ) return Boolean; function Eq ( b1: BorString; s2: String ) return Boolean; string_overflow: exception; pragma Inline(To_String); private type BorString( maxlength: positive ) is record length: Natural:= 0; s: String( 1..maxlength ); end record; -- NB: length allows longer strings than the "s[0]" in T/B-Pascal end BorStrings; ______________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/index.htm Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site!