/src/vlc/contrib/x86_64-unknown-linux-gnu/include/ebml/EbmlUnicodeString.h
Line | Count | Source |
1 | | /**************************************************************************** |
2 | | ** libebml : parse EBML files, see http://embl.sourceforge.net/ |
3 | | ** |
4 | | ** <file/class description> |
5 | | ** |
6 | | ** Copyright (C) 2002-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | | ** |
24 | | ** See http://www.gnu.org/licenses/lgpl-2.1.html 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$ |
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 | | |
46 | | namespace libebml { |
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 | | */ |
53 | | class EBML_DLL_API UTFstring { |
54 | | public: |
55 | | using value_type = wchar_t; |
56 | | |
57 | | UTFstring() = default; |
58 | | UTFstring(const wchar_t *); // should be NULL terminated |
59 | | UTFstring(const UTFstring &); |
60 | | UTFstring(std::wstring const &); |
61 | | |
62 | | virtual ~UTFstring(); |
63 | | bool operator==(const UTFstring&) const; |
64 | | inline bool operator!=(const UTFstring &cmp) const |
65 | 0 | { |
66 | 0 | return !(*this == cmp); |
67 | 0 | } |
68 | | UTFstring & operator=(const UTFstring &); |
69 | | UTFstring & operator=(const wchar_t *); |
70 | | UTFstring & operator=(wchar_t); |
71 | | |
72 | | /// Return length of string |
73 | 0 | size_t length() const {return _Length;} |
74 | | |
75 | | operator const wchar_t*() const; |
76 | 0 | const wchar_t* c_str() const {return _Data;} |
77 | | |
78 | 8.45k | const std::string & GetUTF8() const {return UTF8string;} |
79 | | void SetUTF8(const std::string &); |
80 | | |
81 | | #if defined(EBML_STRICT_API) |
82 | | private: |
83 | | #else |
84 | | protected: |
85 | | #endif |
86 | | size_t _Length{0}; ///< length of the UCS string excluding the \0 |
87 | | wchar_t* _Data{nullptr}; ///< internal UCS representation |
88 | | std::string UTF8string; |
89 | | static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2); |
90 | | void UpdateFromUTF8(); |
91 | | void UpdateFromUCS2(); |
92 | | }; |
93 | | |
94 | | |
95 | | /*! |
96 | | \class EbmlUnicodeString |
97 | | \brief Handle all operations on a Unicode string EBML element |
98 | | \note internally treated as a string made of wide characters (ie UCS-2 or UCS-4 depending on the machine) |
99 | | */ |
100 | | class EBML_DLL_API EbmlUnicodeString : public EbmlElement { |
101 | | public: |
102 | | EbmlUnicodeString(); |
103 | | EbmlUnicodeString(const UTFstring & DefaultValue); |
104 | | EbmlUnicodeString(const EbmlUnicodeString & ElementToClone) = default; |
105 | | |
106 | | ~EbmlUnicodeString() override = default; |
107 | | |
108 | 0 | bool ValidateSize() const override {return IsFiniteSize();} // any size is possible |
109 | | filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; |
110 | | filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; |
111 | | filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; |
112 | | |
113 | | EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code |
114 | | operator const UTFstring &() const; |
115 | | |
116 | | EbmlUnicodeString &SetValue(UTFstring const &NewValue); |
117 | | EbmlUnicodeString &SetValueUTF8(std::string const &NewValue); |
118 | | UTFstring GetValue() const; |
119 | | std::string GetValueUTF8() const; |
120 | | |
121 | | void SetDefaultValue(UTFstring &); |
122 | | |
123 | | const UTFstring & DefaultVal() const; |
124 | | |
125 | 0 | bool IsDefaultValue() const override { |
126 | 0 | return (DefaultISset() && Value == DefaultValue); |
127 | 0 | } |
128 | | |
129 | | #if defined(EBML_STRICT_API) |
130 | | private: |
131 | | #else |
132 | | protected: |
133 | | #endif |
134 | | UTFstring Value; /// The actual value of the element |
135 | | UTFstring DefaultValue; |
136 | | }; |
137 | | |
138 | | } // namespace libebml |
139 | | |
140 | | #endif // LIBEBML_UNICODE_STRING_H |