From d6e45cac4608535288ed2544471d2a8d84bfe26a Mon Sep 17 00:00:00 2001 From: arjen Date: Thu, 4 Dec 2003 09:57:35 +0000 Subject: [PATCH] Transform non-ASCII characters into hexadecimal entities. --- src/gcm_input/string_utils.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/gcm_input/string_utils.cpp b/src/gcm_input/string_utils.cpp index f23daea..10696ad 100644 --- a/src/gcm_input/string_utils.cpp +++ b/src/gcm_input/string_utils.cpp @@ -8,7 +8,7 @@ *********************** ** FILE NAME : string_utils.cpp ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.2 $ +** VERSION NUMBER : $Revision: 1.3 $ ** ** DESCRIPTION : Utility functions for Strings ** @@ -26,7 +26,10 @@ /***************************** $Log: string_utils.cpp,v $ - Revision 1.2 2003-10-27 11:26:43 arjen + Revision 1.3 2003-12-04 09:57:35 arjen + Transform non-ASCII characters into hexadecimal entities. + + Revision 1.2 2003/10/27 11:26:43 arjen Backslashes are correctly escaped with another backslash Revision 1.1 2003/08/05 08:15:01 arjen @@ -36,7 +39,7 @@ *****************************/ -static const char *RCSID = "$Id: string_utils.cpp,v 1.2 2003-10-27 11:26:43 arjen Exp $"; +static const char *RCSID = "$Id: string_utils.cpp,v 1.3 2003-12-04 09:57:35 arjen Exp $"; #include @@ -82,12 +85,14 @@ String SQL_Escape(String s) ** "<" => "<" ** ">" => ">" ** "&" => "&" +** Any non-ASCII characters or ASCII control codes are transformed +** into hexadecimal entities. ** ** VARS USED : ** VARS CHANGED : ** FUNCTIONS USED : ** SEE ALSO : -** LAST MODIFIED : +** LAST MODIFIED : Nov 30, 2003 **========================================================================= */ @@ -111,6 +116,25 @@ String XML_Entities(String s) s(i,1) = ">"; i++; break; + default: + if ((s[i] & 0x80) != 0) + { + // Construct a hexadecimal entity + const char hexdigit[] = "0123456789abcdef"; + char entity[] = "&#x..;"; + + entity[3] = hexdigit[(s[i] >> 4) & 0x0F]; + entity[4] = hexdigit[ s[i] & 0x0F]; + + s(i,1) = entity; + i++; + } + else if (s[i] < ' ' && s[i] != '\t' && s[i] != '\r') + { + std::cerr << "WARNING: discarding illegal character " << int(s[i]) << "\n"; + s(i,1) = ""; + i++; + } } } -- 2.11.0