comp.lang.ada
 help / color / mirror / Atom feed
From: ldries46 <bertus.dries@planet.nl>
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 08:40:41 +0100	[thread overview]
Message-ID: <nnd$23404336$0a486277@9b8ca000aec60c20> (raw)
In-Reply-To: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com>

Op 29-11-2021 om 18:34 schreef Kevin Chadwick:
> I suspect that I am doing something outside of Ada norms.
>
> Are empty strings avoided in Ada?
>
> I have a function to create a record containing strings amongst other things like a subtyped integer, simply to group the outputs neatly of another function.
>
> If something goes wrong and I run the create function with "" then the strings length is zero. Why is a string type Positive and not Natural, because empty strings are in fact useless?
>
> I guess I shall consider re-engineering my functions, rather than add checks, but all thoughts are welcome.
 From your description, I suspect that you are using different 
declarations for the strings you use for instance while " " in fact is a 
string(1.1) you try to put this in a string(1 .. 5).
To avoid this kind of problems I generally use the package 
Ada.Strings.Unbounded where have possibilities to operate strings 
without caring for the length. Changing between strings and unbounded 
strings is possible with functions in the package.
I would then advice you to create an variable at a position where it is 
reachable from all packages where you use it:
Empty_String : Unbounded_String := To_Unbounded_String("");

  parent reply	other threads:[~2021-11-30  7:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 17:34 Empty String confusion; Positive and Natural Kevin Chadwick
2021-11-29 18:05 ` Jeffrey R.Carter
2021-11-29 19:19 ` Niklas Holsti
2021-11-29 22:50   ` Kevin Chadwick
2021-11-30  8:29     ` Simon Wright
2021-11-30  8:34     ` Niklas Holsti
2021-11-30 10:00     ` Jeffrey R.Carter
2021-11-30 12:17       ` Kevin Chadwick
2021-11-30 12:54         ` J-P. Rosen
2021-11-30 13:12           ` Kevin Chadwick
2021-11-30  7:40 ` ldries46 [this message]
2021-11-30  8:21   ` Simon Wright
2021-11-30 12:39     ` ldries46
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox