-
Notifications
You must be signed in to change notification settings - Fork 7
/
char_utf8.cpp
39 lines (29 loc) · 885 Bytes
/
char_utf8.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <string>
#include "utf8.h"
#include "char_utf8.h"
/*
character conversion (<-> utf-8 encoding)
copyright (c) 2015 squell <[email protected]>
use, modification, copying and distribution of this software is permitted
under the conditions described in the file 'COPYING'.
*/
namespace charset {
template<> std::wstring conv<utf8>::decode(const char* s, size_t len)
{
std::wstring build;
build.reserve(len);
::utf8::decode(s, s+len, std::back_inserter(build));
return build;
}
template<> std::string conv<utf8>::encode(const void* p, size_t len)
{
const wchar_t* s = (wchar_t*)p;
std::string build;
build.reserve(len);
::utf8::encode(s, s+len, std::back_inserter(build));
return build;
}
} // end of namespace