merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / deployment / misc / dp_version.cxx
blob440dc8d98d1a9bedc4c3a97ad16777bda69b3fb6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_version.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
34 #include "sal/config.h"
36 #include "com/sun/star/deployment/XPackage.hpp"
37 #include "rtl/ustring.hxx"
39 #include "dp_version.hxx"
41 namespace {
43 namespace css = ::com::sun::star;
45 ::rtl::OUString getElement(::rtl::OUString const & version, ::sal_Int32 * index)
47 while (*index < version.getLength() && version[*index] == '0') {
48 ++*index;
50 return version.getToken(0, '.', *index);
55 namespace dp_misc {
57 ::dp_misc::Order compareVersions(
58 ::rtl::OUString const & version1, ::rtl::OUString const & version2)
60 for (::sal_Int32 i1 = 0, i2 = 0; i1 >= 0 || i2 >= 0;) {
61 ::rtl::OUString e1(getElement(version1, &i1));
62 ::rtl::OUString e2(getElement(version2, &i2));
63 if (e1.getLength() < e2.getLength()) {
64 return ::dp_misc::LESS;
65 } else if (e1.getLength() > e2.getLength()) {
66 return ::dp_misc::GREATER;
67 } else if (e1 < e2) {
68 return ::dp_misc::LESS;
69 } else if (e1 > e2) {
70 return ::dp_misc::GREATER;
73 return ::dp_misc::EQUAL;
76 ::dp_misc::Order comparePackageVersions(
77 css::uno::Reference< css::deployment::XPackage > const & package1,
78 css::uno::Reference< css::deployment::XPackage > const & package2)
80 return compareVersions(package1->getVersion(), package2->getVersion());