pdfmm 0.9.20
Public Member Functions | Static Public Member Functions | List of all members
mm::PdfString Class Referencefinal

#include <PdfString.h>

Inheritance diagram for mm::PdfString:
mm::PdfDataProvider

Public Member Functions

 PdfString ()
 
 PdfString (const std::string_view &view)
 
 PdfString (const PdfString &rhs)
 
bool IsHex () const
 
bool IsUnicode () const
 
const std::string & GetString () const
 
void Write (PdfOutputDevice &device, PdfWriteMode writeMode, const PdfEncrypt *encrypt) const
 
const PdfStringoperator= (const PdfString &rhs)
 
bool operator== (const PdfString &rhs) const
 
bool operator!= (const PdfString &rhs) const
 
virtual void Write (PdfOutputDevice &device, PdfWriteMode writeMode, const PdfEncrypt *encrypt) const =0
 

Static Public Member Functions

static PdfString FromRaw (const std::string_view &view, bool hex=true)
 
static PdfString FromHexData (const std::string_view &hexView, PdfEncrypt *encrypt=nullptr)
 

Additional Inherited Members

- Protected Member Functions inherited from mm::PdfDataProvider
 PdfDataProvider ()
 

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]

PdfString::PdfString ( )

Create an empty string

◆ PdfString() [2/3]

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

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

Parameters
viewthe string to copy

◆ 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,
PdfEncrypt encrypt = nullptr 
)
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 std::string_view &  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()

const string & 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 mm::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)

◆ IsUnicode()

bool PdfString::IsUnicode ( ) const

PdfStrings are either PdfDocEncoded, or Unicode encoded (UTF-16BE or UTF-8) strings.

This function returns true if this is an Unicode string object.

Returns
true if this is an Unicode string.

◆ operator!=()

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

Comparison operator

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

◆ operator=()

const 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

◆ Write()

void PdfString::Write ( PdfOutputDevice device,
PdfWriteMode  writeMode,
const PdfEncrypt encrypt 
) const
virtual

Write this PdfString in PDF format to a PdfOutputDevice.

Parameters
devicethe output device.
writeModeadditional options for writing this object
encryptan encryption object which is used to encrypt this object, or nullptr to not encrypt this object

Implements mm::PdfDataProvider.