Deskflow 1.24.0.365
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
Unicode.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
4 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
5 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6 */
7
8#pragma once
9
10#include <cstdint>
11#include <string>
12
14
19{
20public:
22
23
25
29 static bool isUTF8(const std::string &);
30
32
37 static std::string UTF8ToUCS2(const std::string &, bool *errors = nullptr);
38
40
45 static std::string UTF8ToUCS4(const std::string &, bool *errors = nullptr);
46
48
53 static std::string UTF8ToUTF16(const std::string &, bool *errors = nullptr);
54
56
61 static std::string UTF8ToUTF32(const std::string &, bool *errors = nullptr);
62
64
68 static std::string UCS2ToUTF8(const std::string_view &, bool *errors = nullptr);
69
71
75 static std::string UCS4ToUTF8(const std::string_view &, bool *errors = nullptr);
76
78
82 static std::string UTF16ToUTF8(const std::string_view &, bool *errors = nullptr);
83
85
89 static std::string UTF32ToUTF8(const std::string_view &, bool *errors = nullptr);
90
92
93private:
94 // internal conversion to UTF8
95 static std::string doUCS2ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
96 static std::string doUCS4ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
97 static std::string doUTF16ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
98 static std::string doUTF32ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
99
100 // convert characters to/from UTF8
101 static uint32_t fromUTF8(const uint8_t *&src, uint32_t &size);
102 static void toUTF8(std::string &dst, uint32_t c, bool *errors);
103
104private:
105 static uint32_t s_invalid;
106 static uint32_t s_replacement;
107};
Unicode utility functions.
Definition Unicode.h:19
static std::string UCS4ToUTF8(const std::string_view &, bool *errors=nullptr)
Convert from UCS-4 to UTF-8.
Definition Unicode.cpp:210
static std::string UTF16ToUTF8(const std::string_view &, bool *errors=nullptr)
Convert from UTF-16 to UTF-8.
Definition Unicode.cpp:220
static bool isUTF8(const std::string &)
Test UTF-8 string for validity.
Definition Unicode.cpp:77
static std::string UTF8ToUCS4(const std::string &, bool *errors=nullptr)
Convert from UTF-8 to UCS-4 encoding.
Definition Unicode.cpp:116
static std::string UTF8ToUTF16(const std::string &, bool *errors=nullptr)
Convert from UTF-8 to UTF-16 encoding.
Definition Unicode.cpp:139
static std::string UTF8ToUCS2(const std::string &, bool *errors=nullptr)
Convert from UTF-8 to UCS-2 encoding.
Definition Unicode.cpp:89
static std::string UCS2ToUTF8(const std::string_view &, bool *errors=nullptr)
Convert from UCS-2 to UTF-8.
Definition Unicode.cpp:200
static std::string UTF8ToUTF32(const std::string &, bool *errors=nullptr)
Convert from UTF-8 to UTF-32 encoding.
Definition Unicode.cpp:174
static std::string UTF32ToUTF8(const std::string_view &, bool *errors=nullptr)
Convert from UTF-32 to UTF-8.
Definition Unicode.cpp:230