🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by "Douglas C. Schmidt" Wed, 25 Jan 1989 19:52
g++ 1.32 and escaped backslashes
#1666
Author: "Douglas C. Schmidt"
Date: Wed, 25 Jan 1989 19:52
52 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads