UTF8 - Simple Library for Internationalization
Loading...
Searching...
No Matches
utf8::buffer Class Reference

A simple buffer for caching values returned by Windows API. More...

#include <winutf8.h>

Public Member Functions

 buffer (size_t size_)
 
 ~buffer ()
 Destructor.
 
 buffer (const buffer &other)
 Copy constructor.
 
bufferoperator= (const buffer &rhs)
 Principal assignment operator.
 
bufferoperator= (const std::string &rhs)
 String assignment operator.
 
 operator wchar_t * ()
 Return a pointer to buffer.
 
 operator std::string () const
 Convert buffer to an UTF-8 encoded string.
 
DWORD size () const
 Return buffer size.
 

Detailed Description

A simple buffer for caching values returned by Windows API.

Many Windows API function return output strings as UTF-16 encoded strings.

This class provides conversion operators that make it easier to go back to UTF-8 encoded strings.

Here is a simple usage example:

utf8::buffer path (_MAX_PATH);
utf8::buffer fname (_MAX_PATH);
GetTempPath (path.size (), path);
GetTempFileName (path, L"ABC", 1, fname);
string result = fname;
A simple buffer for caching values returned by Windows API.
Definition winutf8.h:160
std::string GetTempPath()
Convenience wrapper for GetTempPath
Definition win.cpp:171
std::string GetTempFileName(const std::string &path, const std::string &prefix, UINT unique)
Convenience wrapper for GetTempFileName
Definition win.cpp:188

Without this class, the equivalent code would be something like:

wstring wpath (_MAX_PATH, L'\0');
wstring wfname (_MAX_PATH, L'\0');
GetTempPath (wpath.size (), const_cast<wchar_t*>(wpath.data ()));
GetTempFileName (wpath.c_str(), L"ABC", 1, const_cast<wchar_t*>(wfname.data ()));
string result = narrow(wfname);
std::string narrow(const wchar_t *s, size_t nch)
Conversion from wide character to UTF-8.
Definition utf8.cpp:52

Constructor & Destructor Documentation

◆ buffer()

utf8::buffer::buffer ( size_t  size_)
explicit

Constructor

Parameters
size_buffer size in characters (not bytes)

The documentation for this class was generated from the following files: