Anon
Anon

Reputation: 2492

How to do multiline strings in QBS?

At the moment, I am using a very ugly solution:

            codeblock(x, "cpp", (function() {/*
union Seed;
union Feed
{
    int     operator+( Feed & ) { return 0     ; };
    QString operator+( Seed & ) { return "feed"; };
};
union Seed
{
    int     operator+( Feed & ) { return 1     ; }
    QString operator+( Seed & ) { return "seed"; }
};
template<typename T0, typename T1> auto sneed() {
    T0 p;
    T1 q;
    return p + q;
}
*/}).toString()
);

Which doesnt bode well for an api.

I have tried using acutes, but they produce an error: Unexpected token

and using line escapes do not preserve the linebreaks:

            codeblock(x, "cpp", '\
union Seed;\
union Feed\
{\
        int     operator+( Feed & ) { return 0     ; };\
        QString operator+( Seed & ) { return "feed"; };\
};\
union Seed\
{\
        int     operator+( Feed & ) { return 1     ; }\
        QString operator+( Seed & ) { return "seed"; }\
};\
template<typename T0, typename T1> auto sneed() {\
        T0 p;\
        T1 q;\
        return p + q;\
}\
'
);

Producing:

union Seed;union Feed{        int     operator+( Feed & ) { return 0     ; };        QString operator+( Seed & ) { return "feed"; };};union Seed{        int     operator+( Feed & ) { return 1     ; }        QString operator+( Seed & ) { return "seed"; }};template<typename T0, typename T1> auto sneed() {        T0 p;        T1 q;        return p + q;}

Qbs uses an older version of Javascript right now, and is also based on QML. I have looked through the docs, but I havn't found anything for multiline strings. My goal is the cleanest code possible, and would rather not have to rely on hack solutions or ugly escapes all over the place.

Thanks.

Upvotes: 1

Views: 50

Answers (1)

Christian Kandeler
Christian Kandeler

Reputation: 831

The traditional JavaScript way of escaping newlines is the way to go as of now. Qbs might switch to a new JS backend in the future, which would make new-ish features available.

Upvotes: 2

Related Questions