MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / UTF8to16

Function UTF8to16

samples/shared/strtools.cpp:91–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91std::wstring UTF8to16(const char * in)
92{
93 std::wstring out;
94 unsigned int codepoint = 0;
95 int following = 0;
96 for ( ; in && *in != 0; ++in )
97 {
98 unsigned char ch = *in;
99 if (ch <= 0x7f)
100 {
101 codepoint = ch;
102 following = 0;
103 }
104 else if (ch <= 0xbf)
105 {
106 if (following > 0)
107 {
108 codepoint = (codepoint << 6) | (ch & 0x3f);
109 --following;
110 }
111 }
112 else if (ch <= 0xdf)
113 {
114 codepoint = ch & 0x1f;
115 following = 1;
116 }
117 else if (ch <= 0xef)
118 {
119 codepoint = ch & 0x0f;
120 following = 2;
121 }
122 else
123 {
124 codepoint = ch & 0x07;
125 following = 3;
126 }
127 if (following == 0)
128 {
129 if (codepoint > 0xffff)
130 {
131 out.append(1, static_cast<wchar_t>(0xd800 + (codepoint >> 10)));
132 out.append(1, static_cast<wchar_t>(0xdc00 + (codepoint & 0x03ff)));
133 }
134 else
135 out.append(1, static_cast<wchar_t>(codepoint));
136 codepoint = 0;
137 }
138 }
139 return out;
140}
141
142
143// --------------------------------------------------------------------

Callers 7

Path_SetWorkingDirectoryFunction · 0.70
Path_IsDirectoryFunction · 0.70
Path_ExistsFunction · 0.70
Path_ReadBinaryFileFunction · 0.70
Path_WriteBinaryFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected