/src/libreoffice/desktop/source/deployment/misc/dp_version.cxx
Line | Count | Source |
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 <o3tl/string_view.hxx> |
24 | | |
25 | | #include <dp_version.hxx> |
26 | | |
27 | | namespace { |
28 | | |
29 | | std::u16string_view getElement(std::u16string_view version, std::size_t * index) |
30 | 0 | { |
31 | 0 | while (*index < version.size() && version[*index] == '0') { |
32 | 0 | ++*index; |
33 | 0 | } |
34 | 0 | return o3tl::getToken(version, u'.', *index); |
35 | 0 | } |
36 | | |
37 | | } |
38 | | |
39 | | namespace dp_misc { |
40 | | |
41 | | ::dp_misc::Order compareVersions( |
42 | | std::u16string_view version1, std::u16string_view version2) |
43 | 0 | { |
44 | 0 | for (size_t i1 = 0, i2 = 0; i1 != std::u16string_view::npos || i2 != std::u16string_view::npos;) { |
45 | 0 | std::u16string_view e1(i1 != std::u16string_view::npos ? getElement(version1, &i1) : std::u16string_view()); |
46 | 0 | std::u16string_view e2(i2 != std::u16string_view::npos ? getElement(version2, &i2) : std::u16string_view()); |
47 | 0 | if (e1.size() < e2.size()) { |
48 | 0 | return ::dp_misc::LESS; |
49 | 0 | } else if (e1.size() > e2.size()) { |
50 | 0 | return ::dp_misc::GREATER; |
51 | 0 | } else if (e1 < e2) { |
52 | 0 | return ::dp_misc::LESS; |
53 | 0 | } else if (e1 > e2) { |
54 | 0 | return ::dp_misc::GREATER; |
55 | 0 | } |
56 | 0 | } |
57 | 0 | return ::dp_misc::EQUAL; |
58 | 0 | } |
59 | | |
60 | | |
61 | | } |
62 | | |
63 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |