cprover
unicode.cpp File Reference
#include "unicode.h"
#include <cstring>
#include <locale>
#include <iomanip>
#include <sstream>
#include <cstdint>
Include dependency graph for unicode.cpp:

Go to the source code of this file.

Functions

std::string narrow (const wchar_t *s)
 
std::wstring widen (const char *s)
 
std::string narrow (const std::wstring &s)
 
std::wstring widen (const std::string &s)
 
static void utf8_append_code (unsigned int c, std::string &result)
 Appends a unicode character to a utf8-encoded string. More...
 
std::string utf32_native_endian_to_utf8 (const std::basic_string< unsigned int > &s)
 
std::vector< std::string > narrow_argv (int argc, const wchar_t **argv_wide)
 
static void utf16_append_code (unsigned int code, std::wstring &result)
 
std::wstring utf8_to_utf16_native_endian (const std::string &in)
 Convert UTF8-encoded string to UTF-16 with architecture-native endianness. More...
 
static void utf16_native_endian_to_java (const wchar_t ch, std::ostringstream &result, const std::locale &loc)
 
std::string utf16_native_endian_to_java (const wchar_t ch)
 
std::string utf16_native_endian_to_java (const std::wstring &in)
 

Function Documentation

◆ narrow() [1/2]

std::string narrow ( const wchar_t *  s)

◆ narrow() [2/2]

std::string narrow ( const std::wstring &  s)

Definition at line 71 of file unicode.cpp.

References r.

◆ narrow_argv()

std::vector<std::string> narrow_argv ( int  argc,
const wchar_t **  argv_wide 
)

Definition at line 146 of file unicode.cpp.

References narrow().

Referenced by main().

◆ utf16_append_code()

static void utf16_append_code ( unsigned int  code,
std::wstring &  result 
)
static

Definition at line 160 of file unicode.cpp.

Referenced by utf8_to_utf16_native_endian().

◆ utf16_native_endian_to_java() [1/3]

static void utf16_native_endian_to_java ( const wchar_t  ch,
std::ostringstream &  result,
const std::locale &  loc 
)
static
Parameters
chUTF-16 character in architecture-native endianness encoding
resultstream to receive string in US-ASCII format, with \uxxxx escapes for other characters
loclocale to check for printable characters

Definition at line 253 of file unicode.cpp.

References loc.

Referenced by expr2javat::convert_constant(), utf16_constant_array_to_java(), and utf16_native_endian_to_java().

◆ utf16_native_endian_to_java() [2/3]

std::string utf16_native_endian_to_java ( const wchar_t  ch)
Parameters
chUTF-16 character in architecture-native endianness encoding
Returns
String in US-ASCII format, with \uxxxx escapes for other characters

Definition at line 292 of file unicode.cpp.

References loc, and utf16_native_endian_to_java().

◆ utf16_native_endian_to_java() [3/3]

std::string utf16_native_endian_to_java ( const std::wstring &  in)
Parameters
inString in UTF-16 (native endianness) format
Returns
String in US-ASCII format, with \uxxxx escapes for other characters

Definition at line 302 of file unicode.cpp.

References loc, and utf16_native_endian_to_java().

◆ utf32_native_endian_to_utf8()

std::string utf32_native_endian_to_utf8 ( const std::basic_string< unsigned int > &  s)
Parameters
sUTF-32 encoded wide string
Returns
utf8-encoded string with the same unicode characters as the input.

Definition at line 134 of file unicode.cpp.

References utf8_append_code().

Referenced by append_universal_char(), convert_one_string_literal(), and make_identifier().

◆ utf8_append_code()

static void utf8_append_code ( unsigned int  c,
std::string &  result 
)
static

Appends a unicode character to a utf8-encoded string.

parameters: character to append, string to append to

Definition at line 107 of file unicode.cpp.

Referenced by utf32_native_endian_to_utf8().

◆ 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.

parameters: String in UTF-8 format
Returns
String in UTF-16 format. The encoding follows the endianness of the architecture iff swap_bytes is true.

Definition at line 190 of file unicode.cpp.

References size_type(), and utf16_append_code().

Referenced by delete_directory(), and get_or_create_string_literal_symbol().

◆ widen() [1/2]

◆ widen() [2/2]

std::wstring widen ( const std::string &  s)

Definition at line 88 of file unicode.cpp.

References r.