Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "sal/config.h"
22 :
23 : #include "com/sun/star/deployment/XPackage.hpp"
24 : #include "rtl/ustring.hxx"
25 :
26 : #include "dp_version.hxx"
27 :
28 : namespace {
29 :
30 0 : OUString getElement(OUString const & version, ::sal_Int32 * index)
31 : {
32 0 : while (*index < version.getLength() && version[*index] == '0') {
33 0 : ++*index;
34 : }
35 0 : return version.getToken(0, '.', *index);
36 : }
37 :
38 : }
39 :
40 : namespace dp_misc {
41 :
42 0 : ::dp_misc::Order compareVersions(
43 : OUString const & version1, OUString const & version2)
44 : {
45 0 : for (::sal_Int32 i1 = 0, i2 = 0; i1 >= 0 || i2 >= 0;) {
46 0 : OUString e1(i1 >= 0 ? getElement(version1, &i1) : OUString());
47 0 : OUString e2(i2 >= 0 ? getElement(version2, &i2) : OUString());
48 0 : if (e1.getLength() < e2.getLength()) {
49 0 : return ::dp_misc::LESS;
50 0 : } else if (e1.getLength() > e2.getLength()) {
51 0 : return ::dp_misc::GREATER;
52 0 : } else if (e1 < e2) {
53 0 : return ::dp_misc::LESS;
54 0 : } else if (e1 > e2) {
55 0 : return ::dp_misc::GREATER;
56 : }
57 0 : }
58 0 : return ::dp_misc::EQUAL;
59 : }
60 :
61 :
62 : }
63 :
64 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|