From be933ef2241d79558f91796cc5b3a161f72ebf9c Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 19 Oct 2020 00:52:24 +0200 Subject: sync with upstream --- xbmc/utils/Utf8Utils.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 xbmc/utils/Utf8Utils.h (limited to 'xbmc/utils/Utf8Utils.h') 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 @@ +/* + * Copyright (C) 2013-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include + +class CUtf8Utils +{ +public: + enum utf8CheckResult + { + plainAscii = -1, // only US-ASCII characters (valid for UTF-8 too) + hiAscii = 0, // non-UTF-8 sequence with high ASCII characters + // (possible single-byte national encoding like WINDOWS-1251, multi-byte encoding like UTF-32 or invalid UTF-8) + utf8string = 1 // valid UTF-8 sequences, but not US-ASCII only + }; + + /** + * Check given string for valid UTF-8 sequences + * @param str string to check + * @return result of check, "plainAscii" for empty string + */ + static utf8CheckResult checkStrForUtf8(const std::string& str); + + static inline bool isValidUtf8(const std::string& str) + { + return checkStrForUtf8(str) != hiAscii; + } + + static size_t FindValidUtf8Char(const std::string& str, const size_t startPos = 0); + static size_t RFindValidUtf8Char(const std::string& str, const size_t startPos); + + static size_t SizeOfUtf8Char(const std::string& str, const size_t charStart = 0); +private: + static size_t SizeOfUtf8Char(const char* const str); +}; -- cgit v1.2.3