Coverage Report

Created: 2025-11-23 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/UnicodeConverter.h
Line
Count
Source
1
//
2
// UnicodeConverter.h
3
//
4
// Library: Foundation
5
// Package: Text
6
// Module:  UnicodeConverter
7
//
8
// Definition of the UnicodeConverter class.
9
//
10
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_UnicodeConverter_INCLUDED
18
#define Foundation_UnicodeConverter_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include "Poco/UTFString.h"
23
24
25
namespace Poco {
26
27
28
class Foundation_API UnicodeConverter
29
  /// A convenience class that converts strings from
30
  /// UTF-8 encoded std::strings to UTF-16 or UTF-32 encoded std::wstrings
31
  /// and vice-versa.
32
  ///
33
  /// This class is mainly used for working with the Unicode Windows APIs
34
  /// and probably won't be of much use anywhere else ???
35
{
36
public:
37
  static void convert(const std::string& utf8String, UTF32String& utf32String);
38
    /// Converts the given UTF-8 encoded string into an UTF-32 encoded wide string.
39
40
  static void convert(const char* utf8String,  std::size_t length, UTF32String& utf32String);
41
    /// Converts the given UTF-8 encoded character sequence into an UTF-32 encoded wide string.
42
43
  static void convert(const char* utf8String, UTF32String& utf32String);
44
    /// Converts the given zero-terminated UTF-8 encoded character sequence into an UTF-32 encoded wide string.
45
46
  static void convert(const std::string& utf8String, UTF16String& utf16String);
47
    /// Converts the given UTF-8 encoded string into an UTF-16 encoded wide string.
48
49
  static void convert(const char* utf8String,  std::size_t length, UTF16String& utf16String);
50
    /// Converts the given UTF-8 encoded character sequence into an UTF-16 encoded wide string.
51
52
  static void convert(const char* utf8String, UTF16String& utf16String);
53
    /// Converts the given zero-terminated UTF-8 encoded character sequence into an UTF-16 encoded wide string.
54
55
  static void convert(const UTF16String& utf16String, std::string& utf8String);
56
    /// Converts the given UTF-16 encoded wide string into an UTF-8 encoded string.
57
58
  static void convert(const UTF32String& utf32String, std::string& utf8String);
59
    /// Converts the given UTF-32 encoded wide string into an UTF-8 encoded string.
60
61
  static void convert(const UTF16Char* utf16String,  std::size_t length, std::string& utf8String);
62
    /// Converts the given zero-terminated UTF-16 encoded wide character sequence into an UTF-8 encoded string.
63
64
  static void convert(const UTF32Char* utf16String, std::size_t length, std::string& utf8String);
65
    /// Converts the given zero-terminated UTF-32 encoded wide character sequence into an UTF-8 encoded string.
66
67
  static void convert(const UTF16Char* utf16String, std::string& utf8String);
68
    /// Converts the given UTF-16 encoded zero terminated character sequence into an UTF-8 encoded string.
69
70
  static void convert(const UTF32Char* utf32String, std::string& utf8String);
71
    /// Converts the given UTF-32 encoded zero terminated character sequence into an UTF-8 encoded string.
72
73
  template <typename F, typename T>
74
  static void toUTF32(const F& f, T& t)
75
  {
76
    convert(f, t);
77
  }
78
79
  template <typename F, typename T>
80
  static void toUTF32(const F& f, std::size_t l, T& t)
81
  {
82
    convert(f, l, t);
83
  }
84
85
  template <typename F, typename T>
86
  static void toUTF16(const F& f, T& t)
87
  {
88
    convert(f, t);
89
  }
90
91
  template <typename F, typename T>
92
  static void toUTF16(const F& f, std::size_t l, T& t)
93
  {
94
    convert(f, l, t);
95
  }
96
97
  template <typename F, typename T>
98
  static void toUTF8(const F& f, T& t)
99
0
  {
100
0
    convert(f, t);
101
0
  }
102
103
  template <typename F, typename T>
104
  static void toUTF8(const F& f, std::size_t l, T& t)
105
0
  {
106
0
    convert(f, l, t);
107
0
  }
Unexecuted instantiation: void Poco::UnicodeConverter::toUTF8<unsigned short const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(unsigned short const* const&, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)
Unexecuted instantiation: void Poco::UnicodeConverter::toUTF8<wchar_t const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(wchar_t const* const&, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)
108
109
  template <typename T>
110
  static T to(const char* pChar)
111
0
  {
112
0
    T utfStr;
113
0
    Poco::UnicodeConverter::convert(pChar, utfStr);
114
0
    return utfStr;
115
0
  }
116
117
118
  template <typename T>
119
  static T to(const std::string& str)
120
  {
121
    T utfStr;
122
    Poco::UnicodeConverter::convert(str, utfStr);
123
    return utfStr;
124
  }
125
126
  template <typename T>
127
  static std::size_t UTFStrlen(const T* ptr)
128
    /// Returns the length (in characters) of a zero-terminated UTF string.
129
0
  {
130
0
    if (ptr == nullptr) return 0;
131
0
    const T* p;
132
0
    for (p = ptr; *p; ++p);
133
0
    return p - ptr;
134
0
  }
Unexecuted instantiation: unsigned long Poco::UnicodeConverter::UTFStrlen<unsigned short>(unsigned short const*)
Unexecuted instantiation: unsigned long Poco::UnicodeConverter::UTFStrlen<wchar_t>(wchar_t const*)
135
};
136
137
138
} // namespace Poco
139
140
141
#endif // Foundation_UnicodeConverter_INCLUDED