D - verbatim string literals (feature request)
- Chris Lajoie (35/35) Mar 12 2004 Hi,
- Andy Friesen (5/17) Mar 12 2004 There are two ways to do this in D. One is r"This string is verbatim",
- Chris Lajoie (12/27) Mar 13 2004 in
- Andy Friesen (3/12) Mar 13 2004 It's in the "Lexical" section. Scroll to "String Literals"
- Piotr Fusik (20/27) Mar 13 2004 This is obviously not C#'s original idea. Personally I think that using ...
- C. Sauls (12/13) Mar 13 2004 The one place I find myself using them very often is in printing
Hi, escape characters have no effect, and strings can span multiple lines. The reason I want this is because regular expressions that have backslashes in them must be converted so they use a double backslash instead. This also means that regular expressions can be copied directly out of a D file without modification. This isn't a big deal for regexps that have two or three backslash characters, but the kind of regular expressions I often work with are 100 characters or more (22 backslash chars in one I just looked at). The spanning multiple lines I don't use, and may not be a good idea, them in D as well. --------------------- string a = "hello, world"; // hello, world string b = "hello, world"; // hello, world string c = "hello \t world"; // hello world string d = "hello \t world"; // hello \t world string e = "Joe said \"Hello\" to me"; // Joe said "Hello" to me string f = "Joe said ""Hello"" to me"; // Joe said "Hello" to me string g = "\\\\server\\share\\file.txt"; // \\server\share\file.txt string h = "\\server\share\file.txt"; // \\server\share\file.txt string i = "one\ntwo\nthree"; string j = "one two three"; --------------------- Can anyone think of any disadvantages to verbatim strings? The ' ' char is also wide and unmistakable; not to mention it isn't being used (afaik) for anything else in D. Also, what are your thoughts on the line spanning? Personally, I think it could get confusing. This seems like it would be a fairly simple thing to impliment in the compiler, although I am not familiar with the structure of the compiler so I could be wrong. Chris
Mar 12 2004
Chris Lajoie wrote:Hi, escape characters have no effect, and strings can span multiple lines. The reason I want this is because regular expressions that have backslashes in them must be converted so they use a double backslash instead. This also means that regular expressions can be copied directly out of a D file without modification. This isn't a big deal for regexps that have two or three backslash characters, but the kind of regular expressions I often work with are 100 characters or more (22 backslash chars in one I just looked at). The spanning multiple lines I don't use, and may not be a good idea, them in D as well.There are two ways to do this in D. One is r"This string is verbatim", the other is using backquotes: `Look at me!` All D string literals can span lines, I believe. -- andy
Mar 12 2004
whichHi,Theescape characters have no effect, and strings can span multiple lines.inreason I want this is because regular expressions that have backslashesalsothem must be converted so they use a double backslash instead. Thisormeans that regular expressions can be copied directly out of a D file without modification. This isn't a big deal for regexps that have twoworkthree backslash characters, but the kind of regular expressions I oftenidea,with are 100 characters or more (22 backslash chars in one I just looked at). The spanning multiple lines I don't use, and may not be a goodseeAfter having read the documentation I never found anything regarding verbatim strings. Can you point me to where they are discussed? It's certainly possible I missed something, I skimmed most of it. Thanks! Christhem in D as well.There are two ways to do this in D. One is r"This string is verbatim", the other is using backquotes: `Look at me!` All D string literals can span lines, I believe.
Mar 13 2004
Chris Lajoie wrote:It's in the "Lexical" section. Scroll to "String Literals" -- andyThere are two ways to do this in D. One is r"This string is verbatim", the other is using backquotes: `Look at me!` All D string literals can span lines, I believe.After having read the documentation I never found anything regarding verbatim strings. Can you point me to where they are discussed? It's certainly possible I missed something, I skimmed most of it. Thanks!
Mar 13 2004
them in D as well.character is a bad idea and I prefer D's 'r'. For your information, here's how Perl does it: q/String that spans multiple lines and may contain embedded \ characters/ Note that you may choose one from many available delimiter characters: ', ", /, If that's still not enough, you can use the so-called "here document": <<EOF blah blah blah all characters are available: ' " / { } EOF (use any text for EOF).Can anyone think of any disadvantages to verbatim strings?inside verbatim strings at all (I don't remember).The ' ' char is also wide and unmistakable; not to mention it isn't being used (afaik) for anything else in D.This is a drawback. In the future it could be used for something more useful than verbatim strings.Also, what are your thoughts on the line spanning? Personally, I think it could get confusing.It is sometimes useful, but rarely. Well, D's r"" and `` are enough for me.
Mar 13 2004
Piotr Fusik wrote:It is sometimes useful, but rarely.The one place I find myself using them very often is in printing usage/help messages. Ie: void usage() { printf(r"Usage: program [options] -1 Option 1 -2 Option 2 -N Option N "); } -C. Sauls -Invironz
Mar 13 2004