Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
ca2fefb8
Kaydet (Commit)
ca2fefb8
authored
Kas 11, 2014
tarafından
Tor Lillqvist
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add a function to compare version number strings
Change-Id: I88d3d9040f70e84752ade19001a699f60e9e7636
üst
6914b172
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
0 deletions
+120
-0
Library_comphelper.mk
comphelper/Library_comphelper.mk
+1
-0
test_string.cxx
comphelper/qa/string/test_string.cxx
+40
-0
compareversionstrings.cxx
comphelper/source/misc/compareversionstrings.cxx
+70
-0
string.hxx
include/comphelper/string.hxx
+9
-0
No files found.
comphelper/Library_comphelper.mk
Dosyayı görüntüle @
ca2fefb8
...
...
@@ -75,6 +75,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
comphelper/source/misc/accimplaccess \
comphelper/source/misc/anytostring \
comphelper/source/misc/asyncnotification \
comphelper/source/misc/compareversionstrings \
comphelper/source/misc/comphelper_module \
comphelper/source/misc/comphelper_services \
comphelper/source/misc/componentbase \
...
...
comphelper/qa/string/test_string.cxx
Dosyayı görüntüle @
ca2fefb8
...
...
@@ -44,6 +44,7 @@ public:
void
testIsdigitAsciiString
();
void
testReverseString
();
void
testEqualsString
();
void
testCompareVersionStrings
();
CPPUNIT_TEST_SUITE
(
TestString
);
CPPUNIT_TEST
(
testNatural
);
...
...
@@ -57,6 +58,7 @@ public:
CPPUNIT_TEST
(
testIsdigitAsciiString
);
CPPUNIT_TEST
(
testReverseString
);
CPPUNIT_TEST
(
testEqualsString
);
CPPUNIT_TEST
(
testCompareVersionStrings
);
CPPUNIT_TEST_SUITE_END
();
};
...
...
@@ -407,6 +409,44 @@ void TestString::testEqualsString()
CPPUNIT_ASSERT
(
!::
comphelper
::
string
::
equals
(
aIn
,
'A'
));
}
int
sign
(
int
n
)
{
if
(
n
==
0
)
return
0
;
if
(
n
<
0
)
return
-
1
;
else
return
1
;
}
void
TestString
::
testCompareVersionStrings
()
{
#ifdef TEST
#error TEST already defined
#endif
#define TEST(a,b,result) \
CPPUNIT_ASSERT(sign(::comphelper::string::compareVersionStrings(a, b)) == result); \
if ( result != 0 ) \
CPPUNIT_ASSERT(sign(::comphelper::string::compareVersionStrings(b, a)) == -(result))
TEST
(
""
,
""
,
0
);
TEST
(
""
,
"0"
,
-
1
);
TEST
(
""
,
"a"
,
-
1
);
TEST
(
"0"
,
"1"
,
-
1
);
TEST
(
"1"
,
"2"
,
-
1
);
TEST
(
"2"
,
"10"
,
-
1
);
TEST
(
"01"
,
"1"
,
-
1
);
TEST
(
"01"
,
"001"
,
1
);
TEST
(
"1.00"
,
"1"
,
1
);
TEST
(
"1.2"
,
"1"
,
1
);
TEST
(
"1.01"
,
"1.1"
,
-
1
);
TEST
(
"1.001"
,
"1.1"
,
-
1
);
TEST
(
"1.001"
,
"1.010"
,
-
1
);
TEST
(
"1.2.a"
,
"1.2.b"
,
-
1
);
#undef TEST
}
CPPUNIT_TEST_SUITE_REGISTRATION
(
TestString
);
}
...
...
comphelper/source/misc/compareversionstrings.cxx
0 → 100644
Dosyayı görüntüle @
ca2fefb8
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <comphelper/string.hxx>
#include <rtl/ustring.hxx>
namespace
comphelper
{
namespace
string
{
namespace
{
// BSD licensed, from http://git.musl-libc.org/cgit/musl/plain/src/string/strverscmp.c
int
strverscmp
(
const
char
*
l
,
const
char
*
r
)
{
int
haszero
=
1
;
while
(
*
l
==*
r
)
{
if
(
!*
l
)
return
0
;
if
(
*
l
==
'0'
)
{
if
(
haszero
==
1
)
{
haszero
=
0
;
}
}
else
if
(
isdigit
(
*
l
))
{
if
(
haszero
==
1
)
{
haszero
=
2
;
}
}
else
{
haszero
=
1
;
}
l
++
;
r
++
;
}
if
(
haszero
==
1
&&
(
*
l
==
'0'
||
*
r
==
'0'
))
{
haszero
=
0
;
}
if
((
isdigit
(
*
l
)
&&
isdigit
(
*
r
)
)
&&
haszero
)
{
size_t
lenl
=
0
,
lenr
=
0
;
while
(
isdigit
(
l
[
lenl
])
)
lenl
++
;
while
(
isdigit
(
r
[
lenr
])
)
lenr
++
;
if
(
lenl
==
lenr
)
{
return
(
*
l
-
*
r
);
}
else
if
(
lenl
>
lenr
)
{
return
1
;
}
else
{
return
-
1
;
}
}
else
{
return
(
*
l
-
*
r
);
}
}
}
// anonymous namespace
int
compareVersionStrings
(
const
OUString
&
a
,
const
OUString
&
b
)
{
return
strverscmp
(
OUStringToOString
(
a
,
RTL_TEXTENCODING_UTF8
).
getStr
(),
OUStringToOString
(
b
,
RTL_TEXTENCODING_UTF8
).
getStr
());
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
include/comphelper/string.hxx
Dosyayı görüntüle @
ca2fefb8
...
...
@@ -463,6 +463,15 @@ inline bool isalnumAscii(sal_Unicode c)
return
isalphaAscii
(
c
)
||
isdigitAscii
(
c
);
}
/** Compare two strings containing software version numbers
Inspired by the GNU strverscmp(), but there is no guarantee that the exact
same semantics are used, or that the semantics are stable between LibreOffice versions.
@return -1, 0 or 1
*/
COMPHELPER_DLLPUBLIC
int
compareVersionStrings
(
const
OUString
&
a
,
const
OUString
&
b
);
}
}
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment