#include "xstring.h"

XString::XString()
    : XAsset()
    , mString("")
{

}

XString::XString(const QString aString)
    : XAsset()
    , mString(aString)
{

}

XString::~XString()
{

}

QString XString::GetString() const
{
    return mString;
}

void XString::SetString(const QString& aString)
{
    mString = aString;
}

QString XString::ParseCustom(QDataStream *aStream)
{
    QString result;
    char currentChar;

    *aStream >> currentChar;
    while (currentChar != '\0')
    {
        result += currentChar;

        *aStream >> currentChar;
    }
    return result;
}

XStringArray* XString::ParseArray(QDataStream *aStream, int aCount)
{
    XStringArray* result = new XStringArray();

    for (int i = 0; i < aCount; i++)
    {
        XString* string = new XString();
        string->ParseCustom(aStream);

        result->append(string);
    }

    return result;
}

void XString::Clear()
{
    mString = "";
}

void XString::ParseData(QDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        mString = ParseCustom(aStream);
    }
}

