summaryrefslogtreecommitdiffstats
path: root/snap/local/print-inkscape-version.cpp
blob: 17d0c17a0f03c4f1a0cde83b483e3e92de551287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: GPL-2.0-or-later
// Use the Inkscape compiled version identifier and print it out with
// the Snap restrictions on versions. Only a few characters allowed
// and a limit of 32 characters.
#include "inkscape-version.h"

#include <iostream>
#include <cctype>

int main (int argc, char ** argv) {
	std::string outstr;

	for (const auto& c : std::string{Inkscape::version_string}) {
		if (outstr.length() == 32) {
			break;
		}

		if (std::isalpha(c) || std::isdigit(c)) {
			outstr.append(1, c);
			continue;
		}

		if (c == '(' || c == ')' || c == ',') {
			continue;
		}

		if (c == '.' || c == '-') {
			outstr.append(1, c);
			continue;
		}

		outstr.append(1, '-');
	}

	while (outstr.length() > 0 && !std::isalpha(outstr.back()) && !std::isdigit(outstr.back())) {
		outstr.pop_back();
	}

	std::cout << outstr << std::endl;

	return 0;
}