@@ -20,10 +20,10 @@ std::string ToUTF8(std::wstring_view wstr)
20
20
std::wstring_convert<std::codecvt_utf8_utf16<char16_t >, char16_t > convert;
21
21
return convert.to_bytes ((char16_t *)wstr.data (), (char16_t *)wstr.data () + wstr.size ());
22
22
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
23
- std::wstring_convert<std::codecvt_utf8<wchar_t >> convert;
23
+ std::wstring_convert<std::codecvt_utf8<wchar_t > > convert;
24
24
return convert.to_bytes (wstr.data (), wstr.data () + wstr.size ());
25
25
#elif defined(_WIN32) || defined(_WIN64)
26
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> convert;
26
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t > > convert;
27
27
return convert.to_bytes (wstr.data (), wstr.data () + wstr.size ());
28
28
#endif
29
29
}
@@ -35,10 +35,10 @@ std::wstring FromUTF8(std::string_view str)
35
35
auto tmp = convert.from_bytes (str.data (), str.data () + str.size ());
36
36
return std::wstring (tmp.data (), tmp.data () + tmp.size ());
37
37
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
38
- std::wstring_convert<std::codecvt_utf8<wchar_t >> convert;
38
+ std::wstring_convert<std::codecvt_utf8<wchar_t > > convert;
39
39
return convert.from_bytes (str.data (), str.data () + str.size ());
40
40
#elif defined(_WIN32) || defined(_WIN64)
41
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> convert;
41
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t > > convert;
42
42
return convert.from_bytes (str.data (), str.data () + str.size ());
43
43
#endif
44
44
}
@@ -132,7 +132,7 @@ std::u16string UTF32toUTF16(std::u32string_view str)
132
132
std::string Base64Encode (std::string_view str)
133
133
{
134
134
const char base64[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ;
135
- const size_t mods[] = { 0 , 2 , 1 };
135
+ const size_t mods[] = {0 , 2 , 1 };
136
136
137
137
size_t ilength = str.length ();
138
138
size_t olength = 4 * ((ilength + 2 ) / 3 );
@@ -162,25 +162,25 @@ std::string Base64Encode(std::string_view str)
162
162
163
163
std::string Base64Decode (std::string_view str)
164
164
{
165
- static const unsigned char base64[256 ] =
166
- {
167
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
168
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
169
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x3e , 0x00 , 0x00 , 0x00 , 0x3f ,
170
- 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39 , 0x3a , 0x3b , 0x3c , 0x3d , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
171
- 0x00 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e ,
172
- 0x0f , 0x10 , 0x11 , 0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 , 0x18 , 0x19 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
173
- 0x00 , 0x1a , 0x1b , 0x1c , 0x1d , 0x1e , 0x1f , 0x20 , 0x21 , 0x22 , 0x23 , 0x24 , 0x25 , 0x26 , 0x27 , 0x28 ,
174
- 0x29 , 0x2a , 0x2b , 0x2c , 0x2d , 0x2e , 0x2f , 0x30 , 0x31 , 0x32 , 0x33 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
175
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
176
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
177
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
178
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
179
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
180
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
181
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
182
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
183
- };
165
+ static const unsigned char base64[256 ] = {
166
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
167
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
168
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x3e , 0x00 ,
169
+ 0x00 , 0x00 , 0x3f , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39 , 0x3a , 0x3b , 0x3c , 0x3d , 0x00 , 0x00 ,
170
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 ,
171
+ 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0x10 , 0x11 , 0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 , 0x18 ,
172
+ 0x19 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x1a , 0x1b , 0x1c , 0x1d , 0x1e , 0x1f , 0x20 , 0x21 ,
173
+ 0x22 , 0x23 , 0x24 , 0x25 , 0x26 , 0x27 , 0x28 , 0x29 , 0x2a , 0x2b , 0x2c , 0x2d , 0x2e , 0x2f , 0x30 ,
174
+ 0x31 , 0x32 , 0x33 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
175
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
176
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
177
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
178
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
179
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
180
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
181
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
182
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
183
+ 0x00 };
184
184
185
185
size_t ilength = str.length ();
186
186
@@ -189,8 +189,10 @@ std::string Base64Decode(std::string_view str)
189
189
190
190
size_t olength = ilength / 4 * 3 ;
191
191
192
- if (str[ilength - 1 ] == ' =' ) olength--;
193
- if (str[ilength - 2 ] == ' =' ) olength--;
192
+ if (str[ilength - 1 ] == ' =' )
193
+ olength--;
194
+ if (str[ilength - 2 ] == ' =' )
195
+ olength--;
194
196
195
197
std::string result;
196
198
result.resize (olength, 0 );
@@ -202,15 +204,18 @@ std::string Base64Decode(std::string_view str)
202
204
uint32_t sextet_c = str[i] == ' =' ? 0 & i++ : base64[(uint8_t )str[i++]];
203
205
uint32_t sextet_d = str[i] == ' =' ? 0 & i++ : base64[(uint8_t )str[i++]];
204
206
205
- uint32_t triple = (sextet_a << 3 * 6 ) + (sextet_b << 2 * 6 ) + (sextet_c << 1 * 6 ) + (sextet_d << 0 * 6 );
206
-
207
- if (j < olength) result[j++] = (triple >> 2 * 8 ) & 0xFF ;
208
- if (j < olength) result[j++] = (triple >> 1 * 8 ) & 0xFF ;
209
- if (j < olength) result[j++] = (triple >> 0 * 8 ) & 0xFF ;
207
+ uint32_t triple =
208
+ (sextet_a << 3 * 6 ) + (sextet_b << 2 * 6 ) + (sextet_c << 1 * 6 ) + (sextet_d << 0 * 6 );
210
209
210
+ if (j < olength)
211
+ result[j++] = (triple >> 2 * 8 ) & 0xFF ;
212
+ if (j < olength)
213
+ result[j++] = (triple >> 1 * 8 ) & 0xFF ;
214
+ if (j < olength)
215
+ result[j++] = (triple >> 0 * 8 ) & 0xFF ;
211
216
}
212
217
213
218
return result;
214
219
}
215
220
216
- }}
221
+ }} // namespace cppbase::encoding
0 commit comments