1 /****************************************************************************
2 ** libebml : parse EBML files, see http://embl.sourceforge.net/
4 ** <file/class description>
6 ** Copyright (C) 2002-2005 Steve Lhomme. All rights reserved.
8 ** This file is part of libebml.
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.
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.
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
24 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
26 ** Contact license@matroska.org if any conditions of this licensing are
29 **********************************************************************/
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>
38 #ifndef LIBEBML_UNICODE_STRING_H
39 #define LIBEBML_UNICODE_STRING_H
43 #include "EbmlTypes.h"
44 #include "EbmlElement.h"
46 START_LIBEBML_NAMESPACE
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
53 class EBML_DLL_API UTFstring
{
55 typedef wchar_t value_type
;
58 UTFstring(const wchar_t *); // should be NULL terminated
59 UTFstring(const UTFstring
&);
62 bool operator==(const UTFstring
&) const;
63 inline bool operator!=(const UTFstring
&cmp
) const
65 return !(*this == cmp
);
67 UTFstring
& operator=(const UTFstring
&);
68 UTFstring
& operator=(const wchar_t *);
69 UTFstring
& operator=(wchar_t);
71 /// Return length of string
72 size_t length() const {return _Length
;}
74 operator const wchar_t*() const {return _Data
;}
75 const wchar_t* c_str() const {return _Data
;}
77 const std::string
& GetUTF8() const {return UTF8string
;}
78 void SetUTF8(const std::string
&);
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();
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)
95 class EBML_DLL_API EbmlUnicodeString
: public EbmlElement
{
98 EbmlUnicodeString(const UTFstring
& DefaultValue
);
99 EbmlUnicodeString(const EbmlUnicodeString
& ElementToClone
);
101 virtual ~EbmlUnicodeString() {}
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);
108 EbmlUnicodeString
& operator=(const UTFstring
&); ///< platform dependant code
109 operator const UTFstring
&() const {return Value
;}
111 void SetDefaultValue(UTFstring
& aValue
) {assert(!DefaultIsSet
); DefaultValue
= aValue
; DefaultIsSet
= true;}
113 UTFstring
DefaultVal() const {assert(DefaultIsSet
); return DefaultValue
;}
115 bool IsDefaultValue() const {
116 return (DefaultISset() && Value
== DefaultValue
);
120 UTFstring Value
; /// The actual value of the element
121 UTFstring DefaultValue
;
124 END_LIBEBML_NAMESPACE
126 #endif // LIBEBML_UNICODE_STRING_H