Commit eb046ae1 authored by Steve Lhomme's avatar Steve Lhomme

v2: more unicode string handling

fix the PostCreate (not shared because of the inherited call)

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@114 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent 30a14ed2
......@@ -286,7 +286,18 @@ static filepos_t UpdateSizeInt(ebml_integer *Element, bool_t bKeepIntact, bool_t
static void PostCreateInt(ebml_element *Element)
{
INHERITED(Element,ebml_element_vmt,Node_ClassId(Element))->PostCreate(Element);
INHERITED(Element,ebml_element_vmt,EBML_INTEGER_CLASS)->PostCreate(Element);
Element->DefaultSize = 1;
if (Element->bDefaultIsSet)
{
Element->bValueIsSet = 1;
((ebml_integer*)Element)->Value = Element->Context->DefaultValue;
}
}
static void PostCreateSignedInt(ebml_element *Element)
{
INHERITED(Element,ebml_element_vmt,EBML_SINTEGER_CLASS)->PostCreate(Element);
Element->DefaultSize = 1;
if (Element->bDefaultIsSet)
{
......@@ -328,7 +339,7 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,ReadData,ReadDataSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderDataSignedInt)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSizeSignedInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateInt)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateSignedInt)
META_END_CONTINUE(EBML_ELEMENT_CLASS)
META_START_CONTINUE(EBML_BOOLEAN_CLASS)
......
......@@ -163,7 +163,17 @@ static bool_t IsDefaultValue(const ebml_string *Element)
static void PostCreateString(ebml_element *Element)
{
INHERITED(Element,ebml_element_vmt,Node_ClassId(Element))->PostCreate(Element);
INHERITED(Element,ebml_element_vmt,EBML_STRING_CLASS)->PostCreate(Element);
if (Element->bDefaultIsSet)
{
Element->bValueIsSet = 1;
((ebml_string*)Element)->Buffer = strdup((const char *)Element->Context->DefaultValue);
}
}
static void PostCreateUniString(ebml_element *Element)
{
INHERITED(Element,ebml_element_vmt,EBML_UNISTRING_CLASS)->PostCreate(Element);
if (Element->bDefaultIsSet)
{
Element->bValueIsSet = 1;
......@@ -192,5 +202,5 @@ META_VMT(TYPE_FUNC,ebml_element_vmt,UpdateSize,UpdateSize)
#if defined(CONFIG_EBML_WRITING)
META_VMT(TYPE_FUNC,ebml_element_vmt,RenderData,RenderData)
#endif
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateString)
META_VMT(TYPE_FUNC,ebml_element_vmt,PostCreate,PostCreateUniString)
META_END(EBML_ELEMENT_CLASS)
......@@ -303,6 +303,8 @@ namespace LIBEBML_NAMESPACE {
const char* DebugName() const;
inline ebml_element *GetNode() { return Node; }
protected:
EbmlElement(const ebml_context &, ebml_element *WithNode = NULL);
ebml_element *Node;
......
......@@ -42,10 +42,15 @@ namespace LIBEBML_NAMESPACE {
public:
UTFstring();
UTFstring(const wchar_t *);
UTFstring(const UTFstring &);
~UTFstring();
const wchar_t* c_str() const;
bool operator==(const UTFstring&) const;
UTFstring & operator=(const UTFstring &);
operator const wchar_t*() const;
size_t length() const;
protected:
wchar_t *Buffer;
};
class EbmlUnicodeString : public EbmlElement {
......
......@@ -576,8 +576,7 @@ assert(0);
bool EbmlMaster::PushElement(EbmlElement & element)
{
assert(0);
return false;
return EBML_MasterAppend(Node,element.GetNode())==ERR_NONE;
}
EbmlElement *EbmlMaster::AddNewElt(const EbmlCallbacks & Kind)
......@@ -758,10 +757,10 @@ assert(0);
return INVALID_FILEPOS_T;
}
EbmlUnicodeString & EbmlUnicodeString::operator=(const UTFstring &)
EbmlUnicodeString & EbmlUnicodeString::operator=(const UTFstring &val)
{
assert(0);
return *static_cast<EbmlUnicodeString*>(NULL);
EBML_UniStringSetValue((ebml_string*)Node,val);
return *this;
}
EbmlUnicodeString::operator const UTFstring() const
......@@ -780,14 +779,42 @@ assert(0);
/*****************
* UTFstring
****************/
UTFstring::UTFstring(const wchar_t*)
UTFstring::UTFstring(const wchar_t* value)
:Buffer(NULL)
{
assert(0);
size_t Size = wcslen(value);
Buffer = new wchar_t[(Size+1)*sizeof(wchar_t)];
if (Buffer)
memcpy(Buffer,value,(Size+1)*sizeof(wchar_t));
}
UTFstring::UTFstring()
:Buffer(NULL)
{
assert(0);
}
UTFstring::UTFstring(const UTFstring &Clone)
:Buffer(NULL)
{
size_t Size = wcslen(Clone.Buffer);
Buffer = new wchar_t[(Size+1)*sizeof(wchar_t)];
if (Buffer)
memcpy(Buffer,Clone.Buffer,(Size+1)*sizeof(wchar_t));
}
UTFstring::~UTFstring()
{
delete[] Buffer;
}
UTFstring & UTFstring::operator=(const UTFstring & Clone)
{
delete[] Buffer;
size_t Size = wcslen(Clone.Buffer);
Buffer = new wchar_t[(Size+1)*sizeof(wchar_t)];
if (Buffer)
memcpy(Buffer,Clone.Buffer,(Size+1)*sizeof(wchar_t));
return *this;
}
const wchar_t* UTFstring::c_str() const
......@@ -798,14 +825,16 @@ assert(0);
UTFstring::operator const wchar_t*() const
{
assert(0);
return NULL;
return Buffer;
}
bool UTFstring::operator==(const UTFstring&) const
bool UTFstring::operator==(const UTFstring &Cmp) const
{
assert(0);
return false;
size_t Size1 = wcslen(Buffer);
size_t Size2 = wcslen(Cmp.Buffer);
if (Size1 != Size2)
return false;
return memcmp(Buffer,Cmp.Buffer,(Size1+1)*sizeof(wchar_t))==0;
}
size_t UTFstring::length() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment