summaryrefslogtreecommitdiffstats
path: root/src/version.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/version.cpp
parentInitial commit. (diff)
downloadinkscape-upstream.tar.xz
inkscape-upstream.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/version.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/version.cpp b/src/version.cpp
new file mode 100644
index 0000000..7133ca3
--- /dev/null
+++ b/src/version.cpp
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Versions
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Kris De Gussem <Kris.DeGussem@gmail.com>
+ *
+ * Copyright (C) 2003 MenTaLguY
+ * Copyright (C) 2012 Kris De Gussem
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include <glib.h>
+#include <sstream>
+#include "version.h"
+
+bool sp_version_from_string(const char *string, Inkscape::Version *version)
+{
+ if (!string) {
+ return false;
+ }
+
+ try
+ {
+ std::stringstream ss;
+
+ // Throw exception if error.
+ ss.exceptions(std::ios::failbit | std::ios::badbit);
+ ss << string;
+ ss >> version->_major;
+ char tmp=0;
+ ss >> tmp;
+ ss >>version->_minor;
+
+ // Don't throw exception if failbit gets set (empty string OK).
+ ss.exceptions(std::ios::goodbit);
+ getline(ss, version->_tail);
+ return true;
+ }
+ catch(...)
+ {
+ version->_major = 0;
+ version->_minor = 0;
+ version->_tail.clear();
+ return false;
+ }
+}
+
+char *sp_version_to_string(Inkscape::Version version)
+{
+ return g_strdup_printf("%u.%u%s", version._major, version._minor, version._tail.c_str());
+}
+
+bool sp_version_inside_range(Inkscape::Version version,
+ unsigned major_min, unsigned minor_min,
+ unsigned major_max, unsigned minor_max)
+{
+ if ( version._major < major_min || version._major > major_max ) {
+ return false;
+ } else if ( version._major == major_min &&
+ version._minor <= minor_min )
+ {
+ return false;
+ } else if ( version._major == major_max &&
+ version._minor >= minor_max )
+ {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :