Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
b0bb1892
Commit
b0bb1892
authored
Jun 04, 2021
by
Volker Krause
Browse files
Implement stop place level comparison of IFOPT identifiers
Will be needed for Location comparison and Location merging.
parent
7b904337
Changes
3
Hide whitespace changes
Inline
Side-by-side
autotests/ifopttest.cpp
View file @
b0bb1892
...
...
@@ -44,6 +44,20 @@ private Q_SLOTS:
QFETCH
(
bool
,
valid
);
QCOMPARE
(
IfoptUtil
::
isValid
(
ifopt
),
valid
);
}
void
testStopPlace
()
{
QCOMPARE
(
IfoptUtil
::
stopPlace
(
s
(
"de:08115:4512:5:B"
)),
s
(
"de:08115:4512"
));
QCOMPARE
(
IfoptUtil
::
stopPlace
(
s
(
"de:08115:4512:5"
)),
s
(
"de:08115:4512"
));
QCOMPARE
(
IfoptUtil
::
stopPlace
(
s
(
"de:08115:4512"
)),
s
(
"de:08115:4512"
));
}
void
testIsSameStopPlace
()
{
QVERIFY
(
IfoptUtil
::
isSameStopPlace
(
s
(
"de:08115:4512:5:B"
),
s
(
"de:08115:4512"
)));
QVERIFY
(
IfoptUtil
::
isSameStopPlace
(
s
(
"de:08115:4512:5:B"
),
s
(
"de:08115:4512:2:1"
)));
QVERIFY
(
!
IfoptUtil
::
isSameStopPlace
(
s
(
"de:08115:4512:5:B"
),
s
(
"de:08115:4513:2:1"
)));
}
};
QTEST_APPLESS_MAIN
(
IfoptTest
)
...
...
src/lib/ifopt/ifoptutil.cpp
View file @
b0bb1892
...
...
@@ -30,3 +30,17 @@ bool IfoptUtil::isValid(QStringView ifopt)
return
elementCount
>=
3
&&
elementCount
<=
5
&&
ifopt
[
0
].
isLetter
()
&&
ifopt
[
1
].
isLetter
()
&&
ifopt
[
2
]
==
QLatin1Char
(
':'
);
}
QStringView
IfoptUtil
::
stopPlace
(
QStringView
ifopt
)
{
qsizetype
pos
=
0
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
pos
=
ifopt
.
indexOf
(
QLatin1Char
(
':'
),
pos
)
+
1
;
}
return
ifopt
.
left
(
pos
-
1
);
}
bool
IfoptUtil
::
isSameStopPlace
(
QStringView
lhs
,
QStringView
rhs
)
{
return
stopPlace
(
lhs
)
==
stopPlace
(
rhs
);
}
src/lib/ifopt/ifoptutil.h
View file @
b0bb1892
...
...
@@ -21,6 +21,12 @@ namespace IfoptUtil
/** Check if @p ifopt is a valid IFOPT identifier. */
bool
isValid
(
QStringView
ifopt
);
/** Returns the stop place identifier for the given (valid!) IFOPT identifier @p ifopt. */
QStringView
stopPlace
(
QStringView
ifopt
);
/** Checks whether two valid IFOPT ids refer to the same stop place. */
bool
isSameStopPlace
(
QStringView
lhs
,
QStringView
rhs
);
}
}
...
...
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