#ifndef H_CORAL_LIB_UCS4STRING
#define H_CORAL_LIB_UCS4STRING
// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

#include <iconv.h>

#include <string>

#include <coral/lib/python_support.h>
#include <coral/coral.h>

namespace coral {
	class EXPORT_coral unicodestring {
	public:
		// note that std::wstring is wrong here
		// iconv and wchar_t have nothing in common
		typedef std::string ucs4;
	private:
		ucs4 u;
		CORAL_HIDDEN std::string helper(iconv_t) const throw (std::exception);
		static CORAL_HIDDEN ucs4 h(iconv_t, const char*) throw (std::exception);
	public:
		unicodestring() : u("") { };
		unicodestring(const char*, bool is_utf8) throw (std::exception);
		unicodestring(const std::string&, bool is_utf8) throw (std::exception);
		unicodestring(PyObject*) throw (std::exception);
		~unicodestring() throw () { };
		std::string toUTF8() const throw (std::exception);
		PyObject* toPython() const throw (std::exception);
		std::string toNative() const throw (std::exception);
		static CORAL_HIDDEN void initUnicodeCharacterConversions();
		bool operator==(const unicodestring& uc) const {
			return u == uc.u;
		}
		bool operator!=(const unicodestring& uc) const {
			return u != uc.u;
		}
		bool operator<(const unicodestring& uc) const {
			return u < uc.u;
		}
		bool operator<=(const unicodestring& uc) const {
			return u <= uc.u;
		}
		bool operator>(const unicodestring& uc) const {
			return u > uc.u;
		}
		bool operator>=(const unicodestring& uc) const {
			return u >= uc.u;
		}

		void swap(unicodestring& uc) {
			u.swap(uc.u);
		}
		unicodestring::ucs4::size_type size() const throw ();

		friend std::ostream& operator<<(std::ostream &output,
						const unicodestring& a) {
			return output << a.toUTF8();
		}
		bool operator<(const unicodestring& s) {
			return this->u < s.u;
		}
		void operator+(const unicodestring& s) {
			this->u += s.u;
		}
		bool empty() const throw () {
			return u.empty();
		}
	};

}

#endif

