How to do multiline strings in QBS?

44 Views Asked by At

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.

1

There are 1 best solutions below

2
Christian Kandeler On

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.