1/****************************************************************************
2** libebml : parse EBML files, see http://embl.sourceforge.net/
3**
4** <file/class description>
5**
6** Copyright (C) 2002-2005 Steve Lhomme.  All rights reserved.
7**
8** This file is part of libebml.
9**
10** This library is free software; you can redistribute it and/or
11** modify it under the terms of the GNU Lesser General Public
12** License as published by the Free Software Foundation; either
13** version 2.1 of the License, or (at your option) any later version.
14**
15** This library is distributed in the hope that it will be useful,
16** but WITHOUT ANY WARRANTY; without even the implied warranty of
17** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18** Lesser General Public License for more details.
19**
20** You should have received a copy of the GNU Lesser General Public
21** License along with this library; if not, write to the Free Software
22** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23**
24** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
25**
26** Contact license@matroska.org if any conditions of this licensing are
27** not clear to you.
28**
29**********************************************************************/
30
31/*!
32	\file
33	\version \$Id: EbmlUnicodeString.h 1079 2005-03-03 13:18:14Z robux4 $
34	\author Steve Lhomme     <robux4 @ users.sf.net>
35	\author Moritz Bunkus <moritz @ bunkus.org>
36	\author Jory Stone       <jcsston @ toughguy.net>
37*/
38#ifndef LIBEBML_UNICODE_STRING_H
39#define LIBEBML_UNICODE_STRING_H
40
41#include <string>
42
43#include "EbmlTypes.h"
44#include "EbmlElement.h"
45
46START_LIBEBML_NAMESPACE
47
48/*!
49  \class UTFstring
50  A class storing strings in a wchar_t (ie, in UCS-2 or UCS-4)
51  \note inspired by wstring which is not available everywhere
52*/
53class EBML_DLL_API UTFstring {
54public:
55	typedef wchar_t value_type;
56
57	UTFstring();
58	UTFstring(const wchar_t *); // should be NULL terminated
59	UTFstring(const UTFstring &);
60
61	virtual ~UTFstring();
62	bool operator==(const UTFstring&) const;
63	inline bool operator!=(const UTFstring &cmp) const
64	{
65		return !(*this == cmp);
66	}
67	UTFstring & operator=(const UTFstring &);
68	UTFstring & operator=(const wchar_t *);
69	UTFstring & operator=(wchar_t);
70
71	/// Return length of string
72	size_t length() const {return _Length;}
73
74	operator const wchar_t*() const {return _Data;}
75	const wchar_t* c_str() const {return _Data;}
76
77	const std::string & GetUTF8() const {return UTF8string;}
78	void SetUTF8(const std::string &);
79
80protected:
81	size_t _Length; ///< length of the UCS string excluding the \0
82	wchar_t* _Data; ///< internal UCS representation
83	std::string UTF8string;
84	static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2);
85	void UpdateFromUTF8();
86	void UpdateFromUCS2();
87};
88
89
90/*!
91    \class EbmlUnicodeString
92    \brief Handle all operations on a Unicode string EBML element
93	\note internally treated as a string made of wide characters (ie UCS-2 or UCS-4 depending on the machine)
94*/
95class EBML_DLL_API EbmlUnicodeString : public EbmlElement {
96	public:
97		EbmlUnicodeString();
98		EbmlUnicodeString(const UTFstring & DefaultValue);
99		EbmlUnicodeString(const EbmlUnicodeString & ElementToClone);
100
101		virtual ~EbmlUnicodeString() {}
102
103		bool ValidateSize() const {return true;} // any size is possible
104		uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
105		uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
106		uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
107
108		EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code
109		operator const UTFstring &() const {return Value;}
110
111		void SetDefaultValue(UTFstring & aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
112
113		UTFstring DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
114
115		bool IsDefaultValue() const {
116			return (DefaultISset() && Value == DefaultValue);
117		}
118
119	protected:
120		UTFstring Value; /// The actual value of the element
121		UTFstring DefaultValue;
122};
123
124END_LIBEBML_NAMESPACE
125
126#endif // LIBEBML_UNICODE_STRING_H
127