1

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.

Anon
  • 2,267
  • 3
  • 34
  • 51
  • please explain what you are trying to do first – folibis Jul 05 '22 at 07:50
  • @folibis I am trying to embed a multiline string in qbs so I do not have to define it in an seperate external file that will need to be imported, opened, read, and closed. – Anon Jul 05 '22 at 08:20

1 Answers1

2

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.

  • What is the traditional way of escaping newlines? – Anon Jul 05 '22 at 09:59
  • I would just concatenate the strings. See also the ES5-related answers in https://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript – jobor Jul 06 '22 at 07:33