proposed feature for glib




Hi,

While implementing a tool for the dump files generated by solexp (a tool
for the solid database) I found that the scanner in glib can't handle strings
with single quotes that have single quotes escaped by '' (two quotes in
succession).

I couldn't find a way to get the scanner to accept these strings, so 
I propose to add a config option for this behaviour.

	config->scan_string_sql_esc_sq

diffs included.

Regards,
Marc.

diff -r -u glib-1.2.3/glib.h ../glib-1.2.3/glib.h
--- glib-1.2.3/glib.h	Tue May 11 04:30:07 1999
+++ ../glib-1.2.3/glib.h	Tue Jul 27 11:31:16 1999
@@ -1915,6 +1915,7 @@
   guint		scan_hex_dollar : 1;		/* `$0ff0' */
   guint		scan_string_sq : 1;		/* string: 'anything' */
   guint		scan_string_dq : 1;		/* string: "\\-escapes!\n" */
+  guint		scan_string_sql_esc_sq : 1;	/* esc ' in sq-strings with '' */
   guint		numbers_2_int : 1;		/* bin, octal, hex => int */
   guint		int_2_float : 1;		/* int => G_TOKEN_FLOAT? */
   guint		identifier_2_string : 1;
diff -r -u glib-1.2.3/gscanner.c ../glib-1.2.3/gscanner.c
--- glib-1.2.3/gscanner.c	Tue May 11 04:30:07 1999
+++ ../glib-1.2.3/gscanner.c	Tue Jul 27 11:53:18 1999
@@ -112,6 +112,7 @@
   FALSE			/* scan_hex_dollar */,
   TRUE			/* scan_string_sq */,
   TRUE			/* scan_string_dq */,
+  FALSE			/* scan_string_sql_esc_sq */,
   TRUE			/* numbers_2_int */,
   FALSE			/* int_2_float */,
   FALSE			/* identifier_2_string */,
@@ -1291,8 +1292,26 @@
 	    {
 	      if (ch == '\'')
 		{
-		  in_string_sq = FALSE;
-		  break;
+		  if (config->scan_string_sql_esc_sq && 
+		      g_scanner_peek_next_char(scanner) == '\'')
+		    {
+		      /* we have two successive quotes, skip over the
+		       * the first and save the second in our token
+		       * string.
+		       */
+		      ch = g_scanner_get_char(scanner, line_p, position_p);
+		      gstring = g_string_append_c (gstring, ch);
+		    }
+		  else
+		    {
+		      in_string_sq = FALSE;
+		      break;
+		    }
 		}
 	      else
 		gstring = g_string_append_c (gstring, ch);


----------------------------------------------------
Marc van Kempen                 BowTie Technology     
Email: marc@bowtie.nl            WWW & Databases
tel. +31 40 2 43 20 65         
fax. +31 40 2 44 21 86         http://www.bowtie.nl
----------------------------------------------------





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]