#include "UIMLUtils.h"

int* getUIMLTargetAddress(Framework::Text address, int& addressLength)
{
    int* result = 0;
    if (address.has(','))
    {
        Framework::Text* part1
            = address.getTeilText(0, address.positionOf(",", 0) + 1);
        Framework::Text* part2 = address.getTeilText(
            address.positionOf(",", 0) + 1, address.positionOf(",", 1));
        Framework::Text* part3 = address.getTeilText(
            address.positionOf(",", 1) + 1, address.positionOf(",", 2));
        if (address.has(":"))
        {
            Framework::Text* part4 = address.getTeilText(
                address.positionOf(",", 2) + 1, address.positionOf(":"));
            Framework::Text* part5
                = address.getTeilText(address.positionOf(":") + 1);
            addressLength = 5;
            result = new int[5];
            result[4] = (int)*part5;
            result[3] = (int)*part4;
            part5->release();
            part4->release();
        }
        else
        {
            Framework::Text* part4
                = address.getTeilText(address.positionOf(",", 2) + 1);
            addressLength = 4;
            result = new int[4];
            result[3] = (int)*part4;
            part4->release();
        }
        result[0] = (int)*part1;
        result[1] = (int)*part2;
        result[2] = (int)*part3;
        part1->release();
        part2->release();
        part3->release();
    }
    else
    {
        if (address.has(":"))
        {
            Framework::Text* part1
                = address.getTeilText(0, address.positionOf(":"));
            Framework::Text* part2
                = address.getTeilText(address.positionOf(":") + 1);
            addressLength = 2;
            result = new int[2];
            result[0] = (int)*part1;
            result[1] = (int)*part2;
            part1->release();
            part2->release();
        }
        else
        {
            addressLength = 1;
            result = new int[1];
            result[0] = (int)address;
        }
    }
    return result;
}
