kodi
Utf8Utils.h
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 
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 
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 };
Definition: Utf8Utils.h:13
static utf8CheckResult checkStrForUtf8(const std::string &str)
Check given string for valid UTF-8 sequences.
Definition: Utf8Utils.cpp:12