C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Regex-friendly "raw" string literals

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Scott Meyers
Guest





PostPosted: Sat Feb 11, 2006 8:06 am    Post subject: Regex-friendly "raw" string literals Reply with quote



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 ]
Back to top
Pete Becker
Guest





PostPosted: Sat Feb 11, 2006 6:06 pm    Post subject: Re: Regex-friendly "raw" string literals Reply with quote



Scott Meyers wrote:

Quote:

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).

Quote:

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 ]
Back to top
Francis Glassborow
Guest





PostPosted: Sun Feb 12, 2006 6:06 am    Post subject: Re: Regex-friendly "raw" string literals Reply with quote



In article <3dadnSiIy65FgHPenZ2dnUVZ_tCdnZ2d (AT) giganews (DOT) com>, Pete Becker
<petebecker (AT) acm (DOT) org> writes
Quote:
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 ]
Back to top
Pete Becker
Guest





PostPosted: Mon Feb 13, 2006 8:06 pm    Post subject: Re: Regex-friendly "raw" string literals Reply with quote

Francis Glassborow wrote:

Quote:
In article <3dadnSiIy65FgHPenZ2dnUVZ_tCdnZ2d (AT) giganews (DOT) com>, Pete Becker
petebecker (AT) acm (DOT) 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 ]
Back to top
Ron House
Guest





PostPosted: Tue Feb 14, 2006 4:06 am    Post subject: Language changes. Was: Regex-friendly "raw" string literals. Reply with quote

Pete Becker wrote:

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

What's a suitable route for this time frame?


--
Ron House house (AT) usq (DOT) edu.au
http://www.sci.usq.edu.au/staff/house

---
[ 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 ]
Back to top
Francis Glassborow
Guest





PostPosted: Tue Feb 14, 2006 4:06 am    Post subject: Re: Regex-friendly "raw" string literals Reply with quote

In article <3Yednd-AH6yK0HLeRVn-ig (AT) giganews (DOT) com>, Pete Becker
<petebecker (AT) acm (DOT) org> writes
Quote:

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 ]
Back to top
Pete Becker
Guest





PostPosted: Tue Feb 14, 2006 3:36 pm    Post subject: Re: Regex-friendly "raw" string literals Reply with quote

Francis Glassborow wrote:

Quote:
In article <3Yednd-AH6yK0HLeRVn-ig (AT) giganews (DOT) com>, Pete Becker
petebecker (AT) acm (DOT) 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 ]
Back to top
Francis Glassborow
Guest





PostPosted: Tue Feb 14, 2006 7:06 pm    Post subject: Re: Regex-friendly "raw" string literals Reply with quote

In article <mNSdnaFKVMfiV2zenZ2dnUVZ_tudnZ2d (AT) giganews (DOT) com>, Pete Becker
<petebecker (AT) acm (DOT) org> writes
Quote:
Francis Glassborow wrote:

In article <3Yednd-AH6yK0HLeRVn-ig (AT) giganews (DOT) com>, Pete Becker
petebecker (AT) acm (DOT) 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 ]
Back to top
Thorsten Ottosen
Guest





PostPosted: Sun Feb 19, 2006 10:47 pm    Post subject: Re: Regex-friendly "raw" string literals Reply with quote

Scott Meyers wrote:
Quote:
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 ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.