Topic: Regex-friendly "raw" string literals


Author: Thorsten Ottosen <thorsten.ottosen@dezide.com>
Date: Sun, 19 Feb 2006 16:47:22 CST
Raw View
Scott Meyers wrote:
> Last September, Marcus posted the following here:

> IMO, it's a lot easier for a non-expert programmer to get this right,
>
>   std::string zipFileRegex("\w\.zip");
>
> than this:
>
>   std::string zipFileRegex("\\w\\.zip");
>
> (As an aside, if the regex above is wrong, that's partly my point.  It's
> hard enough to come up with the right regex in the first place without
> having to simultaneously worry about whether all the regex backslashes have
> been themselves backslashed.)

> Also, my understanding is that the door has closed on core language
> extensions for C++0x.  Is that the case?  If so, presumably there is no
> chance for "raw" string literals to enter C++0x even if somebody writes up
> a proposal, right?

A major concern has been making C++ easier to use and teach, so
the raw strings seems relevant.

However, maybe we don't need a core-language change. Many
languages has a library with a small utility

string escape( const string& );

this can then be called from within the regex constructor.
IIUC, constructing a regex is a fairly heavy operation, so
running escaping a string also should be releatively easy.

-Thorsten

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: petebecker@acm.org (Pete Becker)
Date: Mon, 13 Feb 2006 19:11:47 GMT
Raw View
Francis Glassborow wrote:

> In article <3dadnSiIy65FgHPenZ2dnUVZ_tCdnZ2d@giganews.com>, Pete Becker
> <petebecker@acm.org> writes
>
>>>  Also, my understanding is that the door has closed on core language
>>> extensions for C++0x.  Is that the case?
>>
>>
>> Nope. Get moving!
>
>
> Sorry Pete, but he was effectively correct. The Evolution Group does not
> intend to consider new proposals (unless already covered by existing
> papers).
>
>

The Evolution Working Group is not the only route for language changes.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: Mon, 13 Feb 2006 22:06:17 CST
Raw View
In article <3Yednd-AH6yK0HLeRVn-ig@giganews.com>, Pete Becker
<petebecker@acm.org> writes
>
>The Evolution Working Group is not the only route for language changes.

I think it is for changes to the core of the language.

--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Pete Becker <petebecker@acm.org>
Date: Tue, 14 Feb 2006 09:36:23 CST
Raw View
Francis Glassborow wrote:

> In article <3Yednd-AH6yK0HLeRVn-ig@giganews.com>, Pete Becker
> <petebecker@acm.org> writes
>
>>
>> The Evolution Working Group is not the only route for language changes.
>
>
> I think it is for changes to the core of the language.
>

I think the core group is in charge of the core of the language.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: Tue, 14 Feb 2006 13:06:35 CST
Raw View
In article <mNSdnaFKVMfiV2zenZ2dnUVZ_tudnZ2d@giganews.com>, Pete Becker
<petebecker@acm.org> writes
>Francis Glassborow wrote:
>
>> In article <3Yednd-AH6yK0HLeRVn-ig@giganews.com>, Pete Becker
>><petebecker@acm.org> writes
>>
>>>
>>> The Evolution Working Group is not the only route for language changes.
>>   I think it is for changes to the core of the language.
>>
>
>I think the core group is in charge of the core of the language.

Yes, indeed it is, but under current policy it does not consider new
language features other than those coming out of the evolution group who
are the people tasked with considering proposals for new features.


--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: usenet@aristeia.com (Scott Meyers)
Date: Sat, 11 Feb 2006 07:24:30 GMT
Raw View
Last September, Marcus posted the following here:

   I've seen that the library technical report includes a regular expression
   library.  However, since regular expressions use a lot of backslashes
   (\w, \1, etc.) and they are escape characters in C++ strings, the
   programmer has to write things like this: "\\w" and "\\\\" for regexps
   "\w" and "\\", respectively.  Have raw-strings been considered to
   simplify these cases?

   For example, Python and D work like this:
   r"\w" == "\\w"
   r"c:\tsd" == "c:\\tsd"

   (D has an alternate syntax for this feature, using backticks: `\w`,
   which allow double quotes inside the string)

   C# uses an @ before the string (@"c:\omf" == "c:\\omf").

   IMHO, this kind of lexical sugar makes the language a lot easier to
   work with (at least for those who use regexps and such) and they don't
   complicate the language (it's just a lexical change).

There were no followups, which surprises me, because it seems to me that
supporting "raw" string literals is an excellent way to facilitate
experimentation by non-C++-experts with the regex support in TR1.  My
understanding is that a goal of C++0x is to make C++ easier for non-experts
to use.

IMO, it's a lot easier for a non-expert programmer to get this right,

   std::string zipFileRegex("\w\.zip");

than this:

   std::string zipFileRegex("\\w\\.zip");

(As an aside, if the regex above is wrong, that's partly my point.  It's
hard enough to come up with the right regex in the first place without
having to simultaneously worry about whether all the regex backslashes have
been themselves backslashed.)

I googled around for discussion of unobvious problems arising from adding a
"raw" string literal to C++, but I didn't find anything.  Is there
something I'm overlooking?

Also, my understanding is that the door has closed on core language
extensions for C++0x.  Is that the case?  If so, presumably there is no
chance for "raw" string literals to enter C++0x even if somebody writes up
a proposal, right?

Thanks,

Scott

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: petebecker@acm.org (Pete Becker)
Date: Sat, 11 Feb 2006 18:03:40 GMT
Raw View
Scott Meyers wrote:

>
> IMO, it's a lot easier for a non-expert programmer to get this right,
>
>   std::string zipFileRegex("\w\.zip");
>
> than this:
>
>   std::string zipFileRegex("\\w\\.zip");
>

Agreed. But one of the constraints that we imposed on TR1 was that it
should be implementable without compiler changes, that is, it's supposed
to be entirely library. (There are a few places where an implementation
can do a better job with compiler help, but the requirements were
written so that they can be met without it).

>
> Also, my understanding is that the door has closed on core language
> extensions for C++0x.  Is that the case?

Nope. Get moving!

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Sun, 12 Feb 2006 05:53:37 GMT
Raw View
In article <3dadnSiIy65FgHPenZ2dnUVZ_tCdnZ2d@giganews.com>, Pete Becker
<petebecker@acm.org> writes
>>  Also, my understanding is that the door has closed on core language
>> extensions for C++0x.  Is that the case?
>
>Nope. Get moving!

Sorry Pete, but he was effectively correct. The Evolution Group does not
intend to consider new proposals (unless already covered by existing
papers).


--
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]