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,a315126e5fc76ced,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-19 05:40:09 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!sol.ctr.columbia.edu!proto.ida.org!wheeler From: wheeler@ida.org (David Wheeler) Newsgroups: comp.lang.ada Subject: Simplifying Unbounded_Stri Date: 19 Mar 1995 13:37:00 GMT Organization: IDA, Alexandria, Virginia Message-ID: <3khc1s$2bt@dmsoproto.ida.org> NNTP-Posting-Host: oids-3.csed.ida.org Summary: Suggestions on simplifying Unbounded_String Keywords: Unbounded_String String Ada Ustring simplify simplifying X-Newsreader: TIN [version 1.2 PL0] Date: 1995-03-19T13:37:00+00:00 List-Id: I'm looking for some advice on how to simplify Unbounded_String handling. Discussion and source code follows. As many of you know I've developed a tutorial on Ada 95, and I've been developing an expanded version. Since the Ada 83 "String" type involves all sorts of convolutions when you want to vary its length, I've decided that it'd be better to teach about Unbounded_String first. However, I think Unbounded_String is a little clumsy to use as-is. For example, there isn't a Text IO package for it (as far as I can tell)! No problem, that's easy to create. However, there's also no way to declare Unbounded_String constants.. I have to keep using To_Unbounded_String("text"). Also, while the type Unbounded_String and the package name Ada.Strings.Unbounded are very descriptive, they are too darn long for names used all over the place. I've decided that I want to create a single package that simplifies a user's life. I want to create a package "Ustrings" that provides the subtype Ustring, all the operations of Ada.Strings.Unbounded and some Text_IO types of operations. There are only two ways I've found to do this, and I'm not entirely happy with either: 1. Using cut & paste, paste in all the declarations from the other packages and then rename each one. Yuk. What I'd like to do is put a "use-like" clause in the package and have it be re-exported, but I don't think I can do that.. can I? 2. Create a child package of Ada.Strings.Unbounded, add what I want, and then create "Ustrings" by declaring it to be a rename of that child. That looks much nicer, but I'm concerned that some compilers may not like me creating a child of a predefined package. Any suggestions, improvements, comments? Code samples follow; suggestions appreciated. --- David A. Wheeler Net address: wheeler@ida.org ============================================================== METHOD 1: with Ada.Strings.Unbounded, Unbounded_String_Text_IO; use Ada.Strings.Unbounded, Unbounded_String_Text_IO; package Ustrings is -- This package provides a simpler way to work with type -- Unbounded_String, since this type will be used very often. -- -- This package the following simplifications: -- + Shortens package name to "Ustrings" and type name to "Ustring". -- + Combines Ada.Strings.Unbounded and Unbounded_String_Text_IO -- into a single package. -- + Creates shorter function names for To_Unbounded_String, i.e. -- To_Ustring(U) and U(S). "U" is not a very readable name, but -- it's such a common operation that a short name seems appropriate -- (this function is needed every time a String constant is used). -- Developed by David A. Wheeler; released to the public domain. subtype Ustring is Unbounded_String; function To_Ustring(Source : String) return Unbounded_String renames To_Unbounded_String; function U(Source : String) return Unbounded_String renames To_Unbounded_String; -- Include all declarations from packages -- Ada.Strings.Unbounded and Unbounded_String_Text_IO. -- These "use" clauses don't do the job, but creating a mass of -- "rename"s is awkward: use Ada.Strings.Unbounded; use Unbounded_String_Text_IO; end Ustrings; =========================================================== METHOD 2: with Ada.Strings.Unbounded.Simplified; package Ustrings renames Ada.Strings.Unbounded.Simplified; with Unbounded_String_Text_IO, Text_IO; use Unbounded_String_Text_IO, Text_IO; package Ada.Strings.Unbounded.Simplified is -- This package provides a simpler way to work with type -- Unbounded_String, since this type will be used very often. -- -- This package the following simplifications: -- + Shortens package name to "Ustrings" and type name to "Ustring". -- + Combines Ada.Strings.Unbounded and Unbounded_String_Text_IO -- into a single package. -- + Creates shorter function names for To_Unbounded_String, i.e. -- To_Ustring(U) and U(S). "U" is not a very readable name, but -- it's such a common operation that a short name seems appropriate -- (this function is needed every time a String constant is used). -- Developed by David A. Wheeler; released to the public domain. subtype Ustring is Unbounded_String; function To_Ustring(Source : String) return Unbounded_String renames To_Unbounded_String; function U(Source : String) return Unbounded_String renames To_Unbounded_String; -- Include all declarations from packages -- Ada.Strings.Unbounded and Unbounded_String_Text_IO. procedure Get_Line(File : in File_Type; Item : out Unbounded_String) renames Get_Line; procedure Get_Line(Item : out Unbounded_String) renames Get_Line; procedure Put(File : in File_Type; Item : in Unbounded_String) renames Put; procedure Put(Item : in Unbounded_String) renames Put; procedure Put_Line(File : in File_Type; Item : in Unbounded_String) renames Put_Line; procedure Put_Line(Item : in Unbounded_String) renames Put_Line; end Ada.Strings.Unbounded.Simplified; with Ada.Strings.Unbounded, Text_IO; use Ada.Strings.Unbounded, Text_IO; package Unbounded_String_Text_IO is procedure Get_Line(File : in File_Type; Item : out Unbounded_String); procedure Get_Line(Item : out Unbounded_String); procedure Put(File : in File_Type; Item : in Unbounded_String); procedure Put(Item : in Unbounded_String); procedure Put_Line(File : in File_Type; Item : in Unbounded_String); procedure Put_Line(Item : in Unbounded_String); end Unbounded_String_Text_IO;