PoDoFo  1.0.0-dev
Public Member Functions | Static Public Member Functions | List of all members
PoDoFo::PdfString Class Referencefinal

A string that can be written to a PDF document. More...

#include <PdfString.h>

Inheritance diagram for PoDoFo::PdfString:
PoDoFo::PdfDataMember PoDoFo::PdfDataProvider< PdfString >

Public Member Functions

 PdfString ()
 Create an empty string.
 
 PdfString (charbuff &&buff, bool isHex)
 
template<std::size_t N>
 PdfString (const char(&str)[N])
 
template<typename T , typename = std::enable_if_t<std::is_same_v<T, const char*>>>
 PdfString (T str)
 
 PdfString (const std::string_view &view)
 Construct a new PdfString from a utf-8 string The input string will be copied. More...
 
 PdfString (const std::string &str)
 
 PdfString (std::string &&str)
 Construct a new PdfString from a utf-8 string. More...
 
 PdfString (const PdfString &rhs)
 Copy an existing PdfString. More...
 
 PdfString (PdfString &&rhs) noexcept
 
bool IsHex () const
 Check if this is a hex string. More...
 
PdfStringCharset GetCharset () const
 A PdfString can be an unevaluated raw buffer, or can be a Ascii, PdfDocEncoding or Unicode string.
 
bool IsEmpty () const
 
bool IsStringEvaluated () const
 True if the raw data buffer has been evaluated to a string.
 
std::string_view GetString () const
 The contents of the string as UTF-8 string. More...
 
std::string_view GetRawData () const
 
void Write (OutputStream &stream, PdfWriteFlags writeMode, const PdfStatefulEncrypt *encrypt, charbuff &buffer) const
 
PdfStringoperator= (const PdfString &rhs)
 Copy an existing PdfString. More...
 
PdfStringoperator= (PdfString &&rhs) noexcept
 
bool operator== (const PdfString &rhs) const
 Comparison operator. More...
 
bool operator== (const char *str) const
 
bool operator== (const std::string &str) const
 
bool operator== (const std::string_view &view) const
 
bool operator!= (const PdfString &rhs) const
 Comparison operator. More...
 
bool operator!= (const char *str) const
 
bool operator!= (const std::string &str) const
 
bool operator!= (const std::string_view &view) const
 
 operator std::string_view () const
 Default cast to utf8 string view.
 
- Public Member Functions inherited from PoDoFo::PdfDataProvider< PdfString >
std::string ToString (PdfWriteFlags flags=PdfWriteFlags::None) const
 Converts the current object into a string representation which can be written directly to a PDF file on disc. More...
 
void ToString (std::string &str, PdfWriteFlags flags=PdfWriteFlags::None) const
 

Static Public Member Functions

static PdfString FromRaw (const bufferview &view, bool hex=true)
 Construct a new PdfString from an utf-8 encoded string. More...
 
static PdfString FromHexData (const std::string_view &hexView, const PdfStatefulEncrypt *encrypt={ })
 Set hex-encoded data as the strings data. More...
 

Detailed Description

A string that can be written to a PDF document.

If it contains binary data it is automatically converted into a hex string, otherwise a normal PDF string is written to the document.

PdfString is an implicitly shared class. As a reason it is very fast to copy PdfString objects.

Constructor & Destructor Documentation

◆ PdfString() [1/3]

PoDoFo::PdfString::PdfString ( const std::string_view &  view)

Construct a new PdfString from a utf-8 string The input string will be copied.

Parameters
strthe string to copy

◆ PdfString() [2/3]

PdfString::PdfString ( std::string &&  str)

Construct a new PdfString from a utf-8 string.

Parameters
strthe string to move from

◆ PdfString() [3/3]

PdfString::PdfString ( const PdfString rhs)

Copy an existing PdfString.

Parameters
rhsanother PdfString to copy

Member Function Documentation

◆ FromHexData()

PdfString PdfString::FromHexData ( const std::string_view &  hexView,
const PdfStatefulEncrypt *  encrypt = { } 
)
static

Set hex-encoded data as the strings data.

Parameters
hexViewmust be hex-encoded data.
lenlength of the hex-encoded data.
encryptif !nullptr, assume the hex data is encrypted and should be decrypted after hex-decoding.

◆ FromRaw()

PdfString PdfString::FromRaw ( const bufferview view,
bool  hex = true 
)
static

Construct a new PdfString from an utf-8 encoded string.

Parameters
viewa buffer
hextrue if the string should be written as hex string

◆ GetString()

string_view PdfString::GetString ( ) const

The contents of the string as UTF-8 string.

The string's contents are always returned as UTF-8 by this function. Works for Unicode strings and for non-Unicode strings.

This is the preferred way to access the string's contents.

Returns
the string's contents always as UTF-8

◆ IsHex()

bool PoDoFo::PdfString::IsHex ( ) const
inline

Check if this is a hex string.

If true the data will be hex-encoded when the string is written to a PDF file.

Returns
true if this is a hex string.
See also
GetString() will return the raw string contents (not hex-encoded)

◆ operator!=()

bool PdfString::operator!= ( const PdfString rhs) const

Comparison operator.

Parameters
rhscompare to this string object
Returns
true if strings have different contents

◆ operator=()

PdfString & PdfString::operator= ( const PdfString rhs)

Copy an existing PdfString.

Parameters
rhsanother PdfString to copy
Returns
this object

◆ operator==()

bool PdfString::operator== ( const PdfString rhs) const

Comparison operator.

UTF-8 and strings of the same data compare equal. Whether the string will be written out as hex is not considered - only the real "text" is tested for equality.

Parameters
rhscompare to this string object
Returns
true if both strings have the same contents

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