简体   繁体   English

如何在 QBS 中做多行字符串?

[英]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.这对 api 来说不是个好兆头。

I have tried using acutes, but they produce an error: Unexpected token我曾尝试使用锐器,但它们会产生错误: 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. Qbs 现在使用旧版本的 Javascript,并且也是基于 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.谢谢。

The traditional JavaScript way of escaping newlines is the way to go as of now.转义换行符的传统 JavaScript 方式是目前要走的路。 Qbs might switch to a new JS backend in the future, which would make new-ish features available. Qbs 将来可能会切换到新的 JS 后端,这将提供新的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM