diff options
Diffstat (limited to 'xbmc/utils/Utf8Utils.h')
| -rw-r--r-- | xbmc/utils/Utf8Utils.h | 42 |
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 | |||
| 13 | class CUtf8Utils | ||
| 14 | { | ||
| 15 | public: | ||
| 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); | ||
| 40 | private: | ||
| 41 | static size_t SizeOfUtf8Char(const char* const str); | ||
| 42 | }; | ||
