***********************
** 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
**
/*****************************
$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
*****************************/
-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 <AXE/String.h>
** "<" => "<"
** ">" => ">"
** "&" => "&"
+** 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
**=========================================================================
*/
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++;
+ }
}
}