in C#, the @ operator lets you have a string where it ignores escape characters like \ and some other shit, I think.
This would be helpful when building regex strings, file paths, and so on.
Because
var/x = @"\your\regex\here" looks better without double backslashes
think they call it a "verbatim string literal"
ID:2169988
Nov 7 2016, 9:16 pm
|
|||||||
Resolved
| |||||||
Nov 8 2016, 11:03 am
|
|
I still want more escape codes speaking of escapes.
|
+1 from me
Escaping square brackets in byond regex is hilarious. You gotta triple escape that shit. \\\[foo |
Dart has something similar: the r"..." operator for a raw string. I like the idea of something like this. I'll just have to give some thought to how it'd go in.
|
one idea could be to expand on the string document syntax,
{"this ignores new lines and double quotes"} |
In response to Super Saiyan X
|
|
Super Saiyan X wrote:
one idea could be to expand on the string document syntax, +1. |
Not a fan of the double brace for this, mostly just because that's a heck of a lot of braces. I think I'd much prefer r or @, and given how the latter won't screw up any 4Ks, I think I like that better.
|
I think @ would probably the better option, seeing how
var t = r"dfhjsdhfkjsd" |
In response to Lummox JR
|
|
@{"a string with "quoted text",
spans multiple lines,
doesn't allow [string] interpolation,
and doesn't \ escape \ backslashes."}
(pretend [string] isn't made darker) |
This is on the list for 512, so I'm just thinking over how it's going to work. I can see a use case for including " in a string like that, so I'm wondering if I should support @"..." and @{"..."}, and maybe for good measure it would be a good idea to allow for an arbitrary delimiter, like @|...| or @(delim)...delim. Lack of escapes means this should be chosen carefully.
|
In response to Lummox JR
|
|
I like @(arbitrary delimiter)actual string here(arbitrary delimiter). I'm not sure if the parentheses around the closing string are necessary, but I think it looks a tiny bit cleaner.
|
There was more to implementing this than I thought, but it's done. There are three formats:
// simple; no newlines I have changes ready to go for prettyref.js, the site, and also the editor in DM. (Gads was the editor a pain.) One nice thing that falls out of this is improved strings in .dms files--but they won't be recognized by pre-512 clients. I've also modified the regex documentation to suggest using raw strings, since they're easier to write than trying to worry about escaping everything. |
Lummox JR resolved issue with message:
DM now supports a raw string format, starting with the @ character. There are three formats: @"..." which cannot include newlines, @{"..."} which can, and @(XYZ)...XYZ (where XYZ can be almost anything) which is the same. Raw strings will not parse backslash escapes, or embedded [] expressions. These are very useful for creating regular expressions. |