TXmlEngString Class Reference

#include <xml/utils/xmlengxestrings.h>

Link against: xmlengineutils.lib

class TXmlEngString : public TXmlEngConstString

Inherits from

Detailed Description

General-purpose string used in libxml2-based API's.

This class holds a zero-terminated sequence of bytes (c-style string). It is commonly used to represent a sequence of UTF-8 characters.

TXmlEngString objects should be treated as if they were pointers. The destructor for TXmlEngString does nothing. This means that the developer needs to free the memory allocated by TXmlEngString by calling Free() or Close() (Close() is an alias for Free()) and to do so only once.

The reason for this design is that the goal is to have a string class that is as small as a one-pointer sized object that is mostly stored on the stack, not on the heap (and therefore no additional memory allocation is required). It is also as flexible as possible to allow developers to create their own derived classes which may provide auto_ptr-like or reference counting solutions.

The contents of this class can be replaced, destroyed, copied and converted to c strings and Symbian descriptor types.

The contents of TXmlEngString may also be modified with AppendL().

When TXmlEngString is the return type in libxml2 based API's, this usually indicates that a string has been newly allocated, which should be freed by the method caller.

Constructor & Destructor Documentation

TXmlEngString ( )

TXmlEngString()[inline]

Default constructor

TXmlEngString ( char * )

TXmlEngString(char *aString)[inline]

Constructs a new string from a given c string. Ownership is transferred and the string must be freed with Free() or Close().

ParameterDescription
aStringA heap-based c string

TXmlEngString ( const TXmlEngConstString & )

TXmlEngString(const TXmlEngConstString &aStr)[protected, inline]

Constructs the object from a TXmlEngConstString

ParameterDescription
aStrThe string to initialize from

Member Function Documentation

AllocAndFreeL ( )

IMPORT_C HBufC *AllocAndFreeL()

Creates a new UTF-16 HBufC from the UTF-8 string contents and transfers ownership of the string. The string held by this object is freed.

Typical use:
      ...
      HBufC* attrValue = attr.WholeValueCopyL().AllocAndFreeL();
      ...

See also: AllocAndFreeLC()

leave
KErrNoMemory Memory allocation failure
leave
KUriUtilsCannotConvert String cannot be converted

Returns: The copied string

AllocAndFreeLC ( )

IMPORT_C HBufC *AllocAndFreeLC()

Creates a new UTF-16 HBufC from the UTF-8 string contents and transfers ownership of the string. The result is placed on the cleanup stack. The string held by this object is freed.

Typical use:
      ...
      HBufC* attrValue = attr.WholeValueCopyL().AllocAndFreeL();
      ...

See also: AllocAndFreeL()

leave
KErrNoMemory Memory allocation failure
leave
KUriUtilsCannotConvert String cannot be converted

Allocates heap descriptor as AllocLC() and frees internal c-string.

More details in AllocAndFreeL() description.

Returns: The copied string

AppendL ( TXmlEngString )

IMPORT_C voidAppendL(TXmlEngStringaStr)
Appends new text to the string
leave
KErrNoMemory Memory allocation failure
ParameterDescription
aStrThe string to add

AppendL ( TXmlEngString, TXmlEngString )

IMPORT_C voidAppendL(TXmlEngStringaStr1,
TXmlEngStringaStr2
)
Appends new text to the string.
leave
KErrNoMemory Memory allocation failure
ParameterDescription
aStr1The first string to append
aStr2The second string to append

Close ( )

voidClose()[inline]

Frees the string

Free ( )

IMPORT_C voidFree()

Frees the string

PushL ( )

TXmlEngString PushL()[inline]
Pushes this string to the cleanup stack. This must be matched with a corresponding call to CleanupStack::Pop() or CleanupStack::PopAndDestroy().
leave
KErrNoMemory Memory allocation failure

Returns: This object

Set ( char * )

voidSet(char *aStr)[inline]

Reimplemented from TXmlEngConstString::Set(char *)

Sets a new value. The old string is freed. Ownership is transferred and the string must be freed with Free() or Close().

ParameterDescription
aStrThe new string

Set ( TXmlEngString & )

IMPORT_C voidSet(TXmlEngString &aSrc)

Transfers a string and its ownership from another TXmlEngString object. If this object currently stores a string it is freed.

ParameterDescription
aSrcThe source string

SetL ( const TDesC & )

IMPORT_C voidSetL(const TDesC &aDes)
Initializes the string, converting from a UTF-16 descriptor to a UTF-8 zero-terminated string.
leave
  • One of the system-wide error codes

ParameterDescription
aDesThe new value

SetL ( const TDesC8 & )

IMPORT_C voidSetL(const TDesC8 &aDes)
Initializes the string from a descriptor
leave
  • One of the system-wide error codes

ParameterDescription
aDesThe new value