summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/Utf8Utils.h
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/Utf8Utils.h
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/Utf8Utils.h')
-rw-r--r--xbmc/utils/Utf8Utils.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/xbmc/utils/Utf8Utils.h b/xbmc/utils/Utf8Utils.h
new file mode 100644
index 0000000..a29f64a
--- /dev/null
+++ b/xbmc/utils/Utf8Utils.h
@@ -0,0 +1,42 @@
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#pragma once
10
11#include <string>
12
13class CUtf8Utils
14{
15public:
16 enum utf8CheckResult
17 {
18 plainAscii = -1, // only US-ASCII characters (valid for UTF-8 too)
19 hiAscii = 0, // non-UTF-8 sequence with high ASCII characters
20 // (possible single-byte national encoding like WINDOWS-1251, multi-byte encoding like UTF-32 or invalid UTF-8)
21 utf8string = 1 // valid UTF-8 sequences, but not US-ASCII only
22 };
23
24 /**
25 * Check given string for valid UTF-8 sequences
26 * @param str string to check
27 * @return result of check, "plainAscii" for empty string
28 */
29 static utf8CheckResult checkStrForUtf8(const std::string& str);
30
31 static inline bool isValidUtf8(const std::string& str)
32 {
33 return checkStrForUtf8(str) != hiAscii;
34 }
35
36 static size_t FindValidUtf8Char(const std::string& str, const size_t startPos = 0);
37 static size_t RFindValidUtf8Char(const std::string& str, const size_t startPos);
38
39 static size_t SizeOfUtf8Char(const std::string& str, const size_t charStart = 0);
40private:
41 static size_t SizeOfUtf8Char(const char* const str);
42};