gcc const fix, converted linefeeds
[shibboleth/cpp-xmltooling.git] / xmltooling / unicode.h
index 50e78f4..b4bd111 100644 (file)
-/*\r
- *  Copyright 2001-2006 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * @file unicode.h\r
- * \r
- * Helper classes and types for manipulating Unicode\r
- */\r
\r
-#if !defined(__xmltooling_unicode_h__)\r
-#define __xmltooling_unicode_h__\r
-\r
-#include <string>\r
-#include <xercesc/util/XMLString.hpp>\r
-#include <xmltooling/base.h>\r
-\r
-using namespace xercesc;\r
-\r
-namespace xmltooling {\r
-    \r
-    #ifdef HAVE_GOOD_STL\r
-        /**\r
-         * An STL string type that supports 16-bit Unicode.\r
-         * Most compilers support this, but various versions of gcc3 do not.\r
-         */\r
-        typedef std::basic_string<XMLCh> xstring;\r
-    #endif\r
-\r
-    /**\r
-     * Transcodes a 16-bit Unicode string into UTF-8.\r
-     * @param src   the 16-bit string to transcode\r
-     * @return      a UTF-8 string allocated by the Xerces memory manager \r
-     */\r
-    extern XMLTOOL_API char* toUTF8(const XMLCh* src);\r
-\r
-    /**\r
-     * Transcodes a UTF-8 string into 16-bit Unicode.\r
-     * @param src   the UTF-8 string to transcode\r
-     * @return      a 16-bit Unicode string allocated by the Xerces memory manager \r
-     */\r
-    extern XMLTOOL_API XMLCh* fromUTF8(const char* src);\r
-\r
-    /**\r
-     * A minimal auto_ptr-like class that can copy or transcode a buffer into\r
-     * the local code page and free the result automatically.\r
-     * \r
-     * Needed because a standard auto_ptr would use delete on the resulting\r
-     * pointer. \r
-     */\r
-    class XMLTOOL_API auto_ptr_char\r
-    {\r
-    public:\r
-        /**\r
-         * Constructor transcodes a 16-bit Unicode string into the local code page (NOT UTF-8) and wraps the result.\r
-         * @param src   the 16-bit string to transcode and wrap\r
-         * @param trim  trims leading/trailing whitespace from the result (defaults to true) \r
-         */\r
-        auto_ptr_char(const XMLCh* src, bool trim=true) : m_buf(XMLString::transcode(src)) {if (trim && m_buf) XMLString::trim(m_buf);}\r
-\r
-        /**\r
-         * Constructor copies a local code page (NOT UTF-8) string and wraps the result.\r
-         * @param src   the local string to copy and wrap\r
-         * @param trim  trims leading/trailing whitespace from the result (defaults to true) \r
-         */\r
-        auto_ptr_char(const char* src, bool trim=true) : m_buf(XMLString::replicate(src)) {if (trim && m_buf) XMLString::trim(m_buf);}\r
-\r
-        /**\r
-         * Destructor frees the wrapped buffer using the Xerces memory manager.\r
-         */\r
-        ~auto_ptr_char() { XMLString::release(&m_buf); }\r
-\r
-        /**\r
-         * Returns the wrapped buffer.\r
-         * @return a null-terminated local code page string\r
-         */\r
-        const char* get() const { return m_buf; }\r
-\r
-        /**\r
-         * Returns the wrapped buffer and transfers ownership of it to the caller.\r
-         * @return a null-terminated local code page string\r
-         */\r
-        char* release() { char* temp=m_buf; m_buf=NULL; return temp; }\r
-\r
-    private:    \r
-        char* m_buf;\r
-    MAKE_NONCOPYABLE(auto_ptr_char);\r
-    };\r
-\r
-    /**\r
-     * A minimal auto_ptr-like class that can copy or transcode a buffer into\r
-     * 16-bit Unicode and free the result automatically.\r
-     * \r
-     * Needed because a standard auto_ptr would use delete on the resulting\r
-     * pointer. \r
-     */\r
-    class XMLTOOL_API auto_ptr_XMLCh\r
-    {\r
-    public:\r
-        /**\r
-         * Constructor transcodes a local code page (NOT UTF-8) string into 16-bit Unicode and wraps the result.\r
-         * @param src   the local string to transcode and wrap\r
-         * @param trim  trims leading/trailing whitespace from the result (defaults to true) \r
-         */\r
-        auto_ptr_XMLCh(const char* src, bool trim=true) : m_buf(XMLString::transcode(src)) {if (trim && m_buf) XMLString::trim(m_buf);}\r
-\r
-        /**\r
-         * Constructor copies a 16-bit Unicode string and wraps the result.\r
-         * @param src   the Unicode string to copy and wrap\r
-         * @param trim  trims leading/trailing whitespace from the result (defaults to true) \r
-         */\r
-        auto_ptr_XMLCh(const XMLCh* src, bool trim=true) : m_buf(XMLString::replicate(src)) {if (trim && m_buf) XMLString::trim(m_buf);}\r
-\r
-        /**\r
-         * Destructor frees the wrapped buffer using the Xerces memory manager.\r
-         */\r
-        ~auto_ptr_XMLCh() { XMLString::release(&m_buf); }\r
-\r
-        /**\r
-         * Returns the wrapped buffer.\r
-         * @return a null-terminated Unicode string\r
-         */\r
-        const XMLCh* get() const { return m_buf; }\r
-        \r
-        /**\r
-         * Returns the wrapped buffer and transfers ownership of it to the caller.\r
-         * @return a null-terminated Unicode string\r
-         */\r
-        XMLCh* release() { XMLCh* temp=m_buf; m_buf=NULL; return temp; }\r
-\r
-    private:\r
-        XMLCh* m_buf;\r
-    MAKE_NONCOPYABLE(auto_ptr_XMLCh);\r
-    };\r
-\r
-};\r
-\r
-#endif /* __xmltooling_unicode_h__ */\r
+/*
+ *  Copyright 2001-2006 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file unicode.h
+ * 
+ * Helper classes and types for manipulating Unicode
+ */
+#if !defined(__xmltooling_unicode_h__)
+#define __xmltooling_unicode_h__
+
+#include <string>
+#include <xercesc/util/XMLString.hpp>
+#include <xmltooling/base.h>
+
+using namespace xercesc;
+
+namespace xmltooling {
+    
+    #ifdef HAVE_GOOD_STL
+        /**
+         * An STL string type that supports 16-bit Unicode.
+         * Most compilers support this, but various versions of gcc3 do not.
+         */
+        typedef std::basic_string<XMLCh> xstring;
+    #endif
+
+    /**
+     * Transcodes a 16-bit Unicode string into UTF-8.
+     * @param src   the 16-bit string to transcode
+     * @return      a UTF-8 string allocated by the Xerces memory manager 
+     */
+    extern XMLTOOL_API char* toUTF8(const XMLCh* src);
+
+    /**
+     * Transcodes a UTF-8 string into 16-bit Unicode.
+     * @param src   the UTF-8 string to transcode
+     * @return      a 16-bit Unicode string allocated by the Xerces memory manager 
+     */
+    extern XMLTOOL_API XMLCh* fromUTF8(const char* src);
+
+    /**
+     * A minimal auto_ptr-like class that can copy or transcode a buffer into
+     * the local code page and free the result automatically.
+     * 
+     * Needed because a standard auto_ptr would use delete on the resulting
+     * pointer. 
+     */
+    class XMLTOOL_API auto_ptr_char
+    {
+    public:
+        /**
+         * Constructor transcodes a 16-bit Unicode string into the local code page (NOT UTF-8) and wraps the result.
+         * @param src   the 16-bit string to transcode and wrap
+         * @param trim  trims leading/trailing whitespace from the result (defaults to true) 
+         */
+        auto_ptr_char(const XMLCh* src, bool trim=true) : m_buf(XMLString::transcode(src)) {if (trim && m_buf) XMLString::trim(m_buf);}
+
+        /**
+         * Constructor copies a local code page (NOT UTF-8) string and wraps the result.
+         * @param src   the local string to copy and wrap
+         * @param trim  trims leading/trailing whitespace from the result (defaults to true) 
+         */
+        auto_ptr_char(const char* src, bool trim=true) : m_buf(XMLString::replicate(src)) {if (trim && m_buf) XMLString::trim(m_buf);}
+
+        /**
+         * Destructor frees the wrapped buffer using the Xerces memory manager.
+         */
+        ~auto_ptr_char() { XMLString::release(&m_buf); }
+
+        /**
+         * Returns the wrapped buffer.
+         * @return a null-terminated local code page string
+         */
+        const char* get() const { return m_buf; }
+
+        /**
+         * Returns the wrapped buffer and transfers ownership of it to the caller.
+         * @return a null-terminated local code page string
+         */
+        char* release() { char* temp=m_buf; m_buf=NULL; return temp; }
+
+    private:    
+        char* m_buf;
+    MAKE_NONCOPYABLE(auto_ptr_char);
+    };
+
+    /**
+     * A minimal auto_ptr-like class that can copy or transcode a buffer into
+     * 16-bit Unicode and free the result automatically.
+     * 
+     * Needed because a standard auto_ptr would use delete on the resulting
+     * pointer. 
+     */
+    class XMLTOOL_API auto_ptr_XMLCh
+    {
+    public:
+        /**
+         * Constructor transcodes a local code page (NOT UTF-8) string into 16-bit Unicode and wraps the result.
+         * @param src   the local string to transcode and wrap
+         * @param trim  trims leading/trailing whitespace from the result (defaults to true) 
+         */
+        auto_ptr_XMLCh(const char* src, bool trim=true) : m_buf(XMLString::transcode(src)) {if (trim && m_buf) XMLString::trim(m_buf);}
+
+        /**
+         * Constructor copies a 16-bit Unicode string and wraps the result.
+         * @param src   the Unicode string to copy and wrap
+         * @param trim  trims leading/trailing whitespace from the result (defaults to true) 
+         */
+        auto_ptr_XMLCh(const XMLCh* src, bool trim=true) : m_buf(XMLString::replicate(src)) {if (trim && m_buf) XMLString::trim(m_buf);}
+
+        /**
+         * Destructor frees the wrapped buffer using the Xerces memory manager.
+         */
+        ~auto_ptr_XMLCh() { XMLString::release(&m_buf); }
+
+        /**
+         * Returns the wrapped buffer.
+         * @return a null-terminated Unicode string
+         */
+        const XMLCh* get() const { return m_buf; }
+        
+        /**
+         * Returns the wrapped buffer and transfers ownership of it to the caller.
+         * @return a null-terminated Unicode string
+         */
+        XMLCh* release() { XMLCh* temp=m_buf; m_buf=NULL; return temp; }
+
+    private:
+        XMLCh* m_buf;
+    MAKE_NONCOPYABLE(auto_ptr_XMLCh);
+    };
+
+};
+
+#endif /* __xmltooling_unicode_h__ */