cprover
unicode.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_UNICODE_H
11 #define CPROVER_UTIL_UNICODE_H
12 
13 #include <algorithm>
14 #include <string>
15 #include <vector>
16 
17 // we follow the ideas suggested at
18 // http://www.utf8everywhere.org/
19 
20 std::string narrow(const wchar_t *s);
21 std::wstring widen(const char *s);
22 std::string narrow(const std::wstring &s);
23 std::wstring widen(const std::string &s);
24 
25 std::string
26 utf32_native_endian_to_utf8(const std::basic_string<unsigned int> &s);
27 
28 std::wstring utf8_to_utf16_native_endian(const std::string &in);
29 std::string utf16_native_endian_to_java(const char16_t ch);
30 std::string utf16_native_endian_to_java(const std::wstring &in);
31 std::string utf16_native_endian_to_java_string(const std::wstring &in);
32 
33 std::vector<std::string> narrow_argv(int argc, const wchar_t **argv_wide);
34 
38 std::string utf16_native_endian_to_utf8(char16_t utf16_char);
39 
42 std::string utf16_native_endian_to_utf8(const std::u16string &utf16_str);
43 
48 char16_t codepoint_hex_to_utf16_native_endian(const std::string &hex);
49 
53 std::string codepoint_hex_to_utf8(const std::string &hex);
54 
55 template <typename It>
56 std::vector<const char *> to_c_str_array(It b, It e)
57 {
58  // Assumes that walking the range will be faster than repeated allocation
59  std::vector<const char *> ret(std::distance(b, e) + 1, nullptr);
60  std::transform(b, e, std::begin(ret), [] (const std::string & s)
61  {
62  return s.c_str();
63  });
64  return ret;
65 }
66 
67 #endif // CPROVER_UTIL_UNICODE_H
codepoint_hex_to_utf16_native_endian
char16_t codepoint_hex_to_utf16_native_endian(const std::string &hex)
Definition: unicode.cpp:374
utf16_native_endian_to_java_string
std::string utf16_native_endian_to_java_string(const std::wstring &in)
Escapes non-printable characters, whitespace except for spaces, double quotes and backslashes.
Definition: unicode.cpp:346
utf16_native_endian_to_utf8
std::string utf16_native_endian_to_utf8(char16_t utf16_char)
Definition: unicode.cpp:355
narrow_argv
std::vector< std::string > narrow_argv(int argc, const wchar_t **argv_wide)
Definition: unicode.cpp:157
narrow
std::string narrow(const wchar_t *s)
Definition: unicode.cpp:32
widen
std::wstring widen(const char *s)
Definition: unicode.cpp:57
to_c_str_array
std::vector< const char * > to_c_str_array(It b, It e)
Definition: unicode.h:56
codepoint_hex_to_utf8
std::string codepoint_hex_to_utf8(const std::string &hex)
Definition: unicode.cpp:380
utf16_native_endian_to_java
std::string utf16_native_endian_to_java(const char16_t ch)
Definition: unicode.cpp:331
utf8_to_utf16_native_endian
std::wstring utf8_to_utf16_native_endian(const std::string &in)
Convert UTF8-encoded string to UTF-16 with architecture-native endianness.
Definition: unicode.cpp:201
utf32_native_endian_to_utf8
std::string utf32_native_endian_to_utf8(const std::basic_string< unsigned int > &s)
Definition: unicode.cpp:145