openMSX
Classes | Typedefs | Functions
StringStorage.hh File Reference
#include <cstdlib>
#include <cstring>
#include <memory>
#include <string_view>
Include dependency graph for StringStorage.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  FreeStringStorage
 StringStorage: Acts like a 'const char*', but in addition calls free() when the pointer goes out of scope. More...
 

Typedefs

using StringStorage = std::unique_ptr< char, FreeStringStorage >
 

Functions

StringStorage allocate_string_storage (size_t size)
 Allocate a 'StringStorage' large enough for 'size' characters. More...
 
StringStorage allocate_c_string (std::string_view s)
 Allocate memory for and copy a c-string (zero-terminated string). More...
 

Typedef Documentation

◆ StringStorage

using StringStorage = std::unique_ptr<char, FreeStringStorage>

Definition at line 17 of file StringStorage.hh.

Function Documentation

◆ allocate_c_string()

StringStorage allocate_c_string ( std::string_view  s)
inline

Allocate memory for and copy a c-string (zero-terminated string).

This function is similar to strdup(), except that this function:

  • takes a 'string_view' instead of a 'const char*' parameter.
  • returns a 'StringStorage' instead of 'char*'.

Definition at line 32 of file StringStorage.hh.

References allocate_string_storage(), and utf8::unchecked::size().

◆ allocate_string_storage()

StringStorage allocate_string_storage ( size_t  size)
inline

Allocate a 'StringStorage' large enough for 'size' characters.

Definition at line 22 of file StringStorage.hh.

References utf8::unchecked::size().

Referenced by allocate_c_string(), make_string_storage(), and TemporaryString::TemporaryString().