2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2015 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "lilypond-version.hh"
23 #include "string-convert.hh"
29 Lilypond_version::Lilypond_version (int major, int minor, int patch)
36 Lilypond_version::Lilypond_version (const string &str)
42 vector<string> version;
43 const char *digits = "0123456789";
44 version = string_split (str, '.');
46 switch (version.size ()) {
48 extra_patch_string_ = version[3];
49 if (version[2].empty ())
52 if (version[2].find_first_not_of (digits) != string::npos
53 || version[1].empty ())
55 patch_ = String_convert::dec2int (version[2]);
57 if (version[1].find_first_not_of (digits) != string::npos
58 || version[1].empty () || version[0].empty ())
60 minor_ = String_convert::dec2int (version[1]);
61 if (version[0].find_first_not_of (digits) != string::npos)
63 major_ = String_convert::dec2int (version[0]);
68 Lilypond_version::to_string () const
72 return ::to_string (major_)
73 + "." + ::to_string (minor_)
74 + "." + ::to_string (patch_);
77 Lilypond_version::operator bool () const
83 Lilypond_version::compare (const Lilypond_version &a, const Lilypond_version &b)
87 if (a.major_ != b.major_)
88 return a.major_ > b.major_ ? 1 : -1;
89 if (a.minor_ != b.minor_)
90 return a.minor_ > b.minor_ ? 1 : -1;
91 if (a.patch_ != b.patch_)
92 return a.patch_ > b.patch_ ? 1 : -1;