2 /**************************************************************************
3 ** (c) Copyright 2003, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 ** FILE NAME : string_utils.cpp
10 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
11 ** VERSION NUMBER : $Revision: 1.3 $
13 ** DESCRIPTION : Utility functions for Strings
18 ***************************************************************************
19 ** ADMINISTRATIVE INFORMATION *
20 ********************************
21 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 ** CREATION DATE : Jul 31, 2003
23 ** LAST UPDATE : Mar 14, 2015
25 **************************************************************************/
27 /*****************************
28 $Log: string_utils.cpp,v $
29 Revision 1.3 2003-12-04 09:57:35 arjen
30 Transform non-ASCII characters into hexadecimal entities.
32 Revision 1.2 2003/10/27 11:26:43 arjen
33 Backslashes are correctly escaped with another backslash
35 Revision 1.1 2003/08/05 08:15:01 arjen
36 Debug output to the log stream instead of cerr.
37 Fixed namespace problems in XPath searches of the DOM.
38 Moved string utility functions to a separate file.
40 *****************************/
42 static const char *RCSID = "$Id: string_utils.cpp,v 1.3 2003-12-04 09:57:35 arjen Exp $";
44 #include <AXE/String.h>
46 /*=========================================================================
48 ** SYNOPSIS : String SQL_Escape(String)
52 ** DESCRIPTION : Double backslashes and single quotes as per SQL syntax.
58 ** LAST MODIFIED : Mar 14, 2015
59 **=========================================================================
62 String SQL_Escape(String s)
66 for (i = 0; i < ~s; i++)
83 /*=========================================================================
84 ** NAME : XML_Entities
85 ** SYNOPSIS : String XML_Entities(String)
89 ** DESCRIPTION : Replace special characters for XML with their entity codes:
93 ** Any non-ASCII characters or ASCII control codes are transformed
94 ** into hexadecimal entities.
100 ** LAST MODIFIED : Nov 30, 2003
101 **=========================================================================
104 String XML_Entities(String s)
108 for (i = 0; i < ~s; i++)
125 if ((s[i] & 0x80) != 0)
127 // Construct a hexadecimal entity
128 const char hexdigit[] = "0123456789abcdef";
129 char entity[] = "&#x..;";
131 entity[3] = hexdigit[(s[i] >> 4) & 0x0F];
132 entity[4] = hexdigit[ s[i] & 0x0F];
137 else if (s[i] < ' ' && s[i] != '\t' && s[i] != '\r')
139 std::cerr << "WARNING: discarding illegal character " << int(s[i]) << "\n";