/*
 * Copyright (C) 2007-2023 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/text.h"
#include "bu/textbuilder.h"

#include "bu/exceptionbase.h"

#include <string.h>

Bu::Text::Text() :
    pData( NULL ),
    bIsBmpOnly( true ),
    iSize( 0 )
{
}

Bu::Text::Text( const Text &rSrc ) :
    pData( NULL ),
    bIsBmpOnly( rSrc.bIsBmpOnly ),
    iSize( rSrc.iSize )
{
    pData = new CodePoint[iSize];
    memcpy( pData, rSrc.pData, sizeof(CodePoint)*iSize );
}

Bu::Text::Text( const TextBuilder &rSrc ) :
    pData( NULL ),
    bIsBmpOnly( true ),
    iSize( rSrc.getSize() )
{
    pData = new CodePoint[iSize];
    
}

Bu::Text::~Text()
{
    delete[] pData;
    pData = NULL;
}

bool Bu::Text::isEmpty() const
{
    return (iSize == 0);
}

bool Bu::Text::isBmpOnly() const
{
    return bIsBmpOnly;
}

int32_t Bu::Text::getSize() const
{
    return iSize;
}

int32_t Bu::Text::getSizeInBytes() const
{
    return iSize*sizeof(CodePoint);
}

Bu::CodePoint Bu::Text::operator[]( int32_t iIndex ) const
{
    if( iIndex < 0 || iIndex >= iSize )
        throw Bu::ExceptionBase("Index out of range.");
    return pData[iIndex];
}

Bu::CodePoint *Bu::Text::getData() const
{
    return pData;
}

