1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26
27 #include "sal/config.h"
28
29 #include "com/sun/star/deployment/XPackage.hpp"
30 #include "rtl/ustring.hxx"
31
32 #include "dp_version.hxx"
33
34 namespace {
35
36 namespace css = ::com::sun::star;
37
getElement(::rtl::OUString const & version,::sal_Int32 * index)38 ::rtl::OUString getElement(::rtl::OUString const & version, ::sal_Int32 * index)
39 {
40 while (*index < version.getLength() && version[*index] == '0') {
41 ++*index;
42 }
43 return version.getToken(0, '.', *index);
44 }
45
46 }
47
48 namespace dp_misc {
49
compareVersions(::rtl::OUString const & version1,::rtl::OUString const & version2)50 ::dp_misc::Order compareVersions(
51 ::rtl::OUString const & version1, ::rtl::OUString const & version2)
52 {
53 for (::sal_Int32 i1 = 0, i2 = 0; i1 >= 0 || i2 >= 0;) {
54 ::rtl::OUString e1(getElement(version1, &i1));
55 ::rtl::OUString e2(getElement(version2, &i2));
56 if (e1.getLength() < e2.getLength()) {
57 return ::dp_misc::LESS;
58 } else if (e1.getLength() > e2.getLength()) {
59 return ::dp_misc::GREATER;
60 } else if (e1 < e2) {
61 return ::dp_misc::LESS;
62 } else if (e1 > e2) {
63 return ::dp_misc::GREATER;
64 }
65 }
66 return ::dp_misc::EQUAL;
67 }
68
69
70 }
71