summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/StringValidation.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/StringValidation.cpp
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/StringValidation.cpp')
-rw-r--r--xbmc/utils/StringValidation.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/xbmc/utils/StringValidation.cpp b/xbmc/utils/StringValidation.cpp
new file mode 100644
index 0000000..386bfb9
--- /dev/null
+++ b/xbmc/utils/StringValidation.cpp
@@ -0,0 +1,49 @@
1/*
2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#include "StringValidation.h"
10
11#include "utils/StringUtils.h"
12
13bool StringValidation::IsInteger(const std::string &input, void *data)
14{
15 return StringUtils::IsInteger(input);
16}
17
18bool StringValidation::IsPositiveInteger(const std::string &input, void *data)
19{
20 return StringUtils::IsNaturalNumber(input);
21}
22
23bool StringValidation::IsTime(const std::string &input, void *data)
24{
25 std::string strTime = input;
26 StringUtils::Trim(strTime);
27
28 if (StringUtils::EndsWithNoCase(strTime, " min"))
29 {
30 strTime = StringUtils::Left(strTime, strTime.size() - 4);
31 StringUtils::TrimRight(strTime);
32
33 return IsPositiveInteger(strTime, NULL);
34 }
35 else
36 {
37 // support [[HH:]MM:]SS
38 std::vector<std::string> bits = StringUtils::Split(input, ":");
39 if (bits.size() > 3)
40 return false;
41
42 for (std::vector<std::string>::const_iterator i = bits.begin(); i != bits.end(); ++i)
43 if (!IsPositiveInteger(*i, NULL))
44 return false;
45
46 return true;
47 }
48 return false;
49}