/**
* Transcodes a 16-bit Unicode string into UTF-8.
- * @param src the 16-bit string to transcode
+ *
+ * @param src the 16-bit string to transcode
+ * @param use_malloc true iff the result should be allocated with malloc, false to use new
* @return a UTF-8 string allocated by the Xerces memory manager
*/
- extern XMLTOOL_API char* toUTF8(const XMLCh* src);
+ extern XMLTOOL_API char* toUTF8(const XMLCh* src, bool use_malloc=false);
/**
* Transcodes a UTF-8 string into 16-bit Unicode.
- * @param src the UTF-8 string to transcode
+ *
+ * @param src the UTF-8 string to transcode
+ * @param use_malloc true iff the result should be allocated with malloc, false to use new
* @return a 16-bit Unicode string allocated by the Xerces memory manager
*/
- extern XMLTOOL_API XMLCh* fromUTF8(const char* src);
+ extern XMLTOOL_API XMLCh* fromUTF8(const char* src, bool use_malloc=false);
/**
* Writes a Unicode string to an ASCII stream by transcoding to UTF8.
XMLCh* m_buf;
};
+ /**
+ * An auto_ptr that uses array delete on its contents.
+ *
+ * @param T type of pointer to wrap
+ */
+ template <typename T> class auto_arrayptr
+ {
+ T* m_ptr;
+
+ auto_arrayptr(const auto_arrayptr<T>&);
+ auto_arrayptr<T>& operator=(const auto_arrayptr<T>&);
+ public:
+ /**
+ * Constructor.
+ *
+ * @param ptr pointer to wrap
+ */
+ auto_arrayptr(T* ptr) : m_ptr(ptr) {
+ }
+
+ /**
+ * Destructor, uses array delete operation on wrapped pointer.
+ */
+ ~auto_arrayptr() {
+ delete[] m_ptr;
+ }
+
+ /**
+ * Returns the wrapped pointer.
+ * @return the wrapped pointer
+ */
+ const T* get() const {
+ return m_ptr;
+ }
+
+ /**
+ * Returns the wrapped pointer and transfers ownership of it to the caller.
+ * @return the wrapped pointer
+ */
+ T* release() {
+ T* temp=m_ptr; m_ptr=NULL; return temp;
+ }
+ };
};
#endif /* __xmltooling_unicode_h__ */