I've given some thought to this kind of string literal in the past (for my imaginary programming language). I want a syntax
something like this:
var xml = """<element attr="content">
""" <body>
""" </body>
"""</element>
""";
This would give you the string:
<element attr="content">
<body>
</body>
</element>(no newline)
If you wanted a newline at the end, you'd do this:
var xml = """<element attr="content">
""" <body>
""" </body>
"""</element>
"""
""";
Basically the end delimiter of the string would be the last """. You could concatenate two strings like so:
var xml = """<element attr="content">
""" <body>
""" </body>
"""</element>
"""
""" // this string ended on this line
+
"""<element attr="content">
""" <body>
""" </body>
"""</element>
"""
"""; // this string ended on this line
This could use the same logic for using
at least three quotes as the indicator that it's a multiline string.
Please, tear this apart and offer improvements.
Edit: this is conceptually similar to Zig's multiline literal: https://ziglang.org/documentation/master/#Multiline-String-L...
Please, tear this apart and offer improvements.
Edit: this is conceptually similar to Zig's multiline literal: https://ziglang.org/documentation/master/#Multiline-String-L...