Article View: gnu.g++.bug
Article #1666g++ 1.32 and escaped backslashes
From: "Douglas C. Schmidt"
Date: Wed, 25 Jan 1989 19:52
Date: Wed, 25 Jan 1989 19:52
52 lines
1663 bytes
1663 bytes
Hi,
G++ 1.32 seems to have a problem. Consider the following program,
which uses regular expression matching in libg++:
----------------------------------------
#include <String.h>
Regex rx_param ("[()\\[a-zA-Z_0-9*\\]]+",1);
main () {
String param = "foobar[]";
if (param.matches (rx_param)) {
printf ("works\n");
}
else {
printf ("fails\n");
}
}
----------------------------------------
The problem here is trying to match a literal ']' within a character
class (the constructor for rx_param seems to believe it is the
trailing ']' for the character class). When I looked at the sparc ASM
output, it didn't reduce the '\\' to '\' at all, i.e., the asm output
looked like:
.text
.align 0
LC0:
.ascii "[()\\[a-zA-Z_0-9*\\]]+\0"
which doesn't work correctly.
Unfortunately, using a single backslash, i.e.,
"[()\[a-zA-Z_0-9*\]]+"
DOES strip the backslash off, so that this leaves
"[()[a-zA-Z_0-9*]]+"
which is clearly not going to work (since the regular expression
scanner will mistake the first ']' for the end of the character class.
So the question remains: how does one get a single backslash before
a ']'?
Doug
Technical Details
Message-ID:
<8901251155.aa20584@PARIS.ICS.UCI.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%crimee.ics.uci.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%crimee.ics.uci.edu
From: schmidt%crimee.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: g++ 1.32 and escaped backslashes
Message-ID: <8901251155.aa20584@PARIS.ICS.UCI.EDU>
Date: 25 Jan 89 19:52:42 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 52