making \n, \t etc printable

Arne Goedeke la... at laramies.com
Thu Feb 8 22:48:24 UTC 2007


hey!

I thought it would be nice for most people to have \n, \t and such
being printed out by rlcodegen -Vp using backslash escapes. here is my
patch:

--- common/common.h	2007-01-21 23:58:22.000000000 +0100
+++ common/common.h	2007-02-08 23:24:29.000000000 +0100
@@ -60,7 +60,11 @@

 	bool isUpper() const { return ( 'A' <= key && key <= 'Z' ); }
 	bool isLower() const { return ( 'a' <= key && key <= 'z' ); }
-	bool isPrintable() const { return ( 32 <= key && key < 127 ); }
+	bool isPrintable() const
+	{
+	    return ( 32 <= key && key < 127 ) || key == '\b' || key == '\t'
+		    || key == '\n' || key == '\f' || key == '\r';
+	}

 	Key toUpper() const
 		{ return Key( 'A' + ( key - 'a' ) ); }
--- rlcodegen/gvdotgen.cpp	2007-01-21 23:58:22.000000000 +0100
+++ rlcodegen/gvdotgen.cpp	2007-02-08 23:24:36.000000000 +0100
@@ -47,6 +47,21 @@
 			case '"': case '\\':
 				out << "\\" << cVal;
 				break;
+			case '\n':
+				out << "\\\\n";
+				break;
+			case '\t':
+				out << "\\\\t";
+				break;
+			case '\r':
+				out << "\\\\r";
+				break;
+			case '\b':
+				out << "\\\\b";
+				break;
+			case '\f':
+				out << "\\\\f";
+				break;
 			default:
 				out << cVal;
 				break;



More information about the ragel-users mailing list