]> git.donarmstrong.com Git - lilypond.git/blob - lily/lilypond-version.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / lilypond-version.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2014 Jan Nieuwenhuizen <janneke@gnu.org>
5
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.
10
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.
15
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/>.
18 */
19
20 #include <ctype.h>
21
22 #include "lilypond-version.hh"
23 #include "string-convert.hh"
24 #include "misc.hh"
25
26 Lilypond_version::Lilypond_version (int major, int minor, int patch)
27 {
28   major_ = major;
29   minor_ = minor;
30   patch_ = patch;
31 }
32
33 Lilypond_version::Lilypond_version (const string &str)
34 {
35   major_ = 0;
36   minor_ = 0;
37   patch_ = 0;
38
39   vector<string> version;
40   version = string_split (str, '.');
41
42   if (version.size () > 0 && isdigit (version[0][0]))
43     major_ = String_convert::dec2int (version[0]);
44   if (version.size () > 1 && isdigit (version[1][0]))
45     minor_ = String_convert::dec2int (version[1]);
46
47   patch_ = 0;
48   if (version.size () >= 3
49       && isdigit (version[2][0]))
50     patch_ = String_convert::dec2int (version[2]);
51
52   if (version.size () >= 4)
53     extra_patch_string_ = version[3];
54 }
55
56 string
57 Lilypond_version::to_string () const
58 {
59   return ::to_string (major_)
60          + "." + ::to_string (minor_)
61          + "." + ::to_string (patch_);
62 }
63
64 Lilypond_version::operator int () const
65 {
66   // ugh
67   return 100000 * major_ + 1000 * minor_ + patch_;
68 }
69