comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: Comparing version numbers
Date: Thu, 16 Nov 2017 07:33:44 -0800 (PST)
Date: 2017-11-16T07:33:44-08:00	[thread overview]
Message-ID: <dbbfcef9-8a0c-4fbf-b8b3-2198f8fb0d1d@googlegroups.com> (raw)
In-Reply-To: <oub0kd$1a6r$1@gioia.aioe.org>

On Sunday, November 12, 2017 at 9:39:15 PM UTC-5, Victor Porton wrote:
> Not sure if it is quite on-topic, because it is more about general 
> programming ideas rather than about Ada. (However, a solution in Python or 
> Ruby or JavaScript would more likely used regexps than Ada.)
> 
> Suppose I have two version numbers of a software. I need to check which of 
> the two is greater.
> 
> Lexical order string comparison does not work:
> 
> "2.3" vs "11.4".
> 
> I could split it by "." and compare the numbers. But a component of a 
> version numbers may be nonnumeric like:
> 
> "1.2beta".
> 
> What to do?
> 
> It should work for example for all Debian packages containing interpreters 
> (for example, "2.7" for "python" package).

It is easy to do using Text_IO.  Assuming that the version numbers are in two strings, compare using Float_IO if the first character both is a digit, otherwise compare as strings.  If the results compare equal, discard the current character in both strings and try again.  I'd probably write it using a goto to emphasize that the case statement is rarely used, but that's a detail.  You might also special case the string "gamma," but that is even more of a detail.  (It only matters if someone decided to issue a fourth test version at one release level, and called the versions alpha, beta, gamma, and delta.  I've seen gamma versions on occasion, but never a delta or epsilon.)


  parent reply	other threads:[~2017-11-16 15:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13  2:39 Comparing version numbers Victor Porton
2017-11-13  5:15 ` J-P. Rosen
2017-11-13  8:04   ` briot.emmanuel
2017-11-13 11:11     ` Simon Wright
2017-11-13 21:30       ` briot.emmanuel
2017-11-13  8:10 ` Dmitry A. Kazakov
2017-11-13 15:56   ` Victor Porton
2017-11-13 17:22     ` Dmitry A. Kazakov
2017-11-13 18:54       ` Victor Porton
2017-11-13 20:25         ` Dmitry A. Kazakov
2017-11-16 15:33 ` Robert Eachus [this message]
2017-11-17 14:45 ` Shark8
replies disabled

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