! Copyright (C) 2010 Maximilian Lupke.
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays ascii combinators kernel math.order math.parser
-sequences splitting ;
+USING: arrays ascii kernel math.order math.parser sequences splitting
+;
IN: semantic-versioning
: split-version ( string -- array )
[ drop [ string>number ] tri@ 3array ]
if ;
-! okay, not beautiful
: version<=> ( version1 version2 -- <=> )
- [ split-version ] bi@
- {
- { [ [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
- { [ drop [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
- { [ drop [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
- { [ drop 2dup [ length ] bi@ >=< dup +eq+ = not ] [ 2nip ] }
- [ drop [ first ] bi@ <=> ]
- } cond ;
+ [ split-version ] bi@ drop-prefix
+ 2dup [ length 0 = ] either?
+ [ [ length ] bi@ >=< ] [ [ first ] bi@ <=> ] if ;
: version< ( version1 version2 -- ? )
version<=> +lt+ = ;