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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.6.16 with SMTP id 16mr1382645iog.105.1510846425277; Thu, 16 Nov 2017 07:33:45 -0800 (PST) X-Received: by 10.157.1.175 with SMTP id e44mr87483ote.1.1510846425128; Thu, 16 Nov 2017 07:33:45 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!feed.usenet.farm!feeder3.usenet.farm!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newspeer1.nac.net!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!i6no219512itb.0!news-out.google.com!x87ni709ita.0!nntp.google.com!i6no219508itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 16 Nov 2017 07:33:44 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:5985:2c17:9409:aa9c; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:5985:2c17:9409:aa9c References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Comparing version numbers From: Robert Eachus Injection-Date: Thu, 16 Nov 2017 15:33:45 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: feeder.eternal-september.org comp.lang.ada:48932 Date: 2017-11-16T07:33:44-08:00 List-Id: 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=20 > programming ideas rather than about Ada. (However, a solution in Python o= r=20 > Ruby or JavaScript would more likely used regexps than Ada.) >=20 > Suppose I have two version numbers of a software. I need to check which o= f=20 > the two is greater. >=20 > Lexical order string comparison does not work: >=20 > "2.3" vs "11.4". >=20 > I could split it by "." and compare the numbers. But a component of a=20 > version numbers may be nonnumeric like: >=20 > "1.2beta". >=20 > What to do? >=20 > It should work for example for all Debian packages containing interpreter= s=20 > (for example, "2.7" for "python" package). It is easy to do using Text_IO. Assuming that the version numbers are in t= wo strings, compare using Float_IO if the first character both is a digit, = otherwise compare as strings. If the results compare equal, discard the cu= rrent 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 d= etail. You might also special case the string "gamma," but that is even mo= re 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 epsi= lon.)