Deskflow 1.22.0.197
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 "arch/ArchString.h"
11#include "common/Common.h"
12#include <string>
13
15
20{
21public:
23
24
26
30 static bool isUTF8(const std::string &);
31
33
38 static std::string UTF8ToUCS2(const std::string &, bool *errors = nullptr);
39
41
46 static std::string UTF8ToUCS4(const std::string &, bool *errors = nullptr);
47
49
54 static std::string UTF8ToUTF16(const std::string &, bool *errors = nullptr);
55
57
62 static std::string UTF8ToUTF32(const std::string &, bool *errors = nullptr);
63
65
70 static std::string UTF8ToText(const std::string &, bool *errors = nullptr);
71
73
77 static std::string UCS2ToUTF8(const std::string_view &, bool *errors = nullptr);
78
80
84 static std::string UCS4ToUTF8(const std::string_view &, bool *errors = nullptr);
85
87
91 static std::string UTF16ToUTF8(const std::string_view &, bool *errors = nullptr);
92
94
98 static std::string UTF32ToUTF8(const std::string_view &, bool *errors = nullptr);
99
101
105 static std::string textToUTF8(
106 const std::string &, bool *errors = nullptr,
108 );
109
111
112private:
113 // convert UTF8 to wchar_t string (using whatever encoding is native
114 // to the platform). caller must delete[] the returned string. the
115 // string is *not* nul terminated; the length (in characters) is
116 // returned in size.
117 static wchar_t *UTF8ToWideChar(const std::string &, uint32_t &size, bool *errors);
118
119 // convert nul terminated wchar_t string (in platform's native
120 // encoding) to UTF8.
121 static std::string wideCharToUTF8(
122 const wchar_t *, uint32_t size, bool *errors,
124 );
125
126 // internal conversion to UTF8
127 static std::string doUCS2ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
128 static std::string doUCS4ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
129 static std::string doUTF16ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
130 static std::string doUTF32ToUTF8(const uint8_t *src, uint32_t n, bool *errors);
131
132 // convert characters to/from UTF8
133 static uint32_t fromUTF8(const uint8_t *&src, uint32_t &size);
134 static void toUTF8(std::string &dst, uint32_t c, bool *errors);
135
136private:
137 static uint32_t s_invalid;
138 static uint32_t s_replacement;
139};
EWideCharEncoding
Wide character encodings.
Definition ArchString.h:37
@ kPlatformDetermined
Definition ArchString.h:42
Unicode utility functions.
Definition Unicode.h:20
static std::string UCS4ToUTF8(const std::string_view &, bool *errors=nullptr)
Convert from UCS-4 to UTF-8.
Definition Unicode.cpp:232
static std::string UTF16ToUTF8(const std::string_view &, bool *errors=nullptr)
Convert from UTF-16 to UTF-8.
Definition Unicode.cpp:242
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 UTF8ToText(const std::string &, bool *errors=nullptr)
Convert from UTF-8 to the current locale encoding.
Definition Unicode.cpp:200
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:222
static std::string textToUTF8(const std::string &, bool *errors=nullptr, ArchString::EWideCharEncoding encoding=ArchString::EWideCharEncoding::kPlatformDetermined)
Convert from the current locale encoding to UTF-8.
Definition Unicode.cpp:262
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:252