2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2014 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"
26 Lilypond_version::Lilypond_version (int major, int minor, int patch)
33 Lilypond_version::Lilypond_version (const string &str)
39 vector<string> version;
40 const char *digits = "0123456789";
41 version = string_split (str, '.');
43 switch (version.size ()) {
45 extra_patch_string_ = version[3];
46 if (version[2].empty ())
49 if (version[2].find_first_not_of (digits) != string::npos
50 || version[1].empty ())
52 patch_ = String_convert::dec2int (version[2]);
54 if (version[1].find_first_not_of (digits) != string::npos
55 || version[1].empty () || version[0].empty ())
57 minor_ = String_convert::dec2int (version[1]);
58 if (version[0].find_first_not_of (digits) != string::npos)
60 major_ = String_convert::dec2int (version[0]);
65 Lilypond_version::to_string () const
69 return ::to_string (major_)
70 + "." + ::to_string (minor_)
71 + "." + ::to_string (patch_);
74 Lilypond_version::operator bool () const
80 Lilypond_version::compare (const Lilypond_version &a, const Lilypond_version &b)
84 if (a.major_ != b.major_)
85 return a.major_ > b.major_ ? 1 : -1;
86 if (a.minor_ != b.minor_)
87 return a.minor_ > b.minor_ ? 1 : -1;
88 if (a.patch_ != b.patch_)
89 return a.patch_ > b.patch_ ? 1 : -1;