Beispiel #1
0
QString CodeGenerator::generateSprite(const Sprite *sprite, bool stage)
{
    QString str;
    _eventCounters.clear();
    _indentCounter = 1;

    QStringList *costumeRegSnippet = &_snippets["costume_register"];
    QStringList *constructSnippet = stage ? &_snippets["construct_stage"] : &_snippets["construct"];

    QString costumeRegister;
    for (CostumeVector::const_iterator it = sprite->getCostumeVector()->begin(); it != sprite->getCostumeVector()->end(); it++)
    {
        costumeRegister += indentCode(costumeRegSnippet, 2)
            .replace(QLatin1String("%entity%"), QLatin1String("self"))
            .replace(QLatin1String("%name%"), addQuotes((*it)->getName()))
            .replace(QLatin1String("%file%"), addQuotes((*it)->getFilename()));
    }

    // create class file
    str += indentCode(&_snippets["import"]);
    str += indentCode(&_snippets["class"]).replace(QLatin1String("%name%"), sprite->getName());
    str += indentCode(constructSnippet, 1, costumeRegister);
    str += "%events%\n";

    // check every block for "header"-block
    const DragElemVector *eleVec = sprite->getDragElemVector();
    for(DragElemVector::const_iterator elemIt = eleVec->begin(); elemIt != eleVec->end(); elemIt++)
    {
        if ((*elemIt)->getType() == DraggableElement::Hat)
        {
            str += generateCode(*elemIt, 1) + '\n';
        }
    }

    // add Event registration
    QString events;
    for(QMap<QString, int>::const_iterator eventIt = _eventCounters.constBegin(); eventIt != _eventCounters.constEnd(); eventIt++)
    {
        for(int i = 1; i <= eventIt.value(); i++)
        {
            QString event = indent(2) + _events[eventIt.key()]._register + "\n";
            events += event.replace(QLatin1String("%counter%"), QString::number(i));
        }
    }

    str.replace(QLatin1String("%events%"), events);
    return str;
}
char *buildPostFields(TaskListItem *item)
{

    int str_length = strlen("{") + 1;
    char *ret_value = malloc(str_length * sizeof (char));
    strcpy(ret_value, "{");
    int added = 0;
    if (item != NULL)
    {

        if (item->title != NULL)
        {
            str_length = addQuotes(ret_value);
            str_length += strlen(TITLE_STRING);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, TITLE_STRING);
            addQuotes(ret_value);
            addColon(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(item->title);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, item->title);
            str_length = addQuotes(ret_value);
            added++;
        }

        if (item->id != NULL)
        {
            if (added++ > 0)
                str_length = addComma(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(ID_STRING);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, ID_STRING);
            str_length = addQuotes(ret_value);
            str_length = addColon(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(item->id);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, item->id);
            str_length = addQuotes(ret_value);
        }

        if (item->updated != NULL)
        {
            if (added++ > 0)
                str_length = addComma(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(UPDATED_STRING);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, UPDATED_STRING);
            str_length = addQuotes(ret_value);
            str_length = addColon(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(item->updated);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, item->updated);
            str_length = addQuotes(ret_value);
        }

        if (item->selfLink != NULL)
        {
            if (added++ > 0)
                str_length = addComma(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(SELFLINK_STRING);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, SELFLINK_STRING);
            str_length = addQuotes(ret_value);
            str_length = addColon(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(item->selfLink);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, item->selfLink);
            str_length = addQuotes(ret_value);
        }

        if (item->etag != NULL)
        {
            if (added++ > 0)
                str_length = addComma(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(ETAG_STRING);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, ETAG_STRING);
            str_length = addQuotes(ret_value);
            str_length = addColon(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(item->etag);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, item->etag);
            str_length = addQuotes(ret_value);
        }

        if (item->kind != NULL)
        {
            if (added++ > 0)
                str_length = addComma(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(KIND_STRING);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, KIND_STRING);
            str_length = addQuotes(ret_value);
            str_length = addColon(ret_value);
            str_length = addQuotes(ret_value);
            str_length += strlen(item->kind);
            ret_value = realloc(ret_value, str_length);
            strcat(ret_value, item->kind);
            str_length = addQuotes(ret_value);
        }
    }

    appendString(ret_value, "}");
    return ret_value;
}
Beispiel #3
0
void QueryBuilder::bind(std::string tag, std::string value)
{
    escape(value);
    addQuotes(value);
    replaceTag(tag, value);
}