#include <QoreString.h>
Public Member Functions | |
DLLLOCAL | TempEncodingHelper (const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) |
converts the given string to the required encoding if necessary | |
DLLLOCAL | TempEncodingHelper () |
creates an empty TempEncodingHelperObject that may be initialized with TempEncodingHelper::set() later | |
DLLLOCAL | ~TempEncodingHelper () |
deletes any temporary string being managed by the object | |
DLLLOCAL int | set (const QoreString *s, const QoreEncoding *qe, ExceptionSink *xsink) |
discards any current state and sets and converts (if necessary) a new string to the desired encoding | |
DLLLOCAL bool | is_temp () const |
returns true if a temporary string is being managed | |
DLLLOCAL const QoreString * | operator-> () |
returns the string being managed | |
DLLLOCAL const QoreString * | operator* () |
returns the string being managed | |
DLLLOCAL | operator bool () const |
returns false if the object is empty (for example, if a Qore-language exception was thrown in the constructor), true if not | |
DLLLOCAL char * | giveBuffer () |
returns a char pointer of the string, the caller owns the pointer returned (it must be manually freed) |
this class calls QoreString::convertEncoding() if necessary and manages any temporary string created by this call. the destructor will delete any temporary string if necessary. Note that the constructor may add Qore-language exception information to the "xsink" parameter in case character set encoding conversion was necessary and failed
// ensure a string is in UTF-8 encoding TempEncodingHelper utf8_str(str, QCS_UTF8, xsink); if (!str) // !str is only true if an exception has been thrown in the conversion return 0; printf("%s\n", utf8_str->getBuffer());
DLLLOCAL TempEncodingHelper::TempEncodingHelper | ( | const QoreString * | s, | |
const QoreEncoding * | qe, | |||
ExceptionSink * | xsink | |||
) | [inline] |
converts the given string to the required encoding if necessary
s | a pointer to the QoreString input value | |
qe | the QoreEncoding required | |
xsink | if an error occurs, the Qore-language exception information will be added here |
DLLLOCAL char* TempEncodingHelper::giveBuffer | ( | ) | [inline] |
returns a char pointer of the string, the caller owns the pointer returned (it must be manually freed)
References QoreString::getBuffer(), and QoreString::giveBuffer().
DLLLOCAL TempEncodingHelper::operator bool | ( | ) | const [inline] |
returns false if the object is empty (for example, if a Qore-language exception was thrown in the constructor), true if not
DLLLOCAL int TempEncodingHelper::set | ( | const QoreString * | s, | |
const QoreEncoding * | qe, | |||
ExceptionSink * | xsink | |||
) | [inline] |
discards any current state and sets and converts (if necessary) a new string to the desired encoding
s | a pointer to the QoreString input value | |
qe | the QoreEncoding required | |
xsink | if an error occurs, the Qore-language exception information will be added here |