FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
utf8_tools.cpp
1 /**********************************************************\
2 Original Author: Dan Weatherford
3 Imported with permission by: Richard Bateman (taxilian)
4 
5 Imported: Aug 7, 2010
6 License: Dual license model; choose one of two:
7  New BSD License
8  http://www.opensource.org/licenses/bsd-license.php
9  - or -
10  GNU Lesser General Public License, version 2.1
11  http://www.gnu.org/licenses/lgpl-2.1.html
12 
13 Copyright 2009 Dan Weatherford, Facebook inc
14 \**********************************************************/
15 
16 #ifdef _WIN32
17 #include "win_targetver.h"
18 #include <boost/asio.hpp>
19 #include "win_common.h"
20 #else
21 #include "../3rdParty/utf8/utf8.h"
22 #include <xlocale.h>
23 #include <wctype.h>
24 #endif
25 #include <stdexcept>
26 
27 #include <boost/scoped_array.hpp>
28 #include "precompiled_headers.h" // On windows, everything above this line in PCH
29 
30 #include <limits.h>
31 #include <boost/algorithm/string/case_conv.hpp>
32 
33 #include "utf8_tools.h"
34 
35 namespace FB {
36 
37  std::string wstring_to_utf8(const std::wstring& src) {
38  std::string out_str;
39  std::wstring in_str;
40  utf8::replace_invalid(src.begin(), src.end(), std::back_inserter(in_str));
41 #ifdef _WIN32
42  utf8::utf16to8(in_str.begin(), in_str.end(), std::back_inserter(out_str));
43 #else
44  utf8::utf32to8(in_str.begin(), in_str.end(), std::back_inserter(out_str));
45 #endif
46  return out_str;
47  }
48 
49 
50  std::wstring utf8_to_wstring(const std::string& src) {
51  std::wstring out_str;
52  std::string in_str;
53  utf8::replace_invalid(src.begin(), src.end(), std::back_inserter(in_str));
54 #ifdef _WIN32
55  utf8::utf8to16(in_str.begin(), in_str.end(), std::back_inserter(out_str));
56 #else
57  utf8::utf8to32(in_str.begin(), in_str.end(), std::back_inserter(out_str));
58 #endif
59  return out_str;
60  }
61 
62 
63  std::wstring wstring_tolower(const std::wstring& src) {
64  return boost::algorithm::to_upper_copy(src);
65  }
66 
67 };
68 
std::wstring wstring_tolower(const std::wstring &src)
Converts a std::wstring to lowercase.
Definition: utf8_tools.cpp:63
std::string wstring_to_utf8(const std::wstring &src)
Accepts a std::wstring and returns a UTF8-encoded std::string.
Definition: utf8_tools.cpp:37
std::wstring utf8_to_wstring(const std::string &src)
Accepts a UTF8-encoded std::string and returns a std::wstring.
Definition: utf8_tools.cpp:50