EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utfUtils.h File Reference
#include <string>
Include dependency graph for utfUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::u16string utf8to16 (std::string &str)
 
std::string utf16to8 (std::u16string &str)
 

Function Documentation

std::string utf16to8 ( std::u16string &  str)

Convert a UTF16 string to a UTF8 string

Parameters
strThe UTF16 string.
Returns
The UTF8 string. Returns an empty string on failure.

Definition at line 309 of file utfUtils.cpp.

References UTFCodeParser::addChar(), and UTFCodeParser::getUTF8().

Referenced by UnmarshalStream::LoadWStringUCS2(), and UnmarshalStream::LoadWStringUCS2Char().

310 {
311  std::string out;
312  UTFCodeParser code;
313  for (char c : str)
314  {
315  int res = code.addChar(c);
316  if (res == -1)
317  {
318  // There was an error.
319  return "";
320  }
321  if (res == 0)
322  {
323  out += code.getUTF8();
324  }
325  }
326  return out;
327 }
std::string getUTF8()
Definition: utfUtils.cpp:218
int addChar(char c)
Definition: utfUtils.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

std::u16string utf8to16 ( std::string &  str)

Convert a UTF8 string to a UTF16 string

Parameters
strThe UTF8 string.
Returns
The UTF16 string. Returns an empty string on failure.

Definition at line 289 of file utfUtils.cpp.

References UTFCodeParser::addChar(), and UTFCodeParser::getUTF16().

Referenced by PasswordModule::GeneratePassHash().

290 {
291  std::u16string out;
292  UTFCodeParser code;
293  for (char16_t c : str)
294  {
295  int res = code.addChar(c);
296  if (res == -1)
297  {
298  // There was an error.
299  return u"";
300  }
301  if (res == 0)
302  {
303  out += code.getUTF16();
304  }
305  }
306  return out;
307 }
int addChar(char c)
Definition: utfUtils.cpp:116
std::u16string getUTF16()
Definition: utfUtils.cpp:231

Here is the call graph for this function:

Here is the caller graph for this function: