Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/util/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::wstring widen(const char *s)
#endif
}

std::string narrow(const std::wstring &s)
std::string narrow(std::wstring_view s)
{
#ifdef _WIN32

Expand All @@ -84,7 +84,7 @@ std::string narrow(const std::wstring &s)
#endif
}

std::wstring widen(const std::string &s)
std::wstring widen(std::string_view s)
{
#ifdef _WIN32

Expand Down Expand Up @@ -188,7 +188,7 @@ static void utf16_append_code(unsigned int code, std::wstring &result)
/// \par parameters: String in UTF-8 format
/// \return String in UTF-16 format. The encoding follows the endianness of the
/// architecture iff swap_bytes is true.
std::wstring utf8_to_utf16_native_endian(const std::string &in)
std::wstring utf8_to_utf16_native_endian(std::string_view in)
{
std::wstring result;
result.reserve(in.size());
Expand All @@ -202,7 +202,7 @@ std::wstring utf8_to_utf16_native_endian(const std::string &in)
/// Convert UTF8-encoded string to UTF-32 with architecture-native endianness.
/// \par parameters: String in UTF-8 format
/// \return String in UTF-32 format.
std::u32string utf8_to_utf32(const std::string &utf8_str)
std::u32string utf8_to_utf32(std::string_view utf8_str)
{
std::u32string result;
result.reserve(utf8_str.size());
Expand Down Expand Up @@ -347,7 +347,7 @@ std::string utf16_native_endian_to_java(const char16_t ch)
/// \param in: String in UTF-16 (native endianness) format
/// \return Valid Java string literal in US-ASCII format, with \\uxxxx escapes
/// for other characters
std::string utf16_native_endian_to_java_string(const std::wstring &in)
std::string utf16_native_endian_to_java_string(std::wstring_view in)
{
std::ostringstream result;
const std::locale loc;
Expand Down
21 changes: 11 additions & 10 deletions src/util/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ Author: Daniel Kroening, kroening@kroening.com

#include <algorithm>
#include <string>
#include <string_view>
#include <vector>

// we follow the ideas suggested at
// http://www.utf8everywhere.org/

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);
std::string narrow(const wchar_t *);
std::wstring widen(const char *);
std::string narrow(std::wstring_view);
std::wstring widen(std::string_view);

// This removes the need to have a #ifdef whenever using std::fstream.
#ifdef _WIN32
Expand All @@ -28,16 +29,16 @@ std::wstring widen(const std::string &s);
# define widen_if_needed(s) (s)
#endif

std::string utf32_native_endian_to_utf8(const std::basic_string<char32_t> &s);
std::string utf32_native_endian_to_utf8(const std::basic_string<char32_t> &);

/// \param utf8_str: UTF-8 string
/// \return UTF-32 encoding of the string
std::u32string utf8_to_utf32(const std::string &utf8_str);
std::u32string utf8_to_utf32(std::string_view utf8_str);

std::wstring utf8_to_utf16_native_endian(const std::string &in);
std::string utf16_native_endian_to_java(const char16_t ch);
std::string utf16_native_endian_to_java(const std::wstring &in);
std::string utf16_native_endian_to_java_string(const std::wstring &in);
std::wstring utf8_to_utf16_native_endian(std::string_view);
std::string utf16_native_endian_to_java(const char16_t);
std::string utf16_native_endian_to_java(std::wstring_view);
std::string utf16_native_endian_to_java_string(std::wstring_view);

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

Expand Down
Loading